From: Tim Düsterhus Date: Tue, 14 Jun 2016 21:36:06 +0000 (+0200) Subject: Allow overriding the envelope sender in Email::getJobs() X-Git-Tag: 3.0.0_Beta_1~1441 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=2d3ca5bfc266ec1121463d9fd7a99d482597d1a5;p=GitHub%2FWoltLab%2FWCF.git Allow overriding the envelope sender in Email::getJobs() --- diff --git a/wcfsetup/install/files/lib/system/background/job/EmailDeliveryBackgroundJob.class.php b/wcfsetup/install/files/lib/system/background/job/EmailDeliveryBackgroundJob.class.php index f5ed2cf89d..77cdc4edc9 100644 --- a/wcfsetup/install/files/lib/system/background/job/EmailDeliveryBackgroundJob.class.php +++ b/wcfsetup/install/files/lib/system/background/job/EmailDeliveryBackgroundJob.class.php @@ -22,11 +22,17 @@ class EmailDeliveryBackgroundJob extends AbstractBackgroundJob { */ protected $email; + /** + * sender mailbox + * @var \wcf\system\email\Mailbox + */ + protected $envelopeFrom; + /** * recipient mailbox * @var \wcf\system\email\Mailbox */ - protected $mailbox; + protected $envelopeTo; /** * instance of the default transport @@ -38,12 +44,14 @@ class EmailDeliveryBackgroundJob extends AbstractBackgroundJob { * Creates the job using the given the email and the destination mailbox. * * @param \wcf\system\email\Email $email - * @param \wcf\system\email\Mailbox $mailbox + * @param \wcf\system\email\Mailbox $envelopeFrom + * @param \wcf\system\email\Mailbox $envelopeTo * @see \wcf\system\email\transport\EmailTransport */ - public function __construct(Email $email, Mailbox $mailbox) { + public function __construct(Email $email, Mailbox $envelopeFrom, Mailbox $envelopeTo) { $this->email = $email; - $this->mailbox = $mailbox; + $this->envelopeFrom = $envelopeFrom; + $this->envelopeTo = $envelopeTo; } /** @@ -72,7 +80,7 @@ class EmailDeliveryBackgroundJob extends AbstractBackgroundJob { } try { - self::$transport->deliver($this->email, $this->mailbox); + self::$transport->deliver($this->email, $this->envelopeFrom, $this->envelopeTo); } catch (PermanentFailure $e) { // no need for retrying. Eat Exception and log the error. diff --git a/wcfsetup/install/files/lib/system/email/Email.class.php b/wcfsetup/install/files/lib/system/email/Email.class.php index 0dc8c46538..5f2dbc9d7f 100644 --- a/wcfsetup/install/files/lib/system/email/Email.class.php +++ b/wcfsetup/install/files/lib/system/email/Email.class.php @@ -492,6 +492,7 @@ class Email { $data = [ 'mail' => $mail, 'recipient' => $recipient, + 'sender' => $mail->getSender(), 'skip' => false ]; EventHandler::getInstance()->fireAction($this, 'getJobs', $data); @@ -499,7 +500,7 @@ class Email { // an event decided that this email should be skipped if ($data['skip']) continue; - $jobs[] = new EmailDeliveryBackgroundJob($mail, $recipient['mailbox']); + $jobs[] = new EmailDeliveryBackgroundJob($mail, $data['sender'], $data['recipient']['mailbox']); } return $jobs; diff --git a/wcfsetup/install/files/lib/system/email/transport/DebugEmailTransport.class.php b/wcfsetup/install/files/lib/system/email/transport/DebugEmailTransport.class.php index fd19a4b980..bf0d94d889 100644 --- a/wcfsetup/install/files/lib/system/email/transport/DebugEmailTransport.class.php +++ b/wcfsetup/install/files/lib/system/email/transport/DebugEmailTransport.class.php @@ -39,10 +39,11 @@ class DebugEmailTransport implements EmailTransport { * Writes the given $email into the mbox. * * @param \wcf\system\email\Email $email + * @param \wcf\system\email\Mailbox $envelopeFrom * @param \wcf\system\email\Mailbox $envelopeTo */ - public function deliver(Email $email, Mailbox $envelopeTo) { - $this->mbox->write("From ".$email->getSender()->getAddress()." ".DateUtil::getDateTimeByTimestamp(TIME_NOW)->format('D M d H:i:s Y')."\r\n"); + public function deliver(Email $email, Mailbox $envelopeFrom, Mailbox $envelopeTo) { + $this->mbox->write("From ".$envelopeFrom->getAddress()." ".DateUtil::getDateTimeByTimestamp(TIME_NOW)->format('D M d H:i:s Y')."\r\n"); $this->mbox->write("Delivered-To: ".$envelopeTo->getAddress()."\r\n"); $this->mbox->write($email->getEmail()); $this->mbox->write("\r\n"); diff --git a/wcfsetup/install/files/lib/system/email/transport/EmailTransport.class.php b/wcfsetup/install/files/lib/system/email/transport/EmailTransport.class.php index 1c193b4efb..1a3b4c82c6 100644 --- a/wcfsetup/install/files/lib/system/email/transport/EmailTransport.class.php +++ b/wcfsetup/install/files/lib/system/email/transport/EmailTransport.class.php @@ -19,7 +19,8 @@ interface EmailTransport { * Delivers the given $email to the given Mailbox as the recipient. * * @param \wcf\system\email\Email $email + * @param \wcf\system\email\Mailbox $envelopeFrom * @param \wcf\system\email\Mailbox $envelopeTo */ - public function deliver(Email $email, Mailbox $envelopeTo); + public function deliver(Email $email, Mailbox $envelopeFrom, Mailbox $envelopeTo); } diff --git a/wcfsetup/install/files/lib/system/email/transport/PhpEmailTransport.class.php b/wcfsetup/install/files/lib/system/email/transport/PhpEmailTransport.class.php index 3f97c14313..3d706a2605 100644 --- a/wcfsetup/install/files/lib/system/email/transport/PhpEmailTransport.class.php +++ b/wcfsetup/install/files/lib/system/email/transport/PhpEmailTransport.class.php @@ -21,9 +21,10 @@ class PhpEmailTransport implements EmailTransport { * Delivers the given email via mail(). * * @param \wcf\system\email\Email $email + * @param \wcf\system\email\Mailbox $envelopeFrom * @param \wcf\system\email\Mailbox $envelopeTo */ - public function deliver(Email $email, Mailbox $envelopeTo) { + public function deliver(Email $email, Mailbox $envelopeFrom, Mailbox $envelopeTo) { $headers = array_filter($email->getHeaders(), function ($item) { // filter out headers that are either // a) automatically added by PHP @@ -42,7 +43,7 @@ class PhpEmailTransport implements EmailTransport { }, $headers)); if (MAIL_USE_F_PARAM) { - $return = mail($envelopeTo->getAddress(), $email->getSubject(), StringUtil::unifyNewlines($email->getBodyString()), $headers, '-f'.$email->getSender()->getAddress()); + $return = mail($envelopeTo->getAddress(), $email->getSubject(), StringUtil::unifyNewlines($email->getBodyString()), $headers, '-f'.$envelopeFrom->getAddress()); } else { $return = mail($envelopeTo->getAddress(), $email->getSubject(), StringUtil::unifyNewlines($email->getBodyString()), $headers); diff --git a/wcfsetup/install/files/lib/system/email/transport/SmtpEmailTransport.class.php b/wcfsetup/install/files/lib/system/email/transport/SmtpEmailTransport.class.php index 87dff5a035..6a6c6c84ac 100644 --- a/wcfsetup/install/files/lib/system/email/transport/SmtpEmailTransport.class.php +++ b/wcfsetup/install/files/lib/system/email/transport/SmtpEmailTransport.class.php @@ -314,13 +314,14 @@ class SmtpEmailTransport implements EmailTransport { * Delivers the given email using SMTP. * * @param Email $email + * @param Mailbox $envelopeFrom * @param Mailbox $envelopeTo * @throws \Exception * @throws PermanentFailure * @throws TransientFailure * @throws SystemException */ - public function deliver(Email $email, Mailbox $envelopeTo) { + public function deliver(Email $email, Mailbox $envelopeFrom, Mailbox $envelopeTo) { // delivery is locked if ($this->locked instanceof \Exception) { throw $this->locked;