Differential D19002 Diff 45567 src/applications/metamta/adapter/PhabricatorMailImplementationAdapter.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/adapter/PhabricatorMailImplementationAdapter.php
<?php | <?php | ||||
abstract class PhabricatorMailImplementationAdapter extends Phobject { | abstract class PhabricatorMailImplementationAdapter extends Phobject { | ||||
private $key; | |||||
private $options = array(); | |||||
abstract public function setFrom($email, $name = ''); | abstract public function setFrom($email, $name = ''); | ||||
abstract public function addReplyTo($email, $name = ''); | abstract public function addReplyTo($email, $name = ''); | ||||
abstract public function addTos(array $emails); | abstract public function addTos(array $emails); | ||||
abstract public function addCCs(array $emails); | abstract public function addCCs(array $emails); | ||||
abstract public function addAttachment($data, $filename, $mimetype); | abstract public function addAttachment($data, $filename, $mimetype); | ||||
abstract public function addHeader($header_name, $header_value); | abstract public function addHeader($header_name, $header_value); | ||||
abstract public function setBody($plaintext_body); | abstract public function setBody($plaintext_body); | ||||
abstract public function setHTMLBody($html_body); | abstract public function setHTMLBody($html_body); | ||||
abstract public function setSubject($subject); | abstract public function setSubject($subject); | ||||
/** | /** | ||||
* Some mailers, notably Amazon SES, do not support us setting a specific | * Some mailers, notably Amazon SES, do not support us setting a specific | ||||
* Message-ID header. | * Message-ID header. | ||||
*/ | */ | ||||
abstract public function supportsMessageIDHeader(); | abstract public function supportsMessageIDHeader(); | ||||
/** | /** | ||||
* Send the message. Generally, this means connecting to some service and | * Send the message. Generally, this means connecting to some service and | ||||
* handing data to it. | * handing data to it. | ||||
* | * | ||||
* If the adapter determines that the mail will never be deliverable, it | * If the adapter determines that the mail will never be deliverable, it | ||||
* should throw a @{class:PhabricatorMetaMTAPermanentFailureException}. | * should throw a @{class:PhabricatorMetaMTAPermanentFailureException}. | ||||
* | * | ||||
* For temporary failures, throw some other exception or return `false`. | * For temporary failures, throw some other exception or return `false`. | ||||
* | * | ||||
* @return bool True on success. | * @return bool True on success. | ||||
*/ | */ | ||||
abstract public function send(); | 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; | |||||
} | |||||
} | } |