Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/mail/PhabricatorPeopleMailEngine.php
| <?php | <?php | ||||
| abstract class PhabricatorPeopleMailEngine | abstract class PhabricatorPeopleMailEngine | ||||
| extends Phobject { | extends Phobject { | ||||
| private $sender; | private $sender; | ||||
| private $recipient; | private $recipient; | ||||
| private $recipientAddress; | private $recipientAddress; | ||||
| private $activityLog; | |||||
| final public function setSender(PhabricatorUser $sender) { | final public function setSender(PhabricatorUser $sender) { | ||||
| $this->sender = $sender; | $this->sender = $sender; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| final public function getSender() { | final public function getSender() { | ||||
| if (!$this->sender) { | if (!$this->sender) { | ||||
| Show All 25 Lines | final public function getRecipientAddress() { | ||||
| } | } | ||||
| return $this->recipientAddress; | return $this->recipientAddress; | ||||
| } | } | ||||
| final public function hasRecipientAddress() { | final public function hasRecipientAddress() { | ||||
| return ($this->recipientAddress !== null); | return ($this->recipientAddress !== null); | ||||
| } | } | ||||
| final public function setActivityLog(PhabricatorUserLog $activity_log) { | |||||
| $this->activityLog = $activity_log; | |||||
| return $this; | |||||
| } | |||||
| final public function getActivityLog() { | |||||
| return $this->activityLog; | |||||
| } | |||||
| final public function canSendMail() { | final public function canSendMail() { | ||||
| try { | try { | ||||
| $this->validateMail(); | $this->validateMail(); | ||||
| return true; | return true; | ||||
| } catch (PhabricatorPeopleMailEngineException $ex) { | } catch (PhabricatorPeopleMailEngineException $ex) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| final public function sendMail() { | final public function sendMail() { | ||||
| $this->validateMail(); | $this->validateMail(); | ||||
| $mail = $this->newMail(); | $mail = $this->newMail(); | ||||
| if ($this->hasRecipientAddress()) { | if ($this->hasRecipientAddress()) { | ||||
| $recipient_address = $this->getRecipientAddress(); | $recipient_address = $this->getRecipientAddress(); | ||||
| $mail->addRawTos(array($recipient_address->getAddress())); | $mail->addRawTos(array($recipient_address->getAddress())); | ||||
| } else { | } else { | ||||
| $recipient = $this->getRecipient(); | $recipient = $this->getRecipient(); | ||||
| $mail->addTos(array($recipient->getPHID())); | $mail->addTos(array($recipient->getPHID())); | ||||
| } | } | ||||
| $activity_log = $this->getActivityLog(); | |||||
| if ($activity_log) { | |||||
| $activity_log->save(); | |||||
| $body = array(); | |||||
| $body[] = rtrim($mail->getBody(), "\n"); | |||||
| $body[] = pht('Activity Log ID: #%d', $activity_log->getID()); | |||||
| $body = implode("\n\n", $body)."\n"; | |||||
| $mail->setBody($body); | |||||
| } | |||||
| ->setForceDelivery(true) | ->setForceDelivery(true) | ||||
| ->save(); | ->save(); | ||||
| return $mail; | return $mail; | ||||
| } | } | ||||
| abstract public function validateMail(); | abstract public function validateMail(); | ||||
| Show All 21 Lines | |||||