Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/adapter/PhabricatorMailTestAdapter.php
| Show All 27 Lines | final class PhabricatorMailTestAdapter | ||||
| public function setFailTemporarily($fail) { | public function setFailTemporarily($fail) { | ||||
| $this->failTemporarily = true; | $this->failTemporarily = true; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getSupportedMessageTypes() { | public function getSupportedMessageTypes() { | ||||
| return array( | return array( | ||||
| PhabricatorMailEmailMessage::MESSAGETYPE, | PhabricatorMailEmailMessage::MESSAGETYPE, | ||||
| PhabricatorMailSMSMessage::MESSAGETYPE, | |||||
| ); | ); | ||||
| } | } | ||||
| protected function validateOptions(array $options) { | protected function validateOptions(array $options) { | ||||
| PhutilTypeSpec::checkMap($options, array()); | PhutilTypeSpec::checkMap($options, array()); | ||||
| } | } | ||||
| public function newDefaultOptions() { | public function newDefaultOptions() { | ||||
| Show All 14 Lines | if ($this->failPermanently) { | ||||
| pht('Unit Test (Permanent)')); | pht('Unit Test (Permanent)')); | ||||
| } | } | ||||
| if ($this->failTemporarily) { | if ($this->failTemporarily) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht('Unit Test (Temporary)')); | pht('Unit Test (Temporary)')); | ||||
| } | } | ||||
| switch ($message->getMessageType()) { | |||||
| case PhabricatorMailEmailMessage::MESSAGETYPE: | |||||
| $guts = $this->newEmailGuts($message); | |||||
| break; | |||||
| case PhabricatorMailSMSMessage::MESSAGETYPE: | |||||
| $guts = $this->newSMSGuts($message); | |||||
| break; | |||||
| } | |||||
| $guts['did-send'] = true; | |||||
| $this->guts = $guts; | |||||
| } | |||||
| public function getBody() { | |||||
| return idx($this->guts, 'body'); | |||||
| } | |||||
| public function getHTMLBody() { | |||||
| return idx($this->guts, 'html-body'); | |||||
| } | |||||
| private function newEmailGuts(PhabricatorMailExternalMessage $message) { | |||||
| $guts = array(); | $guts = array(); | ||||
| $from = $message->getFromAddress(); | $from = $message->getFromAddress(); | ||||
| $guts['from'] = (string)$from; | $guts['from'] = (string)$from; | ||||
| $reply_to = $message->getReplyToAddress(); | $reply_to = $message->getReplyToAddress(); | ||||
| if ($reply_to) { | if ($reply_to) { | ||||
| $guts['reply-to'] = (string)$reply_to; | $guts['reply-to'] = (string)$reply_to; | ||||
| ▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | foreach ($attachments as $attachment) { | ||||
| $file_list[] = array( | $file_list[] = array( | ||||
| 'data' => $attachment->getData(), | 'data' => $attachment->getData(), | ||||
| 'filename' => $attachment->getFilename(), | 'filename' => $attachment->getFilename(), | ||||
| 'mimetype' => $attachment->getMimeType(), | 'mimetype' => $attachment->getMimeType(), | ||||
| ); | ); | ||||
| } | } | ||||
| $guts['attachments'] = $file_list; | $guts['attachments'] = $file_list; | ||||
| $guts['did-send'] = true; | return $guts; | ||||
| $this->guts = $guts; | |||||
| } | } | ||||
| private function newSMSGuts(PhabricatorMailExternalMessage $message) { | |||||
| $guts = array(); | |||||
| public function getBody() { | $guts['to'] = $message->getToNumber(); | ||||
| return idx($this->guts, 'body'); | $guts['body'] = $message->getTextBody(); | ||||
| } | |||||
| public function getHTMLBody() { | return $guts; | ||||
| return idx($this->guts, 'html-body'); | |||||
| } | } | ||||
| } | } | ||||