*/
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
* 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;
}
/**
}
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.
$data = [
'mail' => $mail,
'recipient' => $recipient,
+ 'sender' => $mail->getSender(),
'skip' => false
];
EventHandler::getInstance()->fireAction($this, 'getJobs', $data);
// 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;
* 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");
* 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);
}
* 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
}, $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);
* 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;