Fix sender info not being available until the before trigger has been called

This commit is contained in:
Kijin Sung 2023-04-23 00:40:58 +09:00
parent 4f73c9562b
commit 8db0b06b6a

View file

@ -564,12 +564,6 @@ class Mail
$this->caller = $backtrace[0]['file'] . ($backtrace[0]['line'] ? (' line ' . $backtrace[0]['line']) : '');
}
// Reset Message-ID in case send() is called multiple times.
$random = substr(hash('sha256', mt_rand() . microtime() . getmypid()), 0, 32);
$sender = $this->message->getFrom(); reset($sender);
$id = $random . '@' . (preg_match('/^(.+)@([^@]+)$/', key($sender), $matches) ? $matches[2] : 'swift.generated');
$this->message->getHeaders()->get('Message-ID')->setId($id);
$output = \ModuleHandler::triggerCall('mail.send', 'before', $this);
if(!$output->toBool())
{
@ -577,6 +571,13 @@ class Mail
return false;
}
// Reset Message-ID in case send() is called multiple times.
$random = substr(hash('sha256', mt_rand() . microtime() . getmypid()), 0, 32);
$sender = $this->message->getFrom();
$sender_email = strval(array_first_key($sender));
$id = $random . '@' . (preg_match('/^(.+)@([^@]+)$/', $sender_email, $matches) ? $matches[2] : 'swift.generated');
$this->message->getHeaders()->get('Message-ID')->setId($id);
try
{
$this->sent = $this->driver->send($this) ? true : false;