Page MenuHomePhabricator

D19961.diff
No OneTemporary

D19961.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3417,15 +3417,15 @@
'PhabricatorMailOutboundRoutingSelfEmailHeraldAction' => 'applications/metamta/herald/PhabricatorMailOutboundRoutingSelfEmailHeraldAction.php',
'PhabricatorMailOutboundRoutingSelfNotificationHeraldAction' => 'applications/metamta/herald/PhabricatorMailOutboundRoutingSelfNotificationHeraldAction.php',
'PhabricatorMailOutboundStatus' => 'applications/metamta/constants/PhabricatorMailOutboundStatus.php',
- 'PhabricatorMailPHPMailerAdapter' => 'applications/metamta/adapter/PhabricatorMailPHPMailerAdapter.php',
- 'PhabricatorMailPHPMailerLiteAdapter' => 'applications/metamta/adapter/PhabricatorMailPHPMailerLiteAdapter.php',
'PhabricatorMailPostmarkAdapter' => 'applications/metamta/adapter/PhabricatorMailPostmarkAdapter.php',
'PhabricatorMailPropertiesDestructionEngineExtension' => 'applications/metamta/engineextension/PhabricatorMailPropertiesDestructionEngineExtension.php',
'PhabricatorMailReceiver' => 'applications/metamta/receiver/PhabricatorMailReceiver.php',
'PhabricatorMailReceiverTestCase' => 'applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php',
'PhabricatorMailReplyHandler' => 'applications/metamta/replyhandler/PhabricatorMailReplyHandler.php',
'PhabricatorMailRoutingRule' => 'applications/metamta/constants/PhabricatorMailRoutingRule.php',
+ 'PhabricatorMailSMTPAdapter' => 'applications/metamta/adapter/PhabricatorMailSMTPAdapter.php',
'PhabricatorMailSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailSendGridAdapter.php',
+ 'PhabricatorMailSendmailAdapter' => 'applications/metamta/adapter/PhabricatorMailSendmailAdapter.php',
'PhabricatorMailSetupCheck' => 'applications/config/check/PhabricatorMailSetupCheck.php',
'PhabricatorMailStamp' => 'applications/metamta/stamp/PhabricatorMailStamp.php',
'PhabricatorMailTarget' => 'applications/metamta/replyhandler/PhabricatorMailTarget.php',
@@ -9222,7 +9222,7 @@
'PhabricatorMacroTransactionType' => 'PhabricatorModularTransactionType',
'PhabricatorMacroViewController' => 'PhabricatorMacroController',
'PhabricatorMailAdapter' => 'Phobject',
- 'PhabricatorMailAmazonSESAdapter' => 'PhabricatorMailPHPMailerLiteAdapter',
+ 'PhabricatorMailAmazonSESAdapter' => 'PhabricatorMailSendmailAdapter',
'PhabricatorMailAttachment' => 'Phobject',
'PhabricatorMailConfigTestCase' => 'PhabricatorTestCase',
'PhabricatorMailEmailEngine' => 'PhabricatorMailMessageEngine',
@@ -9251,15 +9251,15 @@
'PhabricatorMailOutboundRoutingSelfEmailHeraldAction' => 'PhabricatorMailOutboundRoutingHeraldAction',
'PhabricatorMailOutboundRoutingSelfNotificationHeraldAction' => 'PhabricatorMailOutboundRoutingHeraldAction',
'PhabricatorMailOutboundStatus' => 'Phobject',
- 'PhabricatorMailPHPMailerAdapter' => 'PhabricatorMailAdapter',
- 'PhabricatorMailPHPMailerLiteAdapter' => 'PhabricatorMailAdapter',
'PhabricatorMailPostmarkAdapter' => 'PhabricatorMailAdapter',
'PhabricatorMailPropertiesDestructionEngineExtension' => 'PhabricatorDestructionEngineExtension',
'PhabricatorMailReceiver' => 'Phobject',
'PhabricatorMailReceiverTestCase' => 'PhabricatorTestCase',
'PhabricatorMailReplyHandler' => 'Phobject',
'PhabricatorMailRoutingRule' => 'Phobject',
+ 'PhabricatorMailSMTPAdapter' => 'PhabricatorMailAdapter',
'PhabricatorMailSendGridAdapter' => 'PhabricatorMailAdapter',
+ 'PhabricatorMailSendmailAdapter' => 'PhabricatorMailAdapter',
'PhabricatorMailSetupCheck' => 'PhabricatorSetupCheck',
'PhabricatorMailStamp' => 'Phobject',
'PhabricatorMailTarget' => 'Phobject',
diff --git a/src/applications/metamta/adapter/PhabricatorMailAmazonSESAdapter.php b/src/applications/metamta/adapter/PhabricatorMailAmazonSESAdapter.php
--- a/src/applications/metamta/adapter/PhabricatorMailAmazonSESAdapter.php
+++ b/src/applications/metamta/adapter/PhabricatorMailAmazonSESAdapter.php
@@ -1,7 +1,7 @@
<?php
final class PhabricatorMailAmazonSESAdapter
- extends PhabricatorMailPHPMailerLiteAdapter {
+ extends PhabricatorMailSendmailAdapter {
const ADAPTERTYPE = 'ses';
diff --git a/src/applications/metamta/adapter/PhabricatorMailPHPMailerAdapter.php b/src/applications/metamta/adapter/PhabricatorMailPHPMailerAdapter.php
deleted file mode 100644
--- a/src/applications/metamta/adapter/PhabricatorMailPHPMailerAdapter.php
+++ /dev/null
@@ -1,150 +0,0 @@
-<?php
-
-final class PhabricatorMailPHPMailerAdapter
- extends PhabricatorMailAdapter {
-
- const ADAPTERTYPE = 'smtp';
-
- private $mailer;
-
- protected function validateOptions(array $options) {
- PhutilTypeSpec::checkMap(
- $options,
- array(
- 'host' => 'string|null',
- 'port' => 'int',
- 'user' => 'string|null',
- 'password' => 'string|null',
- 'protocol' => 'string|null',
- 'encoding' => 'string',
- 'mailer' => 'string',
- ));
- }
-
- public function newDefaultOptions() {
- return array(
- 'host' => null,
- 'port' => 25,
- 'user' => null,
- 'password' => null,
- 'protocol' => null,
- 'encoding' => 'base64',
- 'mailer' => 'smtp',
- );
- }
-
- /**
- * @phutil-external-symbol class PHPMailer
- */
- public function prepareForSend() {
- $root = phutil_get_library_root('phabricator');
- $root = dirname($root);
- require_once $root.'/externals/phpmailer/class.phpmailer.php';
- $this->mailer = new PHPMailer($use_exceptions = true);
- $this->mailer->CharSet = 'utf-8';
-
- $encoding = $this->getOption('encoding');
- $this->mailer->Encoding = $encoding;
-
- // By default, PHPMailer 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;
-
- $mailer = $this->getOption('mailer');
- if ($mailer == 'smtp') {
- $this->mailer->IsSMTP();
- $this->mailer->Host = $this->getOption('host');
- $this->mailer->Port = $this->getOption('port');
- $user = $this->getOption('user');
- if ($user) {
- $this->mailer->SMTPAuth = true;
- $this->mailer->Username = $user;
- $this->mailer->Password = $this->getOption('password');
- }
-
- $protocol = $this->getOption('protocol');
- if ($protocol) {
- $protocol = phutil_utf8_strtolower($protocol);
- $this->mailer->SMTPSecure = $protocol;
- }
- } else if ($mailer == 'sendmail') {
- $this->mailer->IsSendmail();
- } else {
- // Do nothing, by default PHPMailer send message using PHP mail()
- // function.
- }
- }
-
- 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->IsHTML(false);
- $this->mailer->Body = $body;
- return $this;
- }
-
- public function setHTMLBody($html_body) {
- $this->mailer->IsHTML(true);
- $this->mailer->Body = $html_body;
- return $this;
- }
-
- public function setSubject($subject) {
- $this->mailer->Subject = $subject;
- return $this;
- }
-
- public function hasValidRecipients() {
- return true;
- }
-
- public function send() {
- return $this->mailer->Send();
- }
-
-}
diff --git a/src/applications/metamta/adapter/PhabricatorMailSMTPAdapter.php b/src/applications/metamta/adapter/PhabricatorMailSMTPAdapter.php
new file mode 100644
--- /dev/null
+++ b/src/applications/metamta/adapter/PhabricatorMailSMTPAdapter.php
@@ -0,0 +1,154 @@
+<?php
+
+final class PhabricatorMailSMTPAdapter
+ extends PhabricatorMailAdapter {
+
+ const ADAPTERTYPE = 'smtp';
+
+ public function getSupportedMessageTypes() {
+ return array(
+ PhabricatorMailEmailMessage::MESSAGETYPE,
+ );
+ }
+
+ public function supportsMessageIDHeader() {
+ return true;
+ }
+
+ protected function validateOptions(array $options) {
+ PhutilTypeSpec::checkMap(
+ $options,
+ array(
+ 'host' => 'string|null',
+ 'port' => 'int',
+ 'user' => 'string|null',
+ 'password' => 'string|null',
+ 'protocol' => 'string|null',
+ ));
+ }
+
+ public function newDefaultOptions() {
+ return array(
+ 'host' => null,
+ 'port' => 25,
+ 'user' => null,
+ 'password' => null,
+ 'protocol' => null,
+ );
+ }
+
+ /**
+ * @phutil-external-symbol class PHPMailer
+ */
+ public function sendMessage(PhabricatorMailExternalMessage $message) {
+ $root = phutil_get_library_root('phabricator');
+ $root = dirname($root);
+ require_once $root.'/externals/phpmailer/class.phpmailer.php';
+ $smtp = new PHPMailer($use_exceptions = true);
+
+ $smtp->CharSet = 'utf-8';
+ $smtp->Encoding = 'base64';
+
+ // By default, PHPMailer 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.
+ $smtp->SingleTo = false;
+
+ $smtp->IsSMTP();
+ $smtp->Host = $this->getOption('host');
+ $smtp->Port = $this->getOption('port');
+ $user = $this->getOption('user');
+ if (strlen($user)) {
+ $smtp->SMTPAuth = true;
+ $smtp->Username = $user;
+ $smtp->Password = $this->getOption('password');
+ }
+
+ $protocol = $this->getOption('protocol');
+ if ($protocol) {
+ $protocol = phutil_utf8_strtolower($protocol);
+ $smtp->SMTPSecure = $protocol;
+ }
+
+ $subject = $message->getSubject();
+ if ($subject !== null) {
+ $smtp->Subject = $subject;
+ }
+
+ $from_address = $message->getFromAddress();
+ if ($from_address) {
+ $smtp->SetFrom(
+ $from_address->getAddress(),
+ (string)$from_address->getDisplayName(),
+ $crazy_side_effects = false);
+ }
+
+ $reply_address = $message->getReplyToAddress();
+ if ($reply_address) {
+ $smtp->AddReplyTo(
+ $reply_address->getAddress(),
+ (string)$reply_address->getDisplayName());
+ }
+
+ $to_addresses = $message->getToAddresses();
+ if ($to_addresses) {
+ foreach ($to_addresses as $address) {
+ $smtp->AddAddress(
+ $address->getAddress(),
+ (string)$address->getDisplayName());
+ }
+ }
+
+ $cc_addresses = $message->getCCAddresses();
+ if ($cc_addresses) {
+ foreach ($cc_addresses as $address) {
+ $smtp->AddCC(
+ $address->getAddress(),
+ (string)$address->getDisplayName());
+ }
+ }
+
+ $headers = $message->getHeaders();
+ if ($headers) {
+ $list = array();
+ foreach ($headers as $header) {
+ $name = $header->getName();
+ $value = $header->getValue();
+
+ if (phutil_utf8_strtolower($name) === 'message-id') {
+ $smtp->MessageID = $value;
+ } else {
+ $smtp->AddCustomHeader("{$name}: {$value}");
+ }
+ }
+ }
+
+ $text_body = $message->getTextBody();
+ if ($text_body !== null) {
+ $smtp->Body = $text_body;
+ }
+
+ $html_body = $message->getHTMLBody();
+ if ($html_body !== null) {
+ $smtp->IsHTML(true);
+ $smtp->Body = $html_body;
+ if ($text_body !== null) {
+ $smtp->AltBody = $text_body;
+ }
+ }
+
+ $attachments = $message->getAttachments();
+ if ($attachments) {
+ foreach ($attachments as $attachment) {
+ $smtp->AddStringAttachment(
+ $attachment->getData(),
+ $attachment->getFilename(),
+ 'base64',
+ $attachment->getMimeType());
+ }
+ }
+
+ $smtp->Send();
+ }
+
+}
diff --git a/src/applications/metamta/adapter/PhabricatorMailPHPMailerLiteAdapter.php b/src/applications/metamta/adapter/PhabricatorMailSendmailAdapter.php
rename from src/applications/metamta/adapter/PhabricatorMailPHPMailerLiteAdapter.php
rename to src/applications/metamta/adapter/PhabricatorMailSendmailAdapter.php
--- a/src/applications/metamta/adapter/PhabricatorMailPHPMailerLiteAdapter.php
+++ b/src/applications/metamta/adapter/PhabricatorMailSendmailAdapter.php
@@ -5,7 +5,7 @@
*
* @concrete-extensible
*/
-class PhabricatorMailPHPMailerLiteAdapter
+class PhabricatorMailSendmailAdapter
extends PhabricatorMailAdapter {
const ADAPTERTYPE = 'sendmail';

File Metadata

Mime Type
text/plain
Expires
Sun, Feb 9, 8:24 AM (18 h, 43 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7106644
Default Alt Text
D19961.diff (13 KB)

Event Timeline