Path: blob/master/src/applications/people/mail/PhabricatorPeopleMailEngine.php
12256 views
<?php12abstract class PhabricatorPeopleMailEngine3extends Phobject {45private $sender;6private $recipient;7private $recipientAddress;8private $activityLog;910final public function setSender(PhabricatorUser $sender) {11$this->sender = $sender;12return $this;13}1415final public function getSender() {16if (!$this->sender) {17throw new PhutilInvalidStateException('setSender');18}19return $this->sender;20}2122final public function setRecipient(PhabricatorUser $recipient) {23$this->recipient = $recipient;24return $this;25}2627final public function getRecipient() {28if (!$this->recipient) {29throw new PhutilInvalidStateException('setRecipient');30}31return $this->recipient;32}3334final public function setRecipientAddress(PhutilEmailAddress $address) {35$this->recipientAddress = $address;36return $this;37}3839final public function getRecipientAddress() {40if (!$this->recipientAddress) {41throw new PhutilInvalidStateException('recipientAddress');42}43return $this->recipientAddress;44}4546final public function hasRecipientAddress() {47return ($this->recipientAddress !== null);48}4950final public function setActivityLog(PhabricatorUserLog $activity_log) {51$this->activityLog = $activity_log;52return $this;53}5455final public function getActivityLog() {56return $this->activityLog;57}5859final public function canSendMail() {60try {61$this->validateMail();62return true;63} catch (PhabricatorPeopleMailEngineException $ex) {64return false;65}66}6768final public function sendMail() {69$this->validateMail();70$mail = $this->newMail();7172if ($this->hasRecipientAddress()) {73$recipient_address = $this->getRecipientAddress();74$mail->addRawTos(array($recipient_address->getAddress()));75} else {76$recipient = $this->getRecipient();77$mail->addTos(array($recipient->getPHID()));78}7980$activity_log = $this->getActivityLog();81if ($activity_log) {82$activity_log->save();8384$body = array();85$body[] = rtrim($mail->getBody(), "\n");86$body[] = pht('Activity Log ID: #%d', $activity_log->getID());87$body = implode("\n\n", $body)."\n";8889$mail->setBody($body);90}919293->setForceDelivery(true)94->save();9596return $mail;97}9899abstract public function validateMail();100abstract protected function newMail();101102final protected function throwValidationException($title, $body) {103throw new PhabricatorPeopleMailEngineException($title, $body);104}105106final protected function newRemarkupText($text) {107$recipient = $this->getRecipient();108109$engine = PhabricatorMarkupEngine::newMarkupEngine(array())110->setConfig('viewer', $recipient)111->setConfig('uri.base', PhabricatorEnv::getProductionURI('/'))112->setMode(PhutilRemarkupEngine::MODE_TEXT);113114$rendered_text = $engine->markupText($text);115$rendered_text = rtrim($rendered_text, "\n");116117return $rendered_text;118}119120}121122123