From: Tim Düsterhus Date: Wed, 17 Jun 2015 21:06:06 +0000 (+0200) Subject: Add basic implementation of PhpEmailTransport X-Git-Tag: 3.0.0_Beta_1~2249^2~2^2~7 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a928fdfd5ade155154377b9853c82fcfdb45bc4d;p=GitHub%2FWoltLab%2FWCF.git Add basic implementation of PhpEmailTransport --- 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); + } +}