Path: blob/master/src/applications/metamta/receiver/PhabricatorApplicationMailReceiver.php
12256 views
<?php12abstract class PhabricatorApplicationMailReceiver3extends PhabricatorMailReceiver {45private $applicationEmail;6private $emailList;7private $author;89abstract protected function newApplication();1011final protected function setApplicationEmail(12PhabricatorMetaMTAApplicationEmail $email) {13$this->applicationEmail = $email;14return $this;15}1617final protected function getApplicationEmail() {18return $this->applicationEmail;19}2021final protected function setAuthor(PhabricatorUser $author) {22$this->author = $author;23return $this;24}2526final protected function getAuthor() {27return $this->author;28}2930final public function isEnabled() {31return $this->newApplication()->isInstalled();32}3334final public function canAcceptMail(35PhabricatorMetaMTAReceivedMail $mail,36PhutilEmailAddress $target) {3738$viewer = $this->getViewer();39$sender = $this->getSender();4041foreach ($this->loadApplicationEmailList() as $application_email) {42$create_address = $application_email->newAddress();4344if (!PhabricatorMailUtil::matchAddresses($create_address, $target)) {45continue;46}4748if ($sender) {49$author = $sender;50} else {51$author_phid = $application_email->getDefaultAuthorPHID();5253// If this mail isn't from a recognized sender and the target address54// does not have a default author, we can't accept it, and it's an55// error because you tried to send it here.5657// You either need to be sending from a real address or be sending to58// an address which accepts mail from the public internet.5960if (!$author_phid) {61throw new PhabricatorMetaMTAReceivedMailProcessingException(62MetaMTAReceivedMailStatus::STATUS_UNKNOWN_SENDER,63pht(64'You are sending from an unrecognized email address to '.65'an address which does not support public email ("%s").',66(string)$target));67}6869$author = id(new PhabricatorPeopleQuery())70->setViewer($viewer)71->withPHIDs(array($author_phid))72->executeOne();73if (!$author) {74throw new Exception(75pht(76'Application email ("%s") has an invalid default author ("%s").',77(string)$create_address,78$author_phid));79}80}8182$this83->setApplicationEmail($application_email)84->setAuthor($author);8586return true;87}8889return false;90}9192private function loadApplicationEmailList() {93if ($this->emailList === null) {94$viewer = $this->getViewer();95$application = $this->newApplication();9697$this->emailList = id(new PhabricatorMetaMTAApplicationEmailQuery())98->setViewer($viewer)99->withApplicationPHIDs(array($application->getPHID()))100->execute();101}102103return $this->emailList;104}105106}107108109