diff --git a/CHANGELOG.md b/CHANGELOG.md index 35b52d246718deabe1b32cad4dcb2a69283f234a..089e080d7a3bf6d1fa773effeb21c014439acf71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 ----- diff --git a/config/merged/mail.config.php b/config/merged/mail.config.php index 5e8d82906ead3f352e1077ff3bd81ce57a99674a..bc17705183dc84dfb3ee72185a511d1d986e3305 100644 --- a/config/merged/mail.config.php +++ b/config/merged/mail.config.php @@ -56,6 +56,7 @@ return array( [ 'controller' => MailController::class, 'action' => [ + 'afficher-configuration', 'supprimer', ], 'privileges' => [ @@ -122,6 +123,16 @@ return array( ], ], ], + 'afficher-configuration' => [ + 'type' => Literal::class, + 'options' => [ + 'route' => '/afficher-configuration', + 'defaults' => [ + /** @see MailController::afficherConfigurationAction() */ + 'action' => 'afficher-configuration', + ], + ], + ], ], ], ], diff --git a/src/UnicaenMail/Controller/MailController.php b/src/UnicaenMail/Controller/MailController.php index 5bcffa87f3ca182998ef636c55ac7a2a40eb852e..9812697fcc108d36cf541730dfb834ec86a24758 100644 --- a/src/UnicaenMail/Controller/MailController.php +++ b/src/UnicaenMail/Controller/MailController.php @@ -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); diff --git a/src/UnicaenMail/Controller/MailControllerFactory.php b/src/UnicaenMail/Controller/MailControllerFactory.php index 5c06f162191f55106de073b54d1ed04b4aa1558f..412f5390e539d99d7475de1df32ab1ec10a6cdd9 100644 --- a/src/UnicaenMail/Controller/MailControllerFactory.php +++ b/src/UnicaenMail/Controller/MailControllerFactory.php @@ -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; @@ -11,8 +11,6 @@ class MailControllerFactory { /** - * @param ContainerInterface $container - * @return MailController * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ diff --git a/src/UnicaenMail/Service/Mail/MailService.php b/src/UnicaenMail/Service/Mail/MailService.php index 8683fab4ec252a604a9eea7e1fe2041f3b877972..20538f1b6cfa1853003fbaad4252f77402db3ee3 100644 --- a/src/UnicaenMail/Service/Mail/MailService.php +++ b/src/UnicaenMail/Service/Mail/MailService.php @@ -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; @@ -20,6 +21,8 @@ class MailService { use ProvidesObjectManager; + const ATTACHMENT_SEP = "#<>#"; + const BODY_TEXT_TEMPLATE = <<<EOS ----------------------------------------------------------------------- @@ -77,6 +80,10 @@ EOS; $this->config = $config; } + public function getConfig(): array + { + return $this->config; + } public function createMailEntity(): object { @@ -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; @@ -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) { - $mailSymfony->replyTo($mail->getReplyTo()??$replyTo); + 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; } @@ -240,7 +259,7 @@ EOS; $mail->setStatusEnvoi(Mail::PENDING); if ($redirect) { $mail->setDestinatairesInitials($to); - $mail->setDestinataires(implode(',',$redirectTo)); + $mail->setDestinataires(implode(',', $redirectTo)); } else { $mail->setDestinataires($to); } @@ -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); @@ -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; diff --git a/src/UnicaenMail/Service/Mail/MailServiceFactory.php b/src/UnicaenMail/Service/Mail/MailServiceFactory.php index 3a4443226ba6b008adc6ae442057ea6758929c25..dc1255be8dd879fbd410724f034aa605a8553d4b 100644 --- a/src/UnicaenMail/Service/Mail/MailServiceFactory.php +++ b/src/UnicaenMail/Service/Mail/MailServiceFactory.php @@ -3,8 +3,8 @@ namespace UnicaenMail\Service\Mail; use Doctrine\ORM\EntityManager; -use Interop\Container\ContainerInterface; use Psr\Container\ContainerExceptionInterface; +use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; use Symfony\Component\Mailer\Mailer; use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport; diff --git a/view/unicaen-mail/mail/afficher-configuration.phtml b/view/unicaen-mail/mail/afficher-configuration.phtml new file mode 100644 index 0000000000000000000000000000000000000000..f8d8e1f0b7b313e4196e0e99b2837f6dc82c71dc --- /dev/null +++ b/view/unicaen-mail/mail/afficher-configuration.phtml @@ -0,0 +1,14 @@ +<?php + +/** + * @see \UnicaenMail\Controller\MailController::afficherConfigurationAction() + * @var array $config + */ + +?> + + +<?php foreach ($config as $key => $value): ?> + <h2> <?php echo $key; ?> </h2> + <?php var_dump($value); ?> +<?php endforeach; ?> diff --git a/view/unicaen-mail/mail/index.phtml b/view/unicaen-mail/mail/index.phtml index 58241edc1419611659e98f73f01ddd2a3be1cbd9..79c1906d9e3f149dd4e3ce10a34e0d79f97fc549 100644 --- a/view/unicaen-mail/mail/index.phtml +++ b/view/unicaen-mail/mail/index.phtml @@ -14,6 +14,7 @@ $this->headTitle($title); $canTest = $this->isAllowed(MailPrivileges::getResourceId(MailPrivileges::MAIL_AFFICHER)); +$canAfficherConfiguration = $this->isAllowed(MailPrivileges::getResourceId(MailPrivileges::MAIL_SUPPRIMER)); ?> @@ -23,11 +24,22 @@ $canTest = $this->isAllowed(MailPrivileges::getResourceId(MailPrivileges::MAIL_A <div class="row mb-3"> <div class="col-md-12"> - <a href="<?php echo $this->url('mail/test', [], [], true); ?>" - class="btn btn-primary action ajax-modal" data-event="modification"> - <span class="icon icon-notifier"></span> - Envoi d'un mail de test - </a> + <?php if ($canTest): ?> + <?php /** @see \UnicaenMail\Controller\MailController::testAction() */ ?> + <a href="<?php echo $this->url('mail/test', [], [], true); ?>" + class="btn btn-primary ajax-modal" data-event="modification"> + <span class="icon icon-notifier"></span> + Envoi d'un mail de test + </a> + <?php endif; ?> + <?php if ($canAfficherConfiguration) : ?> + <?php /** @see \UnicaenMail\Controller\MailController::afficherConfigurationAction() */ ?> + <a href="<?php echo $this->url('mail/afficher-configuration', [], [], true); ?>" + class="btn btn-secondary ajax-modal"> + <span class="icon icon-gerer"></span> + Vérification de la configuration + </a> + <?php endif; ?> </div> </div>