Commit 53bd23b0 authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Amélioration de la gestion des emails : ajout de vérifications pour les listes...

Amélioration de la gestion des emails : ajout de vérifications pour les listes d'emails vides et nettoyage des adresses email pour compatibilité avec Symfony/Mailer 7.4
parent 309235d6
Loading
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -27,14 +27,13 @@ class MailServiceFactory
        $context       = $container->get(ContextService::class);
        $email         = $context->getUtilisateur()?->getEmail();
        $is_redirected = $config['module']['default']['is_redirected_ose'];
        if ($is_redirected) {
        $redirectTo    = $config['module']['default']['redirect_to'];
        if ($is_redirected) {
            if ($email && empty($redirectTo)) {
                $config['module']['default']['redirect_to'] = $email;
            }
        } else {
            $config['module']['default']['redirect_to'] = [];
        }
        $config['module']['default']['redirect'] = !empty($config['module']['default']['redirect_to']);


        $transport = new EsmtpTransport(host: $config['transport_options']['host'], port: $config['transport_options']['port']);
+9 −3
Original line number Diff line number Diff line
@@ -322,6 +322,10 @@ class IndicateurController extends AbstractController
                } else {
                    $emailsList = $emails;
                }
                if (empty($emailsList)) {
                    $this->flashMessenger()->addErrorMessage("Aucun mail n'a été envoyé : aucun intervenant sélectionné ne possède d'adresse email.");
                    return $this->redirect()->toRoute('indicateur/result', ['indicateur' => $indicateur->getId()]);
                }
                $email = $this->getServiceIndicateur()->createMessage($post, $emailsList, $subject, $fromName);
                $this->getMailService()->send($email);

@@ -342,9 +346,11 @@ class IndicateurController extends AbstractController

                }
                if ($post['cci'] && !empty($post['cci'])) {
                    $emailsCci = explode(';', $post['cci']);
                    $emailsCci = array_filter(array_map('trim', explode(';', $post['cci'])));
                    if (!empty($emailsCci)) {
                        $email = $this->getServiceIndicateur()->createMessage($post, $emailsList, $subject, $fromName, $emailsCci);
                        $this->getMailService()->send($email);
                    }

                }
                $count   = count($emailsList);
+5 −3
Original line number Diff line number Diff line
@@ -244,7 +244,7 @@ class IndicateurService extends AbstractService
    public function createMessage($data,$emails,$subject, $fromName, array $emailCopy = []):Email
    {
        $email = new Email();
        $from = (isset($data['from'])) ? $data['from'] : $this->getFrom();
        $from = trim((isset($data['from'])) ? $data['from'] : $this->getFrom());
        $email->from(new Address($from, $fromName));
        $html = $data['body'];
        if(!empty($emailCopy))
@@ -262,6 +262,7 @@ class IndicateurService extends AbstractService
            //Contexte utilisateur
            foreach($emailCopy as $value)
            {
                $value = trim($value);
                if (!empty($value)) {
                    $email->addBcc($value);
                }
@@ -271,6 +272,7 @@ class IndicateurService extends AbstractService
        else{
            $email->subject($data['subject']);
            foreach ($emails as $value => $name) {
                $value = trim($value);
                if (!empty($value)) {
                    $email->addBcc(new Address($value, $name));
                }