mirror of
https://github.com/humhub/humhub.git
synced 2025-01-18 06:38:14 +01:00
Enh: Added surpressed e-mail addresses configuration variable
This commit is contained in:
parent
80d153adeb
commit
b1a1c1a40d
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user