mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-04 20:52:43 +01:00
4c57e6d34d
Summary: Added support for side-by-side HTML and plaintext email building. We can control if the HTML stuff is sent by by a new config, metamta.html-emails Test Plan: Been running this in our deployment for a few months now. ====Well behaved clients==== - Gmail - Mail.app ====Bad clients==== - [[ http://airmailapp.com/ | Airmail ]]. They confuse Gmail too, though. ====Need testing==== - Outlook (Windows + Mac) Reviewers: chad, #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: webframp, taoqiping, chad, epriestley, Korvin Maniphest Tasks: T992 Differential Revision: https://secure.phabricator.com/D9375
110 lines
2.4 KiB
PHP
110 lines
2.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Mail adapter that doesn't actually send any email, for writing unit tests
|
|
* against.
|
|
*/
|
|
final class PhabricatorMailImplementationTestAdapter
|
|
extends PhabricatorMailImplementationAdapter {
|
|
|
|
private $guts = array();
|
|
private $config;
|
|
|
|
public function __construct(array $config = array()) {
|
|
$this->config = $config;
|
|
}
|
|
|
|
public function setFrom($email, $name = '') {
|
|
$this->guts['from'] = $email;
|
|
$this->guts['from-name'] = $name;
|
|
return $this;
|
|
}
|
|
|
|
public function addReplyTo($email, $name = '') {
|
|
if (empty($this->guts['reply-to'])) {
|
|
$this->guts['reply-to'] = array();
|
|
}
|
|
$this->guts['reply-to'][] = array(
|
|
'email' => $email,
|
|
'name' => $name,
|
|
);
|
|
return $this;
|
|
}
|
|
|
|
public function addTos(array $emails) {
|
|
foreach ($emails as $email) {
|
|
$this->guts['tos'][] = $email;
|
|
}
|
|
return $this;
|
|
}
|
|
|
|
public function addCCs(array $emails) {
|
|
foreach ($emails as $email) {
|
|
$this->guts['ccs'][] = $email;
|
|
}
|
|
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;
|
|
}
|
|
|
|
public function setBody($body) {
|
|
$this->guts['body'] = $body;
|
|
return $this;
|
|
}
|
|
|
|
public function setHTMLBody($html_body) {
|
|
$this->guts['html-body'] = $html_body;
|
|
return $this;
|
|
}
|
|
|
|
public function setSubject($subject) {
|
|
$this->guts['subject'] = $subject;
|
|
return $this;
|
|
}
|
|
|
|
public function supportsMessageIDHeader() {
|
|
return $this->config['supportsMessageIDHeader'];
|
|
}
|
|
|
|
public function send() {
|
|
if (!empty($this->guts['fail-permanently'])) {
|
|
throw new PhabricatorMetaMTAPermanentFailureException(
|
|
'Unit Test (Permanent)');
|
|
}
|
|
|
|
if (!empty($this->guts['fail-temporarily'])) {
|
|
throw new Exception(
|
|
'Unit Test (Temporary)');
|
|
}
|
|
|
|
$this->guts['did-send'] = true;
|
|
return true;
|
|
}
|
|
|
|
public function getGuts() {
|
|
return $this->guts;
|
|
}
|
|
|
|
public function setFailPermanently($fail) {
|
|
$this->guts['fail-permanently'] = $fail;
|
|
return $this;
|
|
}
|
|
|
|
public function setFailTemporarily($fail) {
|
|
$this->guts['fail-temporarily'] = $fail;
|
|
return $this;
|
|
}
|
|
|
|
}
|