From 6c9b03b559b46a1de52ed71f0cfad65143e8a553 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 7 Jul 2015 21:08:57 +0200 Subject: [PATCH] Add IRecipientAwareMimePart --- .../files/lib/system/email/Email.class.php | 23 ++++++++++++++++++ .../mime/IRecipientAwareMimePart.class.php | 24 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/email/mime/IRecipientAwareMimePart.class.php diff --git a/wcfsetup/install/files/lib/system/email/Email.class.php b/wcfsetup/install/files/lib/system/email/Email.class.php index 4b42679912..5a36a8bd43 100644 --- a/wcfsetup/install/files/lib/system/email/Email.class.php +++ b/wcfsetup/install/files/lib/system/email/Email.class.php @@ -3,6 +3,7 @@ namespace wcf\system\email; use wcf\system\background\job\EmailDeliveryBackgroundJob; use wcf\system\background\BackgroundQueueHandler; use wcf\system\email\mime\AbstractMimePart; +use wcf\system\email\mime\IRecipientAwareMimePart; use wcf\system\email\mime\TextMimePart; use wcf\system\event\EventHandler; use wcf\system\exception\SystemException; @@ -404,6 +405,24 @@ class Email { } } + /** + * Returns the text mime parts of this email. + * + * @return array<\wcf\system\email\mime\TextMimePart> + */ + public function getText() { + return $this->text; + } + + /** + * Returns the attachments (i.e. the mime parts that are not a TextMimePart) of this email. + * + * @return array<\wcf\system\email\mime\AbstractMimePart> + */ + public function getAttachments() { + return $this->attachments; + } + /** * Returns an array of [ name, value ] tuples representing the email's headers. * Note: You must have set a Subject and at least one recipient, otherwise fetching the @@ -585,6 +604,10 @@ class Email { $mail->addHeader('X-Community-Framework-Recipient', $recipient[1]->getUser()->username); } + foreach (array_merge($mail->getText(), $mail->getAttachments()) as $mimePart) { + if ($mimePart[1] instanceof IRecipientAwareMimePart) $mimePart[1]->setRecipient($recipient[1]); + } + $data = [ 'mail' => $mail, 'recipient' => $recipient, 'skip' => false ]; EventHandler::getInstance()->fireAction($this, 'getJobs', $data); diff --git a/wcfsetup/install/files/lib/system/email/mime/IRecipientAwareMimePart.class.php b/wcfsetup/install/files/lib/system/email/mime/IRecipientAwareMimePart.class.php new file mode 100644 index 0000000000..8b5505d3ce --- /dev/null +++ b/wcfsetup/install/files/lib/system/email/mime/IRecipientAwareMimePart.class.php @@ -0,0 +1,24 @@ + + * @package com.woltlab.wcf + * @subpackage system.email.mime + * @category Community Framework + */ +interface IRecipientAwareMimePart { + /** + * Makes this mime part aware of it's recipient. + * Note: `null` is a valid parameter and denotes that this mime part should + * not be individualised. + * + * @param \wcf\system\email\Mailbox $mailbox + */ + public function setRecipient(Mailbox $mailbox = null); +} -- 2.20.1