Loading CHANGELOG.md +4 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,10 @@ ----- - Bug fixe pour les envoies de mails en smtps 7.2.2 ----- - Correction du bug lié à la réexpédition d'un mail - Ajout d'une action pour controler la configuration du module 7.2.1 ----- Loading config/merged/mail.config.php +11 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ return array( [ 'controller' => MailController::class, 'action' => [ 'afficher-configuration', 'supprimer', ], 'privileges' => [ Loading Loading @@ -122,6 +123,16 @@ return array( ], ], ], 'afficher-configuration' => [ 'type' => Literal::class, 'options' => [ 'route' => '/afficher-configuration', 'defaults' => [ /** @see MailController::afficherConfigurationAction() */ 'action' => 'afficher-configuration', ], ], ], ], ], ], Loading src/UnicaenMail/Controller/MailController.php +10 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,16 @@ class MailController extends AbstractActionController } public function afficherConfigurationAction(): ViewModel { $config = $this->getMailService()->getConfig(); return new ViewModel([ 'title' => 'Configuration du module', 'config' => $config, ]); } public function afficherAction(): ViewModel { $mail = $this->getMailService()->getRequestedMail($this); Loading src/UnicaenMail/Controller/MailControllerFactory.php +1 −3 Original line number Diff line number Diff line Loading @@ -2,8 +2,8 @@ namespace UnicaenMail\Controller; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenMail\Service\Mail\MailService; Loading @@ -11,8 +11,6 @@ class MailControllerFactory { /** * @param ContainerInterface $container * @return MailController * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ Loading src/UnicaenMail/Service/Mail/MailService.php +30 −11 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use RuntimeException; use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mailer\Mailer; use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Part\DataPart; use UnicaenMail\Entity\Db\Mail; use UnicaenMail\Exception\NotFoundConfigException; Loading @@ -20,6 +21,8 @@ class MailService { use ProvidesObjectManager; const ATTACHMENT_SEP = "#<>#"; const BODY_TEXT_TEMPLATE = <<<EOS ----------------------------------------------------------------------- Loading Loading @@ -77,6 +80,10 @@ EOS; $this->config = $config; } public function getConfig(): array { return $this->config; } public function createMailEntity(): object { Loading Loading @@ -178,10 +185,10 @@ EOS; $value = null; $config = $this->config['module']; if (isset($config[$module][$key])) $value = ($module) ? $config[$module][$key] : null; if ($value === null AND isset($config['default'][$key])) $value = $config['default'][$key]; if ($value === null AND isset($config[$key])) $value = $config[$key]; if ($value === null and isset($config['default'][$key])) $value = $config['default'][$key]; if ($value === null and isset($config[$key])) $value = $config[$key]; if (!$optional AND $value === null) { if (!$optional and $value === null) { throw new NotFoundConfigException("Aucun valeur de trouver dans la configuration de UnicaenMail pour la clef [" . $key . "]"); } return $value; Loading @@ -204,17 +211,29 @@ EOS; $mailSymfony->from("'\"" . $fromName . "\" <" . $fromEmail . ">'"); $adresseToArray = $redirect ? explode(',', $mail->getDestinatairesInitials()) : (explode(',', $mail->getDestinataires())); $mailSymfony->to(...$adresseToArray); if ($mail->getCopies() !== null AND $mail->getCopies() !== '') { if ($mail->getCopies() !== null and $mail->getCopies() !== '') { $adresseCcArray = explode(',', $mail->getCopies()); $mailSymfony->cc(...$adresseCcArray); } if ($mail->getReplyTo() !== null OR $replyTo !== null) { if ($mail->getReplyTo() !== null or $replyTo !== null) { $mailSymfony->replyTo($mail->getReplyTo() ?? $replyTo); } $mailSymfony->subject($mail->getSujet()); $mailSymfony->html($mail->getCorps()); $mailSymfony->text(strip_tags($mail->getCorps())); //if ($mail->getAttachmentPaths()) $mailSymfony->attachFromPath($mail->getAttachmentPaths()); if ($mail->getAttachmentPaths() !== null) { $attachements = explode(MailService::ATTACHMENT_SEP, $mail->getAttachmentPaths()); foreach ($attachements as $attachement) { $extension = pathinfo($attachement, PATHINFO_EXTENSION); $basename = pathinfo($attachement, PATHINFO_BASENAME); if ($extension === 'ics') { $mailSymfony->attachFromPath($attachement, $basename, 'text/calendar; METHOD=REQUEST'); } else { $mailSymfony->attachFromPath($attachement, $basename,); } } } return $mailSymfony; } Loading Loading @@ -252,7 +271,7 @@ EOS; $corps = "<p><i>Ce courrier électronique vous a été adressé <strong>automatiquement</strong> par l'application " . $subjectPrefix . ". </i></p>" . $texte; $mail->setCorps($corps); if ($attachement_path !== null) { $attachement_path = (is_string($attachement_path)) ? $attachement_path : implode("#<>#", $attachement_path); $attachement_path = (is_string($attachement_path)) ? $attachement_path : implode(MailService::ATTACHMENT_SEP, $attachement_path); $mail->setAttachmentPaths($attachement_path); } $this->create($mail); Loading Loading @@ -356,9 +375,9 @@ EOS; $precedenteDateEnvoi = $mail->getDateEnvoi(); $supplement = "<p><strong>Ce courrier électronique est une ré-expédition du courrier envoyé initialement le " . $precedenteDateEnvoi->format('d/m/Y à H:i') . "</strong></p>"; //todo les pieces jointes $nMail = $this->sendMail($mail->getDestinataires(), $mail->getSujet(), $mail->getCorps(), null, null, null, $supplement); $nMail = $this->sendMail($mail->getDestinataires(), $mail->getSujet(), ($supplement . $mail->getCorps()), null, $mail->getAttachmentPaths(), $mail->getReplyTo()); $nMail->setMotsClefs(explode(Mail::MOTCLEF_SEPARATEUR, $mail->getMotsClefs())); $nMail->setCorps($mail->getCorps()); $this->update($nMail); return $mail; Loading Loading
CHANGELOG.md +4 −0 Original line number Diff line number Diff line Loading @@ -2,6 +2,10 @@ ----- - Bug fixe pour les envoies de mails en smtps 7.2.2 ----- - Correction du bug lié à la réexpédition d'un mail - Ajout d'une action pour controler la configuration du module 7.2.1 ----- Loading
config/merged/mail.config.php +11 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ return array( [ 'controller' => MailController::class, 'action' => [ 'afficher-configuration', 'supprimer', ], 'privileges' => [ Loading Loading @@ -122,6 +123,16 @@ return array( ], ], ], 'afficher-configuration' => [ 'type' => Literal::class, 'options' => [ 'route' => '/afficher-configuration', 'defaults' => [ /** @see MailController::afficherConfigurationAction() */ 'action' => 'afficher-configuration', ], ], ], ], ], ], Loading
src/UnicaenMail/Controller/MailController.php +10 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,16 @@ class MailController extends AbstractActionController } public function afficherConfigurationAction(): ViewModel { $config = $this->getMailService()->getConfig(); return new ViewModel([ 'title' => 'Configuration du module', 'config' => $config, ]); } public function afficherAction(): ViewModel { $mail = $this->getMailService()->getRequestedMail($this); Loading
src/UnicaenMail/Controller/MailControllerFactory.php +1 −3 Original line number Diff line number Diff line Loading @@ -2,8 +2,8 @@ namespace UnicaenMail\Controller; use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use UnicaenMail\Service\Mail\MailService; Loading @@ -11,8 +11,6 @@ class MailControllerFactory { /** * @param ContainerInterface $container * @return MailController * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ Loading
src/UnicaenMail/Service/Mail/MailService.php +30 −11 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ use RuntimeException; use Symfony\Component\Mailer\Exception\TransportExceptionInterface; use Symfony\Component\Mailer\Mailer; use Symfony\Component\Mime\Email; use Symfony\Component\Mime\Part\DataPart; use UnicaenMail\Entity\Db\Mail; use UnicaenMail\Exception\NotFoundConfigException; Loading @@ -20,6 +21,8 @@ class MailService { use ProvidesObjectManager; const ATTACHMENT_SEP = "#<>#"; const BODY_TEXT_TEMPLATE = <<<EOS ----------------------------------------------------------------------- Loading Loading @@ -77,6 +80,10 @@ EOS; $this->config = $config; } public function getConfig(): array { return $this->config; } public function createMailEntity(): object { Loading Loading @@ -178,10 +185,10 @@ EOS; $value = null; $config = $this->config['module']; if (isset($config[$module][$key])) $value = ($module) ? $config[$module][$key] : null; if ($value === null AND isset($config['default'][$key])) $value = $config['default'][$key]; if ($value === null AND isset($config[$key])) $value = $config[$key]; if ($value === null and isset($config['default'][$key])) $value = $config['default'][$key]; if ($value === null and isset($config[$key])) $value = $config[$key]; if (!$optional AND $value === null) { if (!$optional and $value === null) { throw new NotFoundConfigException("Aucun valeur de trouver dans la configuration de UnicaenMail pour la clef [" . $key . "]"); } return $value; Loading @@ -204,17 +211,29 @@ EOS; $mailSymfony->from("'\"" . $fromName . "\" <" . $fromEmail . ">'"); $adresseToArray = $redirect ? explode(',', $mail->getDestinatairesInitials()) : (explode(',', $mail->getDestinataires())); $mailSymfony->to(...$adresseToArray); if ($mail->getCopies() !== null AND $mail->getCopies() !== '') { if ($mail->getCopies() !== null and $mail->getCopies() !== '') { $adresseCcArray = explode(',', $mail->getCopies()); $mailSymfony->cc(...$adresseCcArray); } if ($mail->getReplyTo() !== null OR $replyTo !== null) { if ($mail->getReplyTo() !== null or $replyTo !== null) { $mailSymfony->replyTo($mail->getReplyTo() ?? $replyTo); } $mailSymfony->subject($mail->getSujet()); $mailSymfony->html($mail->getCorps()); $mailSymfony->text(strip_tags($mail->getCorps())); //if ($mail->getAttachmentPaths()) $mailSymfony->attachFromPath($mail->getAttachmentPaths()); if ($mail->getAttachmentPaths() !== null) { $attachements = explode(MailService::ATTACHMENT_SEP, $mail->getAttachmentPaths()); foreach ($attachements as $attachement) { $extension = pathinfo($attachement, PATHINFO_EXTENSION); $basename = pathinfo($attachement, PATHINFO_BASENAME); if ($extension === 'ics') { $mailSymfony->attachFromPath($attachement, $basename, 'text/calendar; METHOD=REQUEST'); } else { $mailSymfony->attachFromPath($attachement, $basename,); } } } return $mailSymfony; } Loading Loading @@ -252,7 +271,7 @@ EOS; $corps = "<p><i>Ce courrier électronique vous a été adressé <strong>automatiquement</strong> par l'application " . $subjectPrefix . ". </i></p>" . $texte; $mail->setCorps($corps); if ($attachement_path !== null) { $attachement_path = (is_string($attachement_path)) ? $attachement_path : implode("#<>#", $attachement_path); $attachement_path = (is_string($attachement_path)) ? $attachement_path : implode(MailService::ATTACHMENT_SEP, $attachement_path); $mail->setAttachmentPaths($attachement_path); } $this->create($mail); Loading Loading @@ -356,9 +375,9 @@ EOS; $precedenteDateEnvoi = $mail->getDateEnvoi(); $supplement = "<p><strong>Ce courrier électronique est une ré-expédition du courrier envoyé initialement le " . $precedenteDateEnvoi->format('d/m/Y à H:i') . "</strong></p>"; //todo les pieces jointes $nMail = $this->sendMail($mail->getDestinataires(), $mail->getSujet(), $mail->getCorps(), null, null, null, $supplement); $nMail = $this->sendMail($mail->getDestinataires(), $mail->getSujet(), ($supplement . $mail->getCorps()), null, $mail->getAttachmentPaths(), $mail->getReplyTo()); $nMail->setMotsClefs(explode(Mail::MOTCLEF_SEPARATEUR, $mail->getMotsClefs())); $nMail->setCorps($mail->getCorps()); $this->update($nMail); return $mail; Loading