From: Tim Düsterhus Date: Mon, 30 May 2016 16:40:54 +0000 (+0200) Subject: Add MimePartFacade X-Git-Tag: 3.0.0_Beta_1~1568^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f20ad1091ca33bab06709aaf2b19a58149770d27;p=GitHub%2FWoltLab%2FWCF.git Add MimePartFacade --- 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; + } +}