From a928fdfd5ade155154377b9853c82fcfdb45bc4d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 17 Jun 2015 23:06:06 +0200 Subject: [PATCH] Add basic implementation of PhpEmailTransport --- .../transport/PhpEmailTransport.class.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/email/transport/PhpEmailTransport.class.php diff --git a/wcfsetup/install/files/lib/system/email/transport/PhpEmailTransport.class.php b/wcfsetup/install/files/lib/system/email/transport/PhpEmailTransport.class.php new file mode 100644 index 0000000000..6e538283de --- /dev/null +++ b/wcfsetup/install/files/lib/system/email/transport/PhpEmailTransport.class.php @@ -0,0 +1,45 @@ + + * @package com.woltlab.wcf + * @subpackage system.email.transport + * @category Community Framework + */ +class PhpEmailTransport implements EmailTransport { + /** + * Delivers the given email via mail(). + * + * @param \wcf\system\email\Email $email + * @param \wcf\system\email\Mailbox $envelopeTo + */ + public function deliver(Email $email, Mailbox $envelopeTo) { + $headers = array_filter($email->getHeaders(), function ($item) { + // filter out headers that are either + // a) automatically added by PHP + // b) interpreted by sendmail because of -t + // + // The email will be slightly mangled as the result of this. In particular + // the 'To' and 'Cc' headers will be cleared, which makes this email appear + // to be sent to a single recipient only. + // But this is better than crippling the superior transports or special casing + // the PhpTransport in other classes. + return $item[0] !== 'subject' && $item[0] !== 'to' && $item[0] !== 'cc' && $item[0] !== 'bcc'; + }); + + $headers = implode("\r\n", array_map(function ($item) { + return implode(': ', $item); + }, $headers)); + + // TODO: -f flag + mail($envelopeTo->getAddress(), $email->getSubject(), StringUtil::unifyNewlines($email->getBodyString()), $headers); + } +} -- 2.20.1