diff --git a/src/applications/metamta/adapter/base/PhabricatorMailImplementationAdapter.php b/src/applications/metamta/adapter/base/PhabricatorMailImplementationAdapter.php index 3d20f53d6d..72500c4da7 100644 --- a/src/applications/metamta/adapter/base/PhabricatorMailImplementationAdapter.php +++ b/src/applications/metamta/adapter/base/PhabricatorMailImplementationAdapter.php @@ -22,6 +22,7 @@ abstract class PhabricatorMailImplementationAdapter { abstract public function addReplyTo($email, $name = ''); abstract public function addTos(array $emails); abstract public function addCCs(array $emails); + abstract public function addAttachment($data, $filename, $mimetype); abstract public function addHeader($header_name, $header_value); abstract public function setBody($body); abstract public function setSubject($subject); diff --git a/src/applications/metamta/adapter/phpmailerlite/PhabricatorMailImplementationPHPMailerLiteAdapter.php b/src/applications/metamta/adapter/phpmailerlite/PhabricatorMailImplementationPHPMailerLiteAdapter.php index 343e898208..e10a23131e 100644 --- a/src/applications/metamta/adapter/phpmailerlite/PhabricatorMailImplementationPHPMailerLiteAdapter.php +++ b/src/applications/metamta/adapter/phpmailerlite/PhabricatorMailImplementationPHPMailerLiteAdapter.php @@ -55,6 +55,16 @@ class PhabricatorMailImplementationPHPMailerLiteAdapter 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; diff --git a/src/applications/metamta/adapter/sendgrid/PhabricatorMailImplementationSendGridAdapter.php b/src/applications/metamta/adapter/sendgrid/PhabricatorMailImplementationSendGridAdapter.php index 3d3e56cd3a..72dc3286e2 100644 --- a/src/applications/metamta/adapter/sendgrid/PhabricatorMailImplementationSendGridAdapter.php +++ b/src/applications/metamta/adapter/sendgrid/PhabricatorMailImplementationSendGridAdapter.php @@ -55,6 +55,12 @@ class PhabricatorMailImplementationSendGridAdapter return $this; } + public function addAttachment($data, $filename, $mimetype) { + throw new Exception( + 'SendGrid adapter does not currently support attachments.' + ); + } + public function addHeader($header_name, $header_value) { $this->params['headers'][] = array($header_name, $header_value); return $this; diff --git a/src/applications/metamta/adapter/test/PhabricatorMailImplementationTestAdapter.php b/src/applications/metamta/adapter/test/PhabricatorMailImplementationTestAdapter.php index abf99bf0ef..9890974492 100644 --- a/src/applications/metamta/adapter/test/PhabricatorMailImplementationTestAdapter.php +++ b/src/applications/metamta/adapter/test/PhabricatorMailImplementationTestAdapter.php @@ -61,6 +61,15 @@ class PhabricatorMailImplementationTestAdapter return $this; } + public function addAttachment($data, $filename, $mimetype) { + $this->guts['attachments'][] = array( + 'data' => $data, + 'filename' => $filename, + 'mimetype' => $mimetype + ); + return $this; + } + public function addHeader($header_name, $header_value) { $this->guts['headers'][] = array($header_name, $header_value); return $this; diff --git a/src/applications/metamta/storage/mail/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/mail/PhabricatorMetaMTAMail.php index 4b4cb0a537..eabaf0d587 100644 --- a/src/applications/metamta/storage/mail/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/mail/PhabricatorMetaMTAMail.php @@ -104,6 +104,15 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { return $this; } + public function addAttachment($data, $filename, $mimetype) { + $this->parameters['attachments'][] = array( + 'data' => $data, + 'filename' => $filename, + 'mimetype' => $mimetype + ); + return $this; + } + public function setFrom($from) { $this->setParam('from', $from); return $this; @@ -284,6 +293,15 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { $mailer->addHeader($header_key, $header_value); } break; + case 'attachments': + foreach ($value as $attachment) { + $mailer->addAttachment( + $attachment['data'], + $attachment['filename'], + $attachment['mimetype'] + ); + } + break; case 'body': $mailer->setBody($value); break;