diff --git a/protected/humhub/components/mail/Mailer.php b/protected/humhub/components/mail/Mailer.php index d39b597380..d9d74d9c75 100644 --- a/protected/humhub/components/mail/Mailer.php +++ b/protected/humhub/components/mail/Mailer.php @@ -9,6 +9,7 @@ namespace humhub\components\mail; use Yii; +use yii\mail\MailEvent; /** * Mailer implements a mailer based on SwiftMailer. @@ -25,6 +26,12 @@ class Mailer extends \yii\swiftmailer\Mailer */ public $messageClass = 'humhub\components\mail\Message'; + /** + * @var array of surpressed recipient e-mail addresses + * @since 1.3 + */ + public $surpressedRecipients = ['david.roberts@example.com', 'sara.schuster@example.com']; + /** * Creates a new message instance and optionally composes its body content via view rendering. * @@ -57,4 +64,48 @@ class Mailer extends \yii\swiftmailer\Mailer return $message; } + + /** + * @inheritdoc + * @param Message $message + */ + public function sendMessage($message) + { + // Remove example e-mails + $address = $message->getTo(); + + if (is_array($address)) { + foreach (array_keys($address) as $email) { + if ($this->isRecipientSurpressed($email)) { + unset($address[$email]); + } + } + if (count($address) == 0) { + return true; + } + $message->setTo($address); + } elseif ($this->isRecipientSurpressed($address)) { + return true; + } + + return parent::sendMessage($message); + } + + /** + * Checks if an given e-mail address is surpressed. + * + * @since 1.3 + * @param $email + * @return boolean is surpressed + */ + public function isRecipientSurpressed($email) + { + if (in_array($email, $this->surpressedRecipients)) { + return true; + } + + return false; + } + + } diff --git a/protected/humhub/docs/CHANGELOG_DEV.md b/protected/humhub/docs/CHANGELOG_DEV.md index 80bef41ddb..bfcc2a8b13 100644 --- a/protected/humhub/docs/CHANGELOG_DEV.md +++ b/protected/humhub/docs/CHANGELOG_DEV.md @@ -46,3 +46,4 @@ HumHub Change Log - v1.3-dev Branch - Enh: Added UI core module to group UI components - Enh: Added new IconPicker form field - Chg: Moved form widgets from `humhub\widgets` to `humhub\modules\ui\form\widgets` (added compatibility layer) +- Enh: Added surpressed e-mail addresses configuration variable