Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/adapter/PhabricatorMailSendmailAdapter.php
| <?php | <?php | ||||
| /** | final class PhabricatorMailSendmailAdapter | ||||
amckinley: Hooray! | |||||
| * TODO: Should be final, but inherited by SES. | |||||
| * | |||||
| * @concrete-extensible | |||||
| */ | |||||
| class PhabricatorMailSendmailAdapter | |||||
| extends PhabricatorMailAdapter { | extends PhabricatorMailAdapter { | ||||
| const ADAPTERTYPE = 'sendmail'; | const ADAPTERTYPE = 'sendmail'; | ||||
| protected $mailer; | |||||
| public function getSupportedMessageTypes() { | |||||
| return array( | |||||
| PhabricatorMailEmailMessage::MESSAGETYPE, | |||||
| ); | |||||
| } | |||||
| public function supportsMessageIDHeader() { | |||||
| return true; | |||||
| } | |||||
| protected function validateOptions(array $options) { | protected function validateOptions(array $options) { | ||||
| PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
| $options, | $options, | ||||
| array( | array( | ||||
| 'encoding' => 'string', | 'encoding' => 'string', | ||||
| )); | )); | ||||
| } | } | ||||
| public function newDefaultOptions() { | public function newDefaultOptions() { | ||||
| return array( | return array( | ||||
| 'encoding' => 'base64', | 'encoding' => 'base64', | ||||
| ); | ); | ||||
| } | } | ||||
| /** | /** | ||||
| * @phutil-external-symbol class PHPMailerLite | * @phutil-external-symbol class PHPMailerLite | ||||
| */ | */ | ||||
| public function prepareForSend() { | public function sendMessage(PhabricatorMailExternalMessage $message) { | ||||
| $root = phutil_get_library_root('phabricator'); | $root = phutil_get_library_root('phabricator'); | ||||
| $root = dirname($root); | $root = dirname($root); | ||||
| require_once $root.'/externals/phpmailer/class.phpmailer-lite.php'; | require_once $root.'/externals/phpmailer/class.phpmailer-lite.php'; | ||||
| $this->mailer = new PHPMailerLite($use_exceptions = true); | |||||
| $this->mailer->CharSet = 'utf-8'; | |||||
| $encoding = $this->getOption('encoding'); | |||||
| $this->mailer->Encoding = $encoding; | |||||
| // By default, PHPMailerLite sends one mail per recipient. We handle | |||||
| // combining or separating To and Cc higher in the stack, so tell it to | |||||
| // send mail exactly like we ask. | |||||
| $this->mailer->SingleTo = false; | |||||
| } | |||||
| public function supportsMessageIDHeader() { | |||||
| return true; | |||||
| } | |||||
| public function setFrom($email, $name = '') { | |||||
| $this->mailer->SetFrom($email, $name, $crazy_side_effects = false); | |||||
| return $this; | |||||
| } | |||||
| public function addReplyTo($email, $name = '') { | |||||
| $this->mailer->AddReplyTo($email, $name); | |||||
| return $this; | |||||
| } | |||||
| public function addTos(array $emails) { | |||||
| foreach ($emails as $email) { | |||||
| $this->mailer->AddAddress($email); | |||||
| } | |||||
| return $this; | |||||
| } | |||||
| public function addCCs(array $emails) { | |||||
| foreach ($emails as $email) { | |||||
| $this->mailer->AddCC($email); | |||||
| } | |||||
| return $this; | |||||
| } | |||||
| public function addAttachment($data, $filename, $mimetype) { | |||||
| $this->mailer->AddStringAttachment( | |||||
| $data, | |||||
| $filename, | |||||
| 'base64', | |||||
| $mimetype); | |||||
| return $this; | |||||
| } | |||||
| public function addHeader($header_name, $header_value) { | |||||
| if (strtolower($header_name) == 'message-id') { | |||||
| $this->mailer->MessageID = $header_value; | |||||
| } else { | |||||
| $this->mailer->AddCustomHeader($header_name.': '.$header_value); | |||||
| } | |||||
| return $this; | |||||
| } | |||||
| public function setBody($body) { | |||||
| $this->mailer->Body = $body; | |||||
| $this->mailer->IsHTML(false); | |||||
| return $this; | |||||
| } | |||||
| /** | |||||
| * Note: phpmailer-lite does NOT support sending messages with mixed version | |||||
| * (plaintext and html). So for now lets just use HTML if it's available. | |||||
| * @param $html | |||||
| */ | |||||
Done Inline ActionsOh, and I believe this ("..does NOT support..") wasn't right, the way to do it is just a little tricky (->AltBody). Or maybe this was true when written, then we updated PHPMailerLite, then it became untrue? In either case, we build HTML + Text mail now. epriestley: Oh, and I believe this ("..does NOT support..") wasn't right, the way to do it is just a little… | |||||
| public function setHTMLBody($html_body) { | |||||
| $this->mailer->Body = $html_body; | |||||
| $this->mailer->IsHTML(true); | |||||
| return $this; | |||||
| } | |||||
| public function setSubject($subject) { | |||||
| $this->mailer->Subject = $subject; | |||||
| return $this; | |||||
| } | |||||
| public function hasValidRecipients() { | |||||
| return true; | |||||
| } | |||||
| public function send() { | $mailer = PHPMailerLite::newFromMessage($message); | ||||
| return $this->mailer->Send(); | $mailer->Send(); | ||||
| } | } | ||||
| } | } | ||||
Hooray!