diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2020-03-25 08:10:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-25 08:10:04 +0100 |
commit | b93e1e300e70bca18f7ba822f6d8dfa09bc86803 (patch) | |
tree | 0088ff767b61915b8116692e46a6def2d6fe98db /lib/private | |
parent | 52957d99d8c4d971d2ad68b87311fde759d784d7 (diff) | |
parent | a16aa995866d3319d9f848e0d5811786fad2f223 (diff) | |
download | nextcloud-server-b93e1e300e70bca18f7ba822f6d8dfa09bc86803.tar.gz nextcloud-server-b93e1e300e70bca18f7ba822f6d8dfa09bc86803.zip |
Merge pull request #14722 from tacruc/GpgMailerHooks
Add Mailer events
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Mail/Mailer.php | 14 | ||||
-rw-r--r-- | lib/private/Mail/Message.php | 17 | ||||
-rw-r--r-- | lib/private/Server.php | 3 |
3 files changed, 28 insertions, 6 deletions
diff --git a/lib/private/Mail/Mailer.php b/lib/private/Mail/Mailer.php index df5f2687daa..47a7f8a7c9d 100644 --- a/lib/private/Mail/Mailer.php +++ b/lib/private/Mail/Mailer.php @@ -12,6 +12,7 @@ declare(strict_types=1); * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Arne Hamann <github@arne.email> * * @license AGPL-3.0 * @@ -34,6 +35,7 @@ namespace OC\Mail; use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Validation\RFCValidation; use OCP\Defaults; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -42,6 +44,8 @@ use OCP\Mail\IAttachment; use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; use OCP\Mail\IMessage; +use OCP\Mail\Events\BeforeMessageSent; + /** * Class Mailer provides some basic functions to create a mail message that can be used in combination with @@ -74,6 +78,8 @@ class Mailer implements IMailer { private $urlGenerator; /** @var IL10N */ private $l10n; + /** @var IEventDispatcher */ + private $dispatcher; /** * @param IConfig $config @@ -81,17 +87,20 @@ class Mailer implements IMailer { * @param Defaults $defaults * @param IURLGenerator $urlGenerator * @param IL10N $l10n + * @param IEventDispatcher $dispatcher */ public function __construct(IConfig $config, ILogger $logger, Defaults $defaults, IURLGenerator $urlGenerator, - IL10N $l10n) { + IL10N $l10n, + IEventDispatcher $dispatcher) { $this->config = $config; $this->logger = $logger; $this->defaults = $defaults; $this->urlGenerator = $urlGenerator; $this->l10n = $l10n; + $this->dispatcher = $dispatcher; } /** @@ -182,6 +191,9 @@ class Mailer implements IMailer { $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); } + + $this->dispatcher->dispatchTyped(new BeforeMessageSent($message)); + $mailer->send($message->getSwiftMessage(), $failedRecipients); // Debugging logging diff --git a/lib/private/Mail/Message.php b/lib/private/Mail/Message.php index 4ea9da532b6..9437bd0216f 100644 --- a/lib/private/Mail/Message.php +++ b/lib/private/Mail/Message.php @@ -11,6 +11,7 @@ declare(strict_types=1); * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> + * @author Arne Hamann <github@arne.email> * * @license AGPL-3.0 * @@ -112,7 +113,7 @@ class Message implements IMessage { * @return array */ public function getFrom(): array { - return $this->swiftMessage->getFrom(); + return $this->swiftMessage->getFrom() ?? []; } /** @@ -156,7 +157,7 @@ class Message implements IMessage { * @return array */ public function getTo(): array { - return $this->swiftMessage->getTo(); + return $this->swiftMessage->getTo() ?? []; } /** @@ -178,7 +179,7 @@ class Message implements IMessage { * @return array */ public function getCc(): array { - return $this->swiftMessage->getCc(); + return $this->swiftMessage->getCc() ?? []; } /** @@ -200,7 +201,7 @@ class Message implements IMessage { * @return array */ public function getBcc(): array { - return $this->swiftMessage->getBcc(); + return $this->swiftMessage->getBcc() ?? []; } /** @@ -258,6 +259,14 @@ class Message implements IMessage { /** * Get's the underlying SwiftMessage + * @param Swift_Message $swiftMessage + */ + public function setSwiftMessage(Swift_Message $swiftMessage): void { + $this->swiftMessage = $swiftMessage; + } + + /** + * Get's the underlying SwiftMessage * @return Swift_Message */ public function getSwiftMessage(): Swift_Message { diff --git a/lib/private/Server.php b/lib/private/Server.php index 3300920edb7..971b144e1d0 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -988,7 +988,8 @@ class Server extends ServerContainer implements IServerContainer { $c->getLogger(), $c->query(Defaults::class), $c->getURLGenerator(), - $c->getL10N('lib') + $c->getL10N('lib'), + $c->query(IEventDispatcher::class) ); }); $this->registerDeprecatedAlias('Mailer', IMailer::class); |