3 abstract class PhabricatorPeopleMailEngine
8 private $recipientAddress;
11 final public function setSender(PhabricatorUser
$sender) {
12 $this->sender
= $sender;
16 final public function getSender() {
18 throw new PhutilInvalidStateException('setSender');
23 final public function setRecipient(PhabricatorUser
$recipient) {
24 $this->recipient
= $recipient;
28 final public function getRecipient() {
29 if (!$this->recipient
) {
30 throw new PhutilInvalidStateException('setRecipient');
32 return $this->recipient
;
35 final public function setRecipientAddress(PhutilEmailAddress
$address) {
36 $this->recipientAddress
= $address;
40 final public function getRecipientAddress() {
41 if (!$this->recipientAddress
) {
42 throw new PhutilInvalidStateException('recipientAddress');
44 return $this->recipientAddress
;
47 final public function hasRecipientAddress() {
48 return ($this->recipientAddress
!== null);
51 final public function setActivityLog(PhabricatorUserLog
$activity_log) {
52 $this->activityLog
= $activity_log;
56 final public function getActivityLog() {
57 return $this->activityLog
;
60 final public function canSendMail() {
62 $this->validateMail();
64 } catch (PhabricatorPeopleMailEngineException
$ex) {
69 final public function sendMail() {
70 $this->validateMail();
71 $mail = $this->newMail();
73 if ($this->hasRecipientAddress()) {
74 $recipient_address = $this->getRecipientAddress();
75 $mail->addRawTos(array($recipient_address->getAddress()));
77 $recipient = $this->getRecipient();
78 $mail->addTos(array($recipient->getPHID()));
81 $activity_log = $this->getActivityLog();
83 $activity_log->save();
86 $body[] = rtrim($mail->getBody(), "\n");
87 $body[] = pht('Activity Log ID: #%d', $activity_log->getID());
88 $body = implode("\n\n", $body)."\n";
90 $mail->setBody($body);
94 ->setForceDelivery(true)
100 abstract public function validateMail();
101 abstract protected function newMail();
103 final protected function throwValidationException($title, $body) {
104 throw new PhabricatorPeopleMailEngineException($title, $body);
107 final protected function newRemarkupText($text) {
108 $recipient = $this->getRecipient();
110 $engine = PhabricatorMarkupEngine
::newMarkupEngine(array())
111 ->setConfig('viewer', $recipient)
112 ->setConfig('uri.base', PhabricatorEnv
::getProductionURI('/'))
113 ->setMode(PhutilRemarkupEngine
::MODE_TEXT
);
115 $rendered_text = $engine->markupText($text);
116 $rendered_text = rtrim($rendered_text, "\n");
118 return $rendered_text;