From f20ad1091ca33bab06709aaf2b19a58149770d27 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Mon, 30 May 2016 18:40:54 +0200 Subject: [PATCH] Add MimePartFacade --- .../email/mime/MimePartFacade.class.php | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/email/mime/MimePartFacade.class.php diff --git a/wcfsetup/install/files/lib/system/email/mime/MimePartFacade.class.php b/wcfsetup/install/files/lib/system/email/mime/MimePartFacade.class.php new file mode 100644 index 0000000000..02356d068a --- /dev/null +++ b/wcfsetup/install/files/lib/system/email/mime/MimePartFacade.class.php @@ -0,0 +1,92 @@ + + * @package com.woltlab.wcf + * @subpackage system.email.mime + * @category Community Framework + * @since 2.2 + */ +class MimePartFacade extends AbstractMimePart implements IRecipientAwareMimePart { + /** + * the mime part to provide in the email + * @var AbstractMimePart + */ + protected $mimePart; + + /** + * Creates a new MimePartFacade. + * + * @see MultipartAlternativeMimePart + * @see MultipartMixedMimePart + * @param AbstractMimePart[] $texts Versions of the text part in descending priority (i.e. inside multipart/alternative) + * @param AbstractMimePart[] $attachments Attachments (i.e. inside multipart/mixed) + */ + public function __construct(array $texts, array $attachments = []) { + if (count($texts) > 1) { + $this->mimePart = new MultipartAlternativeMimePart(); + $priority = PHP_INT_MAX; + foreach ($texts as $text) { + $this->mimePart->addMimePart($text, $priority); + $priority -= 1000; + } + } + else { + $this->mimePart = $texts[0]; + } + + if (!empty($attachments)) { + $mixed = new MultipartMixedMimePart(); + $mixed->addMimePart($this->mimePart); + foreach ($attachments as $attachment) { + $mixed->addMimePart($attachment); + } + $this->mimePart = $mixed; + } + } + + /** + * @inheritDoc + */ + public function setRecipient(Mailbox $mailbox = null) { + if ($this->mimePart instanceof IRecipientAwareMimePart) { + $this->mimePart->setRecipient($mailbox); + } + } + + /** + * @inheritDoc + */ + public function getContentType() { + return $this->mimePart->getContentType(); + } + + /** + * @inheritDoc + */ + public function getContentTransferEncoding() { + return $this->mimePart->getContentTransferEncoding(); + } + + /** + * @inheritDoc + */ + public function getContent() { + return $this->mimePart->getContent(); + } + + /** + * Returns the inner mime part. + * + * @return AbstractMimePart + */ + public function getMimePart() { + return $this->mimePart; + } +} -- 2.20.1