diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Dashboard.php b/lib/Alchemy/Phrasea/Controller/Admin/Dashboard.php index cb26c7743b..106461fb01 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Dashboard.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Dashboard.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Admin; use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Mail\MailTest; +use Alchemy\Phrasea\Exception\InvalidArgumentException; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; @@ -187,7 +188,12 @@ class Dashboard implements ControllerProviderInterface $app->abort(400, 'Bad request missing email parameter'); }; - $receiver = new Receiver(null, $mail); + try { + $receiver = new Receiver(null, $mail); + } catch (InvalidArgumentException $e) { + return $app->redirect('/admin/dashboard/?email=not-sent'); + } + $mail = MailTest::create($app, $receiver); $app['notification.deliverer']->deliver($mail); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Export.php b/lib/Alchemy/Phrasea/Controller/Prod/Export.php index cac88af3db..08195f8570 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Export.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Export.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Controller\Prod; use Silex\Application; use Silex\ControllerProviderInterface; +use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Notification\Emitter; use Alchemy\Phrasea\Notification\Receiver; use Alchemy\Phrasea\Notification\Mail\MailRecordsExport; @@ -285,7 +286,11 @@ class Export implements ControllerProviderInterface $emitter = new Emitter($app['phraseanet.user']->get_display_name(), $app['phraseanet.user']->get_email()); foreach ($destMails as $key => $mail) { - $receiver = new Receiver(null, trim($mail)); + try { + $receiver = new Receiver(null, trim($mail)); + } catch (InvalidArgumentException $e) { + continue; + } $mail = MailRecordsExport::create($app, $receiver, $emitter, $request->request->get('textmail')); $mail->setButtonUrl($url); diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index b5e94425dd..6315d4adba 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -12,6 +12,7 @@ namespace Alchemy\Phrasea\Helper\User; use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Notification\Mail\MailSuccessEmailUpdate; use Alchemy\Phrasea\Notification\Receiver; use Symfony\Component\HttpFoundation\Request; @@ -539,15 +540,27 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper $new_email = $user->get_email(); if ($old_email != $new_email) { + try { + $oldReceiver = new Receiver(null, $old_email); + } catch (InvalidArgumentException $e) { - $newReceiver = new Receiver(null, $new_email); - $oldReceiver = new Receiver(null, $old_email); + } - $mailOldAddress = MailSuccessEmailUpdate::create($this->app, $oldReceiver, null, sprintf(_('You will now receive notifications at %s'), $new_email)); - $mailNewAddress = MailSuccessEmailUpdate::create($this->app, $newReceiver, null, sprintf(_('You will no longer receive notifications at %s'), $old_email)); + if ($oldReceiver) { + $mailOldAddress = MailSuccessEmailUpdate::create($this->app, $oldReceiver, null, sprintf(_('You will now receive notifications at %s'), $new_email)); + $this->app['notification.deliverer']->deliver($mailOldAddress); + } - $this->app['notification.deliverer']->deliver($mailOldAddress); - $this->app['notification.deliverer']->deliver($mailNewAddress); + try { + $newReceiver = new Receiver(null, $new_email); + } catch (InvalidArgumentException $e) { + + } + + if ($newReceiver) { + $mailNewAddress = MailSuccessEmailUpdate::create($this->app, $newReceiver, null, sprintf(_('You will no longer receive notifications at %s'), $old_email)); + $this->app['notification.deliverer']->deliver($mailNewAddress); + } } return $this; diff --git a/lib/classes/task/period/ftp.php b/lib/classes/task/period/ftp.php index 5b6c845893..a3f852b5c7 100644 --- a/lib/classes/task/period/ftp.php +++ b/lib/classes/task/period/ftp.php @@ -8,6 +8,7 @@ * file that was distributed with this source code. */ +use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Notification\Mail\MailSuccessFTP; use Alchemy\Phrasea\Notification\Receiver; @@ -658,17 +659,31 @@ class task_period_ftp extends task_appboxAbstract $sender_message = $text_mail_sender . $message; $receiver_message = $text_mail_receiver . $message; - $receiver = new Receiver(null, $sendermail); - $mail = MailSuccessFTP::create($this->dependencyContainer, $receiver, null, $sender_message); - $mail->setServer($ftp_server); + $receiver = null; + try { + $receiver = new Receiver(null, $sendermail); + } catch (InvalidArgumentException $e) { - $this->dependencyContainer['notification.deliverer']->deliver($mail); + } - $receiver = new Receiver(null, $mail); - $mail = MailSuccessFTP::create($this->dependencyContainer, $receiver, null, $receiver_message); - $mail->setServer($ftp_server); + if ($receiver) { + $mail = MailSuccessFTP::create($this->dependencyContainer, $receiver, null, $sender_message); + $mail->setServer($ftp_server); + $this->dependencyContainer['notification.deliverer']->deliver($mail); + } - $this->dependencyContainer['notification.deliverer']->deliver($mail); + $receiver = null; + try { + $receiver = new Receiver(null, $mail); + } catch (InvalidArgumentException $e) { + + } + + if ($receiver) { + $mail = MailSuccessFTP::create($this->dependencyContainer, $receiver, null, $receiver_message); + $mail->setServer($ftp_server); + $this->dependencyContainer['notification.deliverer']->deliver($mail); + } } public function logexport(record_adapter $record, $obj, $ftpLog)