Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordizzy <diosmosis@users.noreply.github.com>2021-05-30 22:21:05 +0300
committerGitHub <noreply@github.com>2021-05-30 22:21:05 +0300
commit30eec9445b0a2117f80305f7a367121039f04817 (patch)
treedff6d781055417fa6754202d6aed4f7d43efd51d /core/Mail.php
parent0e34030c2c29c9908f0cf2fca13db9ac54e62e8c (diff)
Allow aborting sending mails via Mail.send event. (#17635)
* Allow aborting sending mails via Mail.send event. * Add quick entry to developer changelog. * add test
Diffstat (limited to 'core/Mail.php')
-rw-r--r--core/Mail.php11
1 files changed, 8 insertions, 3 deletions
diff --git a/core/Mail.php b/core/Mail.php
index 2a97929b92..01f8926916 100644
--- a/core/Mail.php
+++ b/core/Mail.php
@@ -270,7 +270,7 @@ class Mail
/**
* Sends the mail
*
- * @return bool
+ * @return bool|null returns null if sending the mail was aborted by the Mail.send event
* @throws \DI\NotFoundException
*/
public function send()
@@ -285,9 +285,14 @@ class Mail
* This event is posted right before an email is sent. You can use it to customize the email by, for example, replacing
* the subject/body, changing the from address, etc.
*
- * @param Mail $mail The Mail instance that is about to be sent.
+ * @param Mail &$mail The Mail instance that is about to be sent. Set it to null to stop the email from
+ * being sent.
*/
- Piwik::postEvent('Mail.send', [$mail]);
+ Piwik::postEvent('Mail.send', [&$mail]);
+
+ if (empty($mail)) {
+ return null;
+ }
return StaticContainer::get('Piwik\Mail\Transport')->send($mail);
}