Add IRecipientAwareMimePart
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 7 Jul 2015 19:08:57 +0000 (21:08 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 14 Jul 2015 18:58:29 +0000 (20:58 +0200)
wcfsetup/install/files/lib/system/email/Email.class.php
wcfsetup/install/files/lib/system/email/mime/IRecipientAwareMimePart.class.php [new file with mode: 0644]

index 4b426799127fbcf5d815254ddc0e7dcfc333a617..5a36a8bd43b0730d428120ff013fb674c1c4c85d 100644 (file)
@@ -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 (file)
index 0000000..8b5505d
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+namespace wcf\system\email\mime;
+use wcf\system\email\Mailbox;
+
+/**
+ * Represents a mime part that can be customized based in the recipient Mailbox.
+ * 
+ * @author     Tim Duesterhus
+ * @copyright  2001-2015 WoltLab GmbH
+ * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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);
+}