Summary: Depends on D19000. Ref T13053. Ref T12677. Currently, most mailers are configured with a bunch of `<mailer>.setting-name` global config options. This means that you can't configure two different SMTP servers, which is a reasonable thing to want to do in the brave new world of mail failover. It also means you can't configure two Mailgun accounts or two SES accounts. Although this might seem a little silly, we've had more service disruptions because of policy issues / administrative error (where a particular account was disabled) than actual downtime, so maybe it's not completely ridiculous. Realign mailers so they can take configuration directly in an explicit way. A later change will add new configuration to take advantage of this and let us move away from having ~10 global options for this stuff eventually. (This also makes writing third-party mailers easier.) Test Plan: Processed some mail, ran existing unit tests. But I wasn't especially thorough. I expect later changes to provide some tools to make this more testable, so I'll vet each provider more thoroughly and add coverage for multiple mailers after that stuff is ready. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13053, T12677 Differential Revision: https://secure.phabricator.com/D19002
76 lines
2 KiB
PHP
76 lines
2 KiB
PHP
<?php
|
|
|
|
abstract class PhabricatorMailImplementationAdapter extends Phobject {
|
|
|
|
private $key;
|
|
private $options = array();
|
|
|
|
abstract public function setFrom($email, $name = '');
|
|
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($plaintext_body);
|
|
abstract public function setHTMLBody($html_body);
|
|
abstract public function setSubject($subject);
|
|
|
|
|
|
/**
|
|
* Some mailers, notably Amazon SES, do not support us setting a specific
|
|
* Message-ID header.
|
|
*/
|
|
abstract public function supportsMessageIDHeader();
|
|
|
|
|
|
/**
|
|
* Send the message. Generally, this means connecting to some service and
|
|
* handing data to it.
|
|
*
|
|
* If the adapter determines that the mail will never be deliverable, it
|
|
* should throw a @{class:PhabricatorMetaMTAPermanentFailureException}.
|
|
*
|
|
* For temporary failures, throw some other exception or return `false`.
|
|
*
|
|
* @return bool True on success.
|
|
*/
|
|
abstract public function send();
|
|
|
|
final public function setKey($key) {
|
|
$this->key = $key;
|
|
return $this;
|
|
}
|
|
|
|
final public function getKey() {
|
|
return $this->key;
|
|
}
|
|
|
|
final public function getOption($key) {
|
|
if (!array_key_exists($key, $this->options)) {
|
|
throw new Exception(
|
|
pht(
|
|
'Mailer ("%s") is attempting to access unknown option ("%s").',
|
|
get_class($this),
|
|
$key));
|
|
}
|
|
|
|
return $this->options[$key];
|
|
}
|
|
|
|
final public function setOptions(array $options) {
|
|
$this->validateOptions($options);
|
|
$this->options = $options;
|
|
return $this;
|
|
}
|
|
|
|
abstract protected function validateOptions(array $options);
|
|
|
|
abstract public function newDefaultOptions();
|
|
abstract public function newLegacyOptions();
|
|
|
|
public function prepareForSend() {
|
|
return;
|
|
}
|
|
|
|
}
|