src/Ovh/OvhSend.php line 1051
<?php/*** Created by PhpStorm.* User: anthony* Date: 25/05/18* Time: 11:56*/namespace App\Ovh;use App\Entity\Actualite;use App\Entity\Auth\AuthUser;use App\Entity\BlackList;use App\Entity\CalendrierRedactionnel;use App\Entity\CompteurAdressesEnvoi;use App\Entity\DemandeDeConge;use App\Entity\DerniereAdresseEnvoie;use App\Entity\DiversParution;use App\Entity\Email\AdresseMailVerif;use App\Entity\Mailling;use App\Entity\Parution;use App\Entity\PieceJointeMailling;use App\Entity\Pressroom\PressroomCommunique;use App\Entity\Rappel;use App\Entity\Suivi;use App\Entity\User;use App\Service\Utilitaire\AnomalieGestion;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\Mailer\Exception\TransportExceptionInterface;use Symfony\Component\Mailer\Mailer;use Symfony\Component\Mailer\Transport;use Symfony\Component\Mime\Address;use Symfony\Component\Mime\Crypto\DkimSigner;use Symfony\Component\Mime\Email;use Symfony\Component\Mime\RawMessage;use Symfony\Component\HttpKernel\KernelInterface;use Twig\Environment;use Twig\Loader\FilesystemLoader;class OvhSend{private OvhHelper $ovhHelper;private KernelInterface $kernel;private AnomalieGestion $anomalieGestion;private $authUser;private EntityManagerInterface $em;private Environment $twig;/*** OvhSend constructor.*/public function __construct(OvhHelper $ovhHelper, KernelInterface $kernel, AnomalieGestion $anomalieGestion, EntityManagerInterface $em){$this->authUser = null;$this->anomalieGestion = $anomalieGestion;$this->ovhHelper = $ovhHelper;$this->kernel = $kernel;$this->em = $em;$loader = new FilesystemLoader(__DIR__.'/views/');$this->twig = new Environment($loader, array());}private function buildMailer(string $mail, string $password): Mailer{$dsn = sprintf('smtp://%s:%s@exchange.escalconsulting.com:587?encryption=tls',rawurlencode($mail),rawurlencode($password));return new Mailer(Transport::fromDsn($dsn));}private function projectPath(string $relativePath = ''): string{$base = rtrim($this->kernel->getProjectDir(), '/');return $relativePath ? $base . '/' . ltrim($relativePath, '/') : $base;}private function signEmail(Email $message): RawMessage{$privateKeyPath = $this->projectPath('public/Interne/RSA');$signer = new DkimSigner('file://' . $privateKeyPath, 'escalconsulting.com', '1515841257');return $signer->sign($message);}public function sendMailConfirmationDemandeConge(DemandeDeConge $demandeDeConge){$template = $this->twig->load('demandeCongeValidation.html.twig');$filePath = $this->projectPath('public/Interne/demandeConge/' .$demandeDeConge->getDebutConge()->format('Y-m-d') .'demandeConge' .$demandeDeConge->getAuthUser()->getUser()->getNom() .'.pdf');$message = (new Email())->from('louis@escalconsulting.com')->to($demandeDeConge->getAuthUser()->getUser()->getEmail())->subject('validation demande de congé')->html($template->render(['demandeDeConge' => $demandeDeConge]))->replyTo('louis@escalconsulting.com');if (file_exists($filePath)) {$message->attachFromPath($filePath);}$authUser = $this->em->getRepository(AuthUser::class)->findOneBy(['username' => 'louis']);/** @var AuthUser $authUser */$mail = $authUser->getUser()->getEmail();$password = $authUser->getPasswordMail();$mailer = $this->buildMailer($mail, $password);try {$mailer->send($message);} catch (TransportExceptionInterface $e) {throw $e;}}public function sendMailCongeCopil(DemandeDeConge $demandeDeConge) {$template = $this->twig->load('notificationCongeCopil.html.twig');$message = (new Email())->from('notification@escalconsulting.com')->to('copil@escalconsulting.com')->subject('Congé ' .$demandeDeConge->getAuthUser()->getUser()->getPrenom() . ' ' .$demandeDeConge->getAuthUser()->getUser()->getNom())->html($template->render(['demandeDeConge' => $demandeDeConge]))->replyTo('louis@escalconsulting.com');$authUser = $this->em->getRepository(AuthUser::class)->findOneBy(['username' => 'Notification']);/** @var AuthUser $authUser */$mail = $authUser->getUser()->getEmail();$password = $authUser->getPasswordMail();$mailer = $this->buildMailer($mail, $password);try {$mailer->send($message);} catch (TransportExceptionInterface $e) {throw $e;}}public function getContactSend(Mailling $mailling){$post = ['login' => 'Systeme','password' => 'i5iJ;5@J7',];$ch = curl_init('extranet.escalconsulting.com/identification.php');curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_POSTFIELDS, $post);curl_setopt($ch, CURLOPT_COOKIESESSION, true);curl_setopt($ch, CURLOPT_HEADER, 1);$response = curl_exec($ch);curl_close($ch);preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $response, $matches);foreach($matches[1] as $item) {parse_str($item, $cookie);$cookiesRetour = $cookie['PHPSESSID'];}$curl = curl_init();curl_setopt($curl, CURLOPT_URL, 'extranet.escalconsulting.com/mail_cms.php?action=lstuniq_frame&ID_mail=' . $mailling->getAncienId());curl_setopt($curl, CURLOPT_COOKIE,"PHPSESSID=".$cookiesRetour);curl_setopt($curl, CURLOPT_COOKIESESSION, true);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);$return = curl_exec($curl);curl_close($curl);$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => true,CURLOPT_URL => 'extranet.escalconsulting.com/information/getInfoListMailling.php?id=' . $mailling->getAncienId(),));$retourUserList = curl_exec($curl);$retourUserList = substr($retourUserList, 0, -1);curl_close($curl);$usersSend = explode('~', $retourUserList);return $usersSend;}public function verifMail($contactEmail) {$blackList = $this->em->getRepository(BlackList::class)->findOneBy(['email' => $contactEmail['email']]);if($blackList){return false;}$emailVerif = $this->em->getRepository(AdresseMailVerif::class)->findOneBy(['email' => $contactEmail['email']]);if($emailVerif){/** @var $emailVerif AdresseMailVerif */if($emailVerif->getSafeToSend() == 0){if($emailVerif->getReason() != 'Unreachable'){return false;}}}return true;}public function getNextMail($idcontact, $contactEmail) {$url="localhost:81/information/getNextMailByListId.php?id=".$idcontact;$postFields= $contactEmail;$options=array(CURLOPT_URL => $url,CURLOPT_RETURNTRANSFER => true,CURLOPT_HEADER => false,CURLOPT_FAILONERROR => true,CURLOPT_POST => true,CURLOPT_POSTFIELDS => array("idContact"=>json_encode($postFields)));$curl=curl_init();curl_setopt_array($curl,$options);$content=curl_exec($curl);dump($content);die();return $content;}public function getContactSend2(Mailling $mailling) {$curl = curl_init();$url = 'extranet.escalconsulting.com/information/genererMailContactMailling.php?id=' . $mailling->getAncienId();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_COOKIESESSION, true);curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);$return = curl_exec($curl);curl_close($curl);$contactsEmail = json_decode($return, true);$idsContactWithoutMail = [];$idContactAEnvoyer = [];$mailFalse = [];foreach ($contactsEmail as $idContact => $contactEmail) {$emailOK = false;$idContactTraite = $idContact;$contactEmailTraite = $contactEmail;while ($emailOK == false) {$emailOK = $this->verifMail($contactEmailTraite);if ($emailOK == false) {$mailFalse[]=$contactEmailTraite;$contsEmail = $this->getNextMail($idContactTraite,$contactEmailTraite);dump($contsEmail);if (count($contsEmail) == 0) {$idsContactWithoutMail[] = $idContactTraite;$emailOK = true;} else if (count($contsEmail) != 1) {dump("Impossible");die();}foreach ($contsEmail as $idCont => $contEmail) {$idContactTraite = $idCont;$contactEmailTraite = $contEmail;}} else {$a=1;//die();//idContactAEnvoyer[$idContactTraite] = $contactEmailTraite;}}}$idsCanBeBetter = [];foreach ($contactsEmail as $idContact => $contactEmail){$emailVerif = $this->em->getRepository(AdresseMailVerif::class)->findOneBy(['email' => $contactEmail['email']]);if($emailVerif){/** @var $emailVerif AdresseMailVerif */if($emailVerif->getRole() == 1){$idsCanBeBetter[$idContact] = $contactEmail;}}}dump(count($contactsEmail));die();}public function miseAjourPressroom(Mailling $mailling, $update = 0){$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1,CURLOPT_URL => 'extranet.escalconsulting.com/information/getPressroomId.php?id=' . $mailling->getClient()->getAncienId(),));$idPressroom = curl_exec($curl);curl_close($curl);$file = $this->kernel->getProjectDir(). '/public/maillings/'.$mailling->getId().'.pdf';if($mailling->getClient()->getPressroom()){$pressroom = $mailling->getClient()->getPressroom();$pressroomComunique = new PressroomCommunique();$pressroomComunique->setAncienId($mailling->getAncienId());$pressroomComunique->setDate(new \DateTime('now'));if($mailling->getObjetCour()){$pressroomComunique->setNom($mailling->getObjetCour());} else {$pressroomComunique->setNom($mailling->getObjet());}$pressroomComunique->setPdf(true);// recuperation et création des paths$pathPressroomFile = $this->kernel->getProjectDir(). '/public/pressroomClient/' . $pressroom->getId();if(!file_exists($pathPressroomFile)){mkdir($pathPressroomFile,0777);}$pathPressroomCommunique = $pathPressroomFile . '/communique/';if(!file_exists($pathPressroomCommunique)){mkdir($pathPressroomCommunique,0777);}// recupération du pdf$communiqueFile = $this->kernel->getProjectDir(). '/public/maillings/'. $mailling->getId() . '.pdf';if(file_exists($communiqueFile)){copy($communiqueFile, $pathPressroomCommunique. $mailling->getAncienId() . '.pdf');$pressroomComunique->setPdf(true);}// recuperation photoif($mailling->getPhoto()){$explodeUrl = explode('.', $mailling->getPhoto()->getUrl());$extension = end($explodeUrl);$url = 'extranet.escalconsulting.com/photocp/'. $mailling->getPhoto()->getUrl();$c = curl_init();curl_setopt($c, CURLOPT_URL, $url);curl_setopt($c, CURLOPT_RETURNTRANSFER, true);curl_setopt($c, CURLOPT_HEADER, false);$output = curl_exec($c);curl_close($c);file_put_contents($pathPressroomFile. '/communique/'. $mailling->getAncienId() . '.' .$extension , $output);$pressroomComunique->setPhoto($extension);$pressroomComunique->setDate($mailling->getDateEnvoi());}$pressroom->addPressroomCommunique($pressroomComunique);$this->em->persist($pressroomComunique);$this->em->persist($pressroom);$this->em->flush();}}public function setMaillingSend(Mailling $mailling){if($mailling->getTypeMail() == "Coupure"){foreach ($mailling->getPiecesJointes() as $piecesJointe){/** @var PieceJointeMailling $piecesJointe */$idCoupure = $piecesJointe->getCoupure()->getAncienId();$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1,CURLOPT_URL => 'extranet.escalconsulting.com/information/setCoupureSend.php?id=' . $idCoupure,));$coupureSend = curl_exec($curl);curl_close($curl);$piecesJointe->getCoupure()->setEnvoyer(true);$this->em->persist($piecesJointe->getCoupure());$this->em->flush();}} else {$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1,CURLOPT_URL => 'extranet.escalconsulting.com/information/setMaillingSend.php?id=' . $mailling->getAncienId(),));$maillingSend = curl_exec($curl);curl_close($curl);}}public function sendMailEnvoie(\App\Entity\MaillingEnCour $maillingEnCour){$endMailling = false;$maillingEnCour->setDestinataire(trim($maillingEnCour->getDestinataire()));if($maillingEnCour->getTypeMail() == "mailling"){$message = $this->getMessageMaillingType($maillingEnCour);} elseif ($maillingEnCour->getTypeMail() == "veille"){$message = $this->getMessageVeilleType($maillingEnCour);} elseif ($maillingEnCour->getTypeMail() == "test"){$message = $this->getMessageMaillingTestType($maillingEnCour);} elseif ($maillingEnCour->getTypeMail() == "confirmationBegin"){$message = $this->getMessageConfirmation($maillingEnCour,'begin');} elseif ($maillingEnCour->getTypeMail() == "confirmationEnd"){$message = $this->getMessageConfirmation($maillingEnCour,'end');if($maillingEnCour->getDestinataire() == 'informatique@escalconsulting.com')$endMailling = true;}if($message != false){if(is_array($message)){foreach ($message as $mess){$this->sendMail($mess, $maillingEnCour);}return false;} else {$this->sendMail($message, $maillingEnCour);}}if($endMailling){return $maillingEnCour;}return false;}public function finMailling(\App\Entity\MaillingEnCour $maillingEnCour){$maillingEnCourMailling = $this->em->getRepository(\App\Entity\MaillingEnCour::class)->findBy(['mailling' => $maillingEnCour->getMailling(), 'typeMail' => 'mailling', 'envoyer' => true]);$maillingEnCour->getMailling()->setNbMailEnvoye(count($maillingEnCourMailling));$maillingEnCour->getMailling()->setEnvoyer(true);$maillingEnCour->getMailling()->setEnCour(false);$maillingEnCour->getMailling()->setDateEnvoi(new \DateTime('now'));$this->em->persist($maillingEnCour->getMailling());$this->em->flush();$this->setMaillingSend($maillingEnCour->getMailling());if($maillingEnCour->getMailling()->getTypeMail() != "Coupure") {$this->miseAjourPressroom($maillingEnCour->getMailling());}}public function getMessageConfirmation(\App\Entity\MaillingEnCour $maillingEnCour, $status){$from = $this->getFrom($maillingEnCour);if($status == 'begin'){$mailling = $maillingEnCour->getMailling();$from = $this->getFrom($maillingEnCour);if($mailling->getTypeMail() != 'CP'){$size = 0;$pathCoupure = $this->projectPath('public/coupures/');$iterator = $mailling->getPiecesJointes()->getIterator();$iterator->uasort(function ($a, $b) {return ($a->getCoupure()->getDateParution() < $b->getCoupure()->getDateParution()) ? -1 : 1;});$mailling->setPiecesJointes(new ArrayCollection(iterator_to_array($iterator)));foreach ($mailling->getPiecesJointes() as $pieceJointe){$size = $size + filesize ( $pathCoupure . $pieceJointe->getUrl());}$coupuresMessage = [];if($size < 10000000){$coupuresMessage[] = $mailling->getPiecesJointes();} else {$ratio = $size / 10000000;$ratio = floor($ratio) + 1;$sizeMid = $size / $ratio;$sizeCoupure = 0;$pieceJointeMail = [];foreach ($mailling->getPiecesJointes() as $pieceJointe){if($sizeCoupure > $sizeMid){$coupuresMessage[] = $pieceJointeMail;$pieceJointeMail = [];$sizeCoupure = 0;}$pieceJointeMail[] = $pieceJointe;$sizeCoupure = $sizeCoupure + filesize ( $pathCoupure . $pieceJointe->getUrl());}$coupuresMessage[] = $pieceJointeMail;}$messages = [];$i = 1;foreach ($coupuresMessage as $coupureMessage) {$template = $this->twig->load('mailCoupure.html.twig');if (count($coupuresMessage) == 1) {$objetMail = $mailling->getNom();} else {$objetMail = $mailling->getNom() .' '. $i . '/' . count($coupuresMessage);}$debut = '';$fin = '';if($i == 1){$debut = $mailling->getDebutMailCoupure();}if($i == count($coupuresMessage)){$fin = $mailling->getFinMailCoupure();}$message = (new Email())->from($from)->to($maillingEnCour->getDestinataire())->subject($objetMail)->html($template->render(['mailling' => $mailling, 'coupureMessage' => $coupureMessage, 'user' => $mailling->getReplyTo(),'debut' => $debut, 'fin' => $fin, 'logo' => $mailling->getClient()->getLogo()->getUrl()]))->replyTo($mailling->getReplyTo()->getUser()->getEmail());/** @var PieceJointeMailling $pieceJointe */foreach ($coupureMessage as $pieceJointe) {$filePath = $pathCoupure . $pieceJointe->getUrl();if (file_exists($filePath)) {$message->attachFromPath($filePath);}}$i = $i + 1;$messages[] = $message;}return $messages;} else {$rand = '&'.rand(0,1000000).'='.rand(0,1000000);if (strlen($mailling->getColor())==7){$color = $mailling->getColor();} else {$color = "#F57E60";}$template = $this->twig->load('mailConfirmation.html.twig');$logoPath = $this->kernel->getProjectDir() . '/public/logoMail.png';$message = (new Email())->from($from)->to($maillingEnCour->getDestinataire())->subject($mailling->getObjetCour())->html($template->render(['mailling' => $mailling, 'user' => $mailling->getReplyTo(),'logo' => $mailling->getClient()->getLogo()->getUrl(), 'rand' => $rand, 'color' => $color,'logoPath' => $logoPath]))->replyTo($mailling->getReplyTo()->getUser()->getEmail());if($mailling->getId() == 6824){$pathfile = $this->projectPath('public/Interne/infographie.jpg');if (file_exists($pathfile)) {$message->attachFromPath($pathfile);}}/** @var PieceJointeMailling $piecesJointe */foreach ($mailling->getPiecesJointes() as $piecesJointe){$filePath = $this->projectPath('public/maillings/' . $mailling->getAncienId() . '/' . $piecesJointe->getUrl());if (file_exists($filePath)) {$message->attachFromPath($filePath);}}}return $message;}$template = $this->twig->load('mailConfirmationFin.html.twig');if($maillingEnCour->getMailling()->getTypeMail() == 'Coupure'){$objet = $maillingEnCour->getMailling()->getObjet();} else {$objet = $maillingEnCour->getMailling()->getObjetCour();}$finObjet = ' a été envoyé';$message = (new Email())->from($from)->to($maillingEnCour->getDestinataire())->subject($objet . $finObjet)->html($template->render(['mailling' => $maillingEnCour->getMailling()]));return $message;}public function getMessageVeilleType(\App\Entity\MaillingEnCour $maillingEnCour){$from = $this->getFrom($maillingEnCour);$template = $this->twig->load('veille.html.twig');return (new Email())->from($from)->to($maillingEnCour->getDestinataire())->subject('Veille du ' . $maillingEnCour->getVeille()->getDate()->format('d/m/Y'))->html($template->render(['veille' => $maillingEnCour->getVeille()]));}public function getMessageMaillingTestType(\App\Entity\MaillingEnCour $maillingEnCour){$from = $this->getFrom($maillingEnCour);$mailling = $maillingEnCour->getMailling();$rand = '&' . rand(0, 1000000) . '=' . rand(0, 1000000);if ($mailling->getTypeMail() != 'CP') {$size = 0;$pathCoupure = $this->projectPath('public/coupures/');$iterator = $mailling->getPiecesJointes()->getIterator();$iterator->uasort(function ($a, $b) {return ($a->getCoupure()->getDateParution() < $b->getCoupure()->getDateParution()) ? -1 : 1;});$mailling->setPiecesJointes(new ArrayCollection(iterator_to_array($iterator)));foreach ($mailling->getPiecesJointes() as $pieceJointe) {$size += filesize($pathCoupure . $pieceJointe->getUrl());}$coupuresMessage = [];if ($size < 10000000) {$coupuresMessage[] = $mailling->getPiecesJointes();} else {$ratio = $size / 10000000;$ratio = floor($ratio) + 1;$sizeMid = $size / $ratio;$sizeCoupure = 0;$pieceJointeMail = [];foreach ($mailling->getPiecesJointes() as $pieceJointe) {if ($sizeCoupure > $sizeMid) {$coupuresMessage[] = $pieceJointeMail;$pieceJointeMail = [];$sizeCoupure = 0;}$pieceJointeMail[] = $pieceJointe;$sizeCoupure += filesize($pathCoupure . $pieceJointe->getUrl());}$coupuresMessage[] = $pieceJointeMail;}$messages = [];$i = 1;foreach ($coupuresMessage as $coupureMessage) {$template = $this->twig->load('mailTestCoupure.html.twig');if (count($coupuresMessage) == 1) {$objetMail = $mailling->getNom();} else {$objetMail = $mailling->getNom() . ' ' . $i . '/' . count($coupuresMessage);}$debut = '';$fin = '';if ($i == 1) {$debut = $mailling->getDebutMailCoupure();}if ($i == count($coupuresMessage)) {$fin = $mailling->getFinMailCoupure();}$message = (new Email())->from($from)->to($maillingEnCour->getDestinataire())->subject($objetMail)->html($template->render(['mailling' => $mailling, 'coupureMessage' => $coupureMessage, 'user' => $mailling->getReplyTo(),'debut' => $debut, 'fin' => $fin, 'rand' => $rand, 'logo' => $mailling->getClient()->getLogo()->getUrl()]))->replyTo($mailling->getReplyTo()->getUser()->getEmail());/** @var PieceJointeMailling $pieceJointe */foreach ($coupureMessage as $pieceJointe) {$filePath = $pathCoupure . $pieceJointe->getUrl();if (file_exists($filePath)) {$message->attachFromPath($filePath);}}$i++;$messages[] = $message;}return $messages;}if (strlen($mailling->getColor()) == 7) {$color = $mailling->getColor();} else {$color = "#F57E60";}if ($mailling->getId() == 5517 || $mailling->getId() == 5899) {$template = $this->twig->load('mailClient/logoFCAtest.html.twig');} else {$template = $this->twig->load('mailTestNew.html.twig');}$logoPath = $this->kernel->getProjectDir() . '/public/logoMail.png';$message = (new Email())->from($from)->to($maillingEnCour->getDestinataire())->subject($mailling->getObjetCour())->html($template->render(['mailling' => $mailling, 'user' => $mailling->getReplyTo(), 'logo' => $mailling->getClient()->getLogo()->getUrl(),'rand' => $rand, 'color' => $color,'logoPath' => $logoPath]))->replyTo($mailling->getReplyTo()->getUser()->getEmail());if ($mailling->getId() == 6824) {$pathfile = $this->projectPath('public/Interne/infographie.jpg');if (file_exists($pathfile)) {$message->attachFromPath($pathfile);}}/** @var PieceJointeMailling $piecesJointe */foreach ($mailling->getPiecesJointes() as $piecesJointe) {$filePath = $this->projectPath('public/maillings/' . $mailling->getAncienId() . '/' . $piecesJointe->getUrl());if (file_exists($filePath)) {$message->attachFromPath($filePath);}}return $message;}public function getMessageMaillingType(\App\Entity\MaillingEnCour $maillingEnCour){if (filter_var(trim($maillingEnCour->getDestinataire()), FILTER_VALIDATE_EMAIL)) {$from = $this->getFrom($maillingEnCour);$mailling = $maillingEnCour->getMailling();if ($mailling->getTypeMail() != 'CP') {$size = 0;$pathCoupure = $this->projectPath('public/coupures/');$iterator = $mailling->getPiecesJointes()->getIterator();$iterator->uasort(function ($a, $b) {return ($a->getCoupure()->getDateParution() < $b->getCoupure()->getDateParution()) ? -1 : 1;});$mailling->setPiecesJointes(new ArrayCollection(iterator_to_array($iterator)));foreach ($mailling->getPiecesJointes() as $pieceJointe) {$size += filesize($pathCoupure . $pieceJointe->getUrl());}$coupuresMessage = [];if ($size < 10000000) {$coupuresMessage[] = $mailling->getPiecesJointes();} else {$ratio = $size / 10000000;$ratio = floor($ratio) + 1;$sizeMid = $size / $ratio;$sizeCoupure = 0;$pieceJointeMail = [];foreach ($mailling->getPiecesJointes() as $pieceJointe) {if ($sizeCoupure > $sizeMid) {$coupuresMessage[] = $pieceJointeMail;$pieceJointeMail = [];$sizeCoupure = 0;}$pieceJointeMail[] = $pieceJointe;$sizeCoupure += filesize($pathCoupure . $pieceJointe->getUrl());}$coupuresMessage[] = $pieceJointeMail;}$messages = [];$i = 1;foreach ($coupuresMessage as $coupureMessage) {$template = $this->twig->load('mailCoupure.html.twig');if (count($coupuresMessage) == 1) {$objetMail = $mailling->getNom();} else {$objetMail = $mailling->getNom() . ' ' . $i . '/' . count($coupuresMessage);}$debut = '';$fin = '';if ($i == 1) {$debut = $mailling->getDebutMailCoupure();}if ($i == count($coupuresMessage)) {$fin = $mailling->getFinMailCoupure();}$message = (new Email())->from($from)->to($maillingEnCour->getDestinataire())->subject($objetMail)->html($template->render(['mailling' => $mailling, 'coupureMessage' => $coupureMessage, 'user' => $mailling->getReplyTo(),'debut' => $debut, 'fin' => $fin, 'logo' => $mailling->getClient()->getLogo()->getUrl(), 'idUser' => $maillingEnCour->getUserId(),'userSend' => $maillingEnCour->getDestinataire()]))->replyTo($mailling->getReplyTo()->getUser()->getEmail());/** @var PieceJointeMailling $pieceJointe */foreach ($coupureMessage as $pieceJointe) {$filePath = $pathCoupure . $pieceJointe->getUrl();if (file_exists($filePath)) {$message->attachFromPath($filePath);}}$i++;$messages[] = $message;}return $messages;}if (strlen($mailling->getColor()) == 7) {$color = $mailling->getColor();} else {$color = "#F57E60";}if ($mailling->getId() == 5517 || $mailling->getId() == 5899) {$template = $this->twig->load('mailClient/logoFCA.html.twig');} else {$template = $this->twig->load('maillingNew.html.twig');}$logoPath = $this->kernel->getProjectDir() . '/public/logoMail.png';$message = (new Email())->from($from)->to($maillingEnCour->getDestinataire())->subject($mailling->getObjetCour())->html($template->render(['mailling' => $mailling, 'user' => $mailling->getReplyTo(), 'logo' => $mailling->getClient()->getLogo()->getUrl(),'idUser' => $maillingEnCour->getUserId(), 'userSend' => $maillingEnCour->getDestinataire(), 'color' => $color,'logoPath' => $logoPath]))->replyTo($mailling->getReplyTo()->getUser()->getEmail());if ($mailling->getId() == 6824) {$pathfile = $this->projectPath('public/Interne/infographie.jpg');if (file_exists($pathfile)) {$message->attachFromPath($pathfile);}}} else {$message = false;$maillingEnCour->setErreur('le mail est incorrect');$this->em->persist($maillingEnCour);$this->em->flush();}return $message;}public function sendMail(Email $message ,\App\Entity\MaillingEnCour $maillingEnCour){// Envoi de CPif($maillingEnCour->getAdressEnvoie()) {$password = 'skl001';//recuperer derniere adresse de la table$derniereAdresseEnvoie = $this->em->getRepository(DerniereAdresseEnvoie::class)->findOneBy(['id' => 1]);$nomDerniereAdresseEnvoie = $derniereAdresseEnvoie->getAdresseEnvoie();//recuperer l'id de la derniere adresse envoyee$adresseEnvoye = $this->em->getRepository(CompteurAdressesEnvoi::class)->findOneBy(['adresse_envoi' => $nomDerniereAdresseEnvoie]);$IDadresseEnvoyee = $adresseEnvoye->getId();//on recup le nb total d'adresses d'envoies$totalAdressesEnvoies = $this->em->getRepository(CompteurAdressesEnvoi::class)->findAll();$nbAdressesEnvoies = count($totalAdressesEnvoies);//si ID supp au nb total d'adresses on retourne à 1if ($IDadresseEnvoyee < $nbAdressesEnvoies) {$IDnouvelleAdresse = $IDadresseEnvoyee + 1;} else {$IDnouvelleAdresse = 1;}$nouvelleAdresseEnvoie = $this->em->getRepository(CompteurAdressesEnvoi::class)->findOneBy(['id' => $IDnouvelleAdresse]);$compteurMail = $this->em->getRepository(CompteurAdressesEnvoi::class)->findOneBy(['adresse_envoi' => $nouvelleAdresseEnvoie->getAdresseEnvoi(), 'date_envoi_mail' => new \DateTime('now')]);if (is_null($compteurMail)) {//on ecrase la date$nouvelleAdresseEnvoie->setDateEnvoiMail(new \DateTime('now'));//mettre à jour le compteur d'envoie pour l'adresse$nouvelleAdresseEnvoie->setCompteurMail(1);} else {//mettre à jour le compteur d'envoie pour l'adresse$nouvelleAdresseEnvoie->setCompteurMail($nouvelleAdresseEnvoie->getCompteurMail() + 1);}$derniereAdresseEnvoie->setAdresseEnvoie($nouvelleAdresseEnvoie->getAdresseEnvoi());$mail = $nouvelleAdresseEnvoie->getAdresseEnvoi();$this->em->persist($derniereAdresseEnvoie);$this->em->persist($nouvelleAdresseEnvoie);$this->em->flush();//si c'est un gmailif (substr_compare($maillingEnCour->getDestinataire(), "@gmail.com", -10, 10) === 0) {//recuperer nombre total d'envoi pour l'adresse mail fictive pour date du jour$compteur = $this->em->getRepository(CompteurAdressesEnvoi::class)->findOneBy(['adresse_envoi' => $mail, 'date_envoi_gmail' => new \DateTime('now')]);if (!is_null($compteur)) {$compteurGmail = $compteur->getCompteurGmail();} else {//si aucun compteur pour cette adresse fictive pour la date du jour, écraser l'ancien compteur et changer la date$compteurGmail = 0;$compteur = $this->em->getRepository(CompteurAdressesEnvoi::class)->findOneBy(['adresse_envoi' => $mail]);$compteur->setCompteurGmail($compteurGmail);$compteur->setDateEnvoiGmail(new \DateTime('now'));$this->em->persist($compteur);$this->em->flush();}//si moins de 500 envois gmail, on garde l'adresse fictive de baseif ($compteurGmail < 500) {//on ajoute un envoi au compteur$compteur->setCompteurGmail($compteurGmail + 1);$this->em->persist($compteur);$this->em->flush();} else {$adressesFictives = $this->em->getRepository(CompteurAdressesEnvoi::class)->findAll();$trouve = false;//on parcourt toutes les adresses fictivesforeach ($adressesFictives as $adresse) {if ($adresse->getDateEnvoiGmail() < new \DateTime('midnight')) {$adresse->setDateEnvoiGmail(new \DateTime('now'));$adresse->setCompteurGmail(0);}if ($adresse->getCompteurGmail() < 500) {$trouve = true;//recuperer l'adresse mail fictive de moins de 500 envois$mail = $adresse->getAdresseEnvoi();//On soustrait le compteur $nouvelleAdresseEnvoie si elle est différente de l'adresse envoie couranteif ($mail != $nouvelleAdresseEnvoie->getAdresseEnvoi()) {$nouvelleAdresseEnvoie->setCompteurMail($nouvelleAdresseEnvoie->getCompteurMail() - 1);}$compteurGmail = $adresse->getCompteurGmail();$adresse->setCompteurGmail($compteurGmail + 1);$this->em->persist($adresse);$this->em->flush();break;}}//dans le cas où il ne reste plus d'adresses fictives à moins de 500 envois gmailif ($trouve === false) {$mail = $maillingEnCour->getEnvoyerPar()->getAdresseEnvoi();$cmpt = $this->em->getRepository(CompteurAdressesEnvoi::class)->findOneBy(['adresse_envoi' => $mail]);$cmpt->setCompteurGmail($compteurGmail + 1);$this->em->persist($cmpt);$this->em->flush();}$this->em->persist($nouvelleAdresseEnvoie);$this->em->flush();}}// dans le cas d'envoi des retombées} else {$mail = $maillingEnCour->getEnvoyerPar()->getUser()->getEmail();$password = $maillingEnCour->getEnvoyerPar()->getPasswordMail();}$mailer = $this->buildMailer($mail, $password);// Correspondre l'adresse mail qui se connecte et l'expediteur$message->from($mail);try {$signedMessage = $this->signEmail($message);$mailer->send($message);$maillingEnCour->setEnvoyer(true);} catch (TransportExceptionInterface $e) {$maillingEnCour->setErreur('erreur lors de l\'envoie du mail');}$this->em->persist($maillingEnCour);$this->em->flush();}public function getFrom(\App\Entity\MaillingEnCour $maillingEnCour){if($maillingEnCour->getAdressEnvoie()){return $maillingEnCour->getEnvoyerPar()->getAdresseEnvoi();}return $maillingEnCour->getEnvoyerPar()->getUser()->getEmail();}public function sendMailMerge($rand, AuthUser $authUser){$template = $this->twig->load('mergePdf.html.twig');$message = (new Email())->from('notification@escalconsulting.com')->to($authUser->getUser()->getEmail())->subject('pdf')->html($template->render(['rand' => $rand]))->replyTo('notification@escalconsulting.com');$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}// envoie rappels escalnetpublic function sendRappelEscalnet(Rappel $rappel){$template = $this->twig->load('mailRappel.html.twig');$destinataire = $rappel->getMembre()->getUser()->getEmail();$message = (new Email())->from('rappel@escalconsulting.com')->to($destinataire)->subject('Rappel')->html($template->render(['rappel' => $rappel]));$mailer = $this->buildMailer('rappel@escalconsulting.com', 'C?uR*5j59');$mailer->send($message);}// envoie alerte calenriers redactionnels bouclés ce jourpublic function sendAlerteCalendrierRedactionnel($calendriersConsultant, $email){$template = $this->twig->load('mailAlerteCalendrierReactionnel.html.twig');$destinataire = $email;$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->subject('Alerte bouclage calendrier rédactionnel')->html($template->render(['calendriers' => $calendriersConsultant]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendDemandeContact($message, $object, $email, $identite, $telephone){$template = $this->twig->load('contact.html.twig');$message = (new Email())->from('notification@escalconsulting.com')->to('contact@escalconsulting.com')->subject(' Demande Site Web /' .$object)->html($template->render(['identite' => $identite, 'message' => $message, 'email' => $email, 'telephone' => $telephone]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}/*** @param DemandeDeConge $demandeDeConge*/public function sendMailDemandeCongeResponsable(DemandeDeConge $demandeDeConge, $rand, $user = null){$userToSend = $this->em->getRepository(User::class)->findOneBy(['email'=> $demandeDeConge->getPersonneAEnvoyer()]);/** @var User $userToSend */if($userToSend->getEmail() == 'louis@escalconsulting.com'){$template = $this->twig->load('demandeConge.html.twig');} else {$template = $this->twig->load('demandeCongeResponsable.html.twig');}$filePath = $this->projectPath('public/Interne/demandeConge/' . $demandeDeConge->getDebutConge()->format('Y-m-d') .'demandeConge' . $demandeDeConge->getAuthUser()->getUser()->getNom() . '.pdf');$message = (new Email())->from($demandeDeConge->getAuthUser()->getUser()->getEmail())->to($userToSend->getEmail())->subject('demande de congé ' . $demandeDeConge->getAuthUser()->getUser()->getNom() . ' ' .$demandeDeConge->getAuthUser()->getUser()->getPrenom())->html($template->render(['demandeDeConge' => $demandeDeConge, 'rand' => $rand, 'user' => $userToSend, 'uservalide' => $user]))->replyTo($demandeDeConge->getAuthUser()->getUser()->getEmail());if (file_exists($filePath)) {$message->attachFromPath($filePath);}$mail = $demandeDeConge->getAuthUser()->getUser()->getEmail();$password = $demandeDeConge->getAuthUser()->getPasswordMail();$mailer = $this->buildMailer($mail, $password);try {$mailer->send($message);} catch (TransportExceptionInterface $e) {throw $e;}}public function sendMailAccuseReception(DemandeDeConge $demandeDeConge){$template = $this->twig->load('accuseReceptionConge.html.twig');$destinataire = $demandeDeConge->getAuthUser()->getUser()->getEmail();$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->subject('Accusé de réception demande de congé')->html($template->render(['demandeDeConge' => $demandeDeConge]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendReseauxSociaux($coupure){// gestion des accents$coupure['titre'] = str_replace(''', '\'', $coupure['titre']);$coupure['nom_support'] = str_replace(''', '\'', $coupure['nom_support']);$coupure['doc_lier'] = str_replace(''', '\'', $coupure['doc_lier']);$template = $this->twig->load('mailReseauxSociaux.html.twig');$destinataire = "andry@escalconsulting.com";$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->subject('Informations coupures')->html($template->render(['coupure' => $coupure]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendMailNouvelleActualite(Actualite $actualite){$template = $this->twig->load('mailNouvelleActualite.html.twig');$destinataire = "paris@escalconsulting.com";$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->subject('Nouvelle Actualité')->html($template->render(['actualite' => $actualite]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendMailAssocierParution(Parution $parution, DiversParution $divers){$template = $this->twig->load('mailParutionAssociee.html.twig');$destinataire = [];if (count($parution->getClient()->getMembres()) > 0) {$destinataire[] = $parution->getClient()->getMembres()[0]->getDeuxiemeMembre()->getEmail(); // le deuxieme membre = consultant$destinataire[] = $parution->getClient()->getMembres()[0]->getPremierMembre()->getEmail(); // le premier membre = RS} else if ($parution->getClient()->getAdresseGenerique() != '' && $parution->getClient()->getAdresseGenerique() != null) {$destinataire[] = $parution->getClient()->getAdresseGenerique();} else if ($parution->getAuteur() != null) {$destinataire[] = $parution->getAuteur()->getUser()->getEmail();} else {$destinataire[] = 'informatique@escalconsulting.com';}$message = (new Email())->from('notification@escalconsulting.com')->to(...$destinataire)->subject('Nouvelle parution rentrée')->html($template->render(['parution' => $parution, 'divers' => $divers]));$fichier = null;foreach ($parution->getFichiersParutions() as $fichierParution) {if (!$fichierParution->getMultimedia() && $fichierParution->getUrl()) {$fichier = $fichierParution;break;}}if ($fichier) {$content = file_get_contents($fichier->getUrl());if ($content !== false) {$message->attach($content, basename($fichier->getUrl()), 'application/pdf');}}$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendMailMutualisation(Suivi $suivi, $axe, $interesse, $sujet, $supports, $email){$template = $this->twig->load('mailMutualisation.html.twig');$destinataire = $email;$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->cc('mutualisation@escalconsulting.com')->subject('Mutualisation de la part de ' . $suivi->getAuteur()->getUser()->getPrenom() . ' ' . $suivi->getAuteur()->getUser()->getNom())->html($template->render(['suivi' => $suivi, 'axe'=> $axe, 'interesse' => $interesse, 'sujet' => $sujet, 'supports' => $supports]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendDesabonnement($email){$template = $this->twig->load('notificationDesabonnement.html.twig');$destinataire = $email;$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->subject('Confirmation de désabonnement')->html($template->render(['email' => $email]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendDemandeITSupprimerContact($contactID, $nomContact, $nomDemandeur) {// Gestion des accents$nomDemandeur = str_replace(''', '\'',$nomDemandeur);$nomContact = str_replace(''', '\'',$nomContact);$template = $this->twig->load('demandeSuppressionContact.html.twig');$destinataire = 'informatique@escalconsulting.com';$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->subject("Demande de suppression d'un Contact")->html($template->render(['id' => $contactID ,'contact' => $nomContact, 'demandeur' => $nomDemandeur]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendDemandeEnvoyerIT($suggestion) {$template = $this->twig->load('suggestionAmelioration.html.twig');$destinataire = 'bdd@escalconsulting.com';$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->subject("Suggestions d'amélioration - Escalnet")->html($template->render(['suggestion' => $suggestion]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}public function sendDemandeITSupprimerSupport($supportId, $nom, $nomDemandeur) {// Gestion des accents$nomDemandeur = str_replace(''', '\'',$nomDemandeur);$nom = str_replace(''', '\'',$nom);$template = $this->twig->load('demandeSuppressionSupport.html.twig');$destinataire = 'informatique@escalconsulting.com';$message = (new Email())->from('notification@escalconsulting.com')->to($destinataire)->subject("Demande de suppression d'un Support")->html($template->render(['id' => $supportId ,'support' => $nom, 'demandeur' => $nomDemandeur]));$mailer = $this->buildMailer('notification@escalconsulting.com', 'H76-7Gj%a');$mailer->send($message);}}