@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Update Mail test adapter for the newer adapter API and make all tests pass

Summary: Depends on D19956. Ref T920. Move the TestAdapter to the new API and adjust a couple of tests for the changes.

Test Plan: All tests now pass.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T920

Differential Revision: https://secure.phabricator.com/D19957

+106 -87
+85 -74
src/applications/metamta/adapter/PhabricatorMailTestAdapter.php
··· 10 10 const ADAPTERTYPE = 'test'; 11 11 12 12 private $guts = array(); 13 - private $config = array(); 14 13 15 - protected function validateOptions(array $options) { 16 - PhutilTypeSpec::checkMap( 17 - $options, 18 - array()); 19 - } 20 - 21 - public function newDefaultOptions() { 22 - return array(); 23 - } 24 - 25 - public function prepareForSend(array $config = array()) { 26 - $this->config = $config; 27 - } 28 - 29 - public function setFrom($email, $name = '') { 30 - $this->guts['from'] = $email; 31 - $this->guts['from-name'] = $name; 32 - return $this; 33 - } 14 + private $supportsMessageID; 15 + private $failPermanently; 16 + private $failTemporarily; 34 17 35 - public function addReplyTo($email, $name = '') { 36 - if (empty($this->guts['reply-to'])) { 37 - $this->guts['reply-to'] = array(); 38 - } 39 - $this->guts['reply-to'][] = array( 40 - 'email' => $email, 41 - 'name' => $name, 42 - ); 18 + public function setSupportsMessageID($support) { 19 + $this->supportsMessageID = $support; 43 20 return $this; 44 21 } 45 22 46 - public function addTos(array $emails) { 47 - foreach ($emails as $email) { 48 - $this->guts['tos'][] = $email; 49 - } 23 + public function setFailPermanently($fail) { 24 + $this->failPermanently = true; 50 25 return $this; 51 26 } 52 27 53 - public function addCCs(array $emails) { 54 - foreach ($emails as $email) { 55 - $this->guts['ccs'][] = $email; 56 - } 28 + public function setFailTemporarily($fail) { 29 + $this->failTemporarily = true; 57 30 return $this; 58 31 } 59 32 60 - public function addAttachment($data, $filename, $mimetype) { 61 - $this->guts['attachments'][] = array( 62 - 'data' => $data, 63 - 'filename' => $filename, 64 - 'mimetype' => $mimetype, 33 + public function getSupportedMessageTypes() { 34 + return array( 35 + PhabricatorMailEmailMessage::MESSAGETYPE, 65 36 ); 66 - return $this; 67 37 } 68 38 69 - public function addHeader($header_name, $header_value) { 70 - $this->guts['headers'][] = array($header_name, $header_value); 71 - return $this; 72 - } 73 - 74 - public function setBody($body) { 75 - $this->guts['body'] = $body; 76 - return $this; 39 + protected function validateOptions(array $options) { 40 + PhutilTypeSpec::checkMap($options, array()); 77 41 } 78 42 79 - public function setHTMLBody($html_body) { 80 - $this->guts['html-body'] = $html_body; 81 - return $this; 43 + public function newDefaultOptions() { 44 + return array(); 82 45 } 83 46 84 - public function setSubject($subject) { 85 - $this->guts['subject'] = $subject; 86 - return $this; 47 + public function supportsMessageIDHeader() { 48 + return $this->supportsMessageID; 87 49 } 88 50 89 - public function supportsMessageIDHeader() { 90 - return idx($this->config, 'supportsMessageIDHeader', true); 51 + public function getGuts() { 52 + return $this->guts; 91 53 } 92 54 93 - public function send() { 94 - if (!empty($this->guts['fail-permanently'])) { 55 + public function sendMessage(PhabricatorMailExternalMessage $message) { 56 + if ($this->failPermanently) { 95 57 throw new PhabricatorMetaMTAPermanentFailureException( 96 58 pht('Unit Test (Permanent)')); 97 59 } 98 60 99 - if (!empty($this->guts['fail-temporarily'])) { 61 + if ($this->failTemporarily) { 100 62 throw new Exception( 101 63 pht('Unit Test (Temporary)')); 102 64 } 103 65 104 - $this->guts['did-send'] = true; 105 - return true; 106 - } 66 + $guts = array(); 67 + 68 + $from = $message->getFromAddress(); 69 + $guts['from'] = (string)$from; 70 + 71 + $reply_to = $message->getReplyToAddress(); 72 + if ($reply_to) { 73 + $guts['reply-to'] = (string)$reply_to; 74 + } 75 + 76 + $to_addresses = $message->getToAddresses(); 77 + $to = array(); 78 + foreach ($to_addresses as $address) { 79 + $to[] = (string)$address; 80 + } 81 + $guts['tos'] = $to; 82 + 83 + $cc_addresses = $message->getCCAddresses(); 84 + $cc = array(); 85 + foreach ($cc_addresses as $address) { 86 + $cc[] = (string)$address; 87 + } 88 + $guts['ccs'] = $cc; 89 + 90 + $subject = $message->getSubject(); 91 + if (strlen($subject)) { 92 + $guts['subject'] = $subject; 93 + } 94 + 95 + $headers = $message->getHeaders(); 96 + $header_list = array(); 97 + foreach ($headers as $header) { 98 + $header_list[] = array( 99 + $header->getName(), 100 + $header->getValue(), 101 + ); 102 + } 103 + $guts['headers'] = $header_list; 104 + 105 + $text_body = $message->getTextBody(); 106 + if (strlen($text_body)) { 107 + $guts['body'] = $text_body; 108 + } 109 + 110 + $html_body = $message->getHTMLBody(); 111 + if (strlen($html_body)) { 112 + $guts['html-body'] = $html_body; 113 + } 114 + 115 + $attachments = $message->getAttachments(); 116 + $file_list = array(); 117 + foreach ($attachments as $attachment) { 118 + $file_list[] = array( 119 + 'data' => $attachment->getData(), 120 + 'filename' => $attachment->getFilename(), 121 + 'mimetype' => $attachment->getMimeType(), 122 + ); 123 + } 124 + $guts['attachments'] = $file_list; 107 125 108 - public function getGuts() { 109 - return $this->guts; 110 - } 126 + $guts['did-send'] = true; 111 127 112 - public function setFailPermanently($fail) { 113 - $this->guts['fail-permanently'] = $fail; 114 - return $this; 128 + $this->guts = $guts; 115 129 } 116 130 117 - public function setFailTemporarily($fail) { 118 - $this->guts['fail-temporarily'] = $fail; 119 - return $this; 120 - } 121 131 122 132 public function getBody() { 123 133 return idx($this->guts, 'body'); ··· 126 136 public function getHTMLBody() { 127 137 return idx($this->guts, 'html-body'); 128 138 } 139 + 129 140 130 141 }
+2 -2
src/applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php
··· 42 42 } 43 43 44 44 public function testReservedAddresses() { 45 - $default_address = id(new PhabricatorMetaMTAMail()) 45 + $default_address = id(new PhabricatorMailEmailEngine()) 46 46 ->newDefaultEmailAddress(); 47 47 48 - $void_address = id(new PhabricatorMetaMTAMail()) 48 + $void_address = id(new PhabricatorMailEmailEngine()) 49 49 ->newVoidEmailAddress(); 50 50 51 51 $map = array(
+17 -9
src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
··· 182 182 $supports_message_id, 183 183 $is_first_mail) { 184 184 185 + $user = $this->generateNewTestUser(); 186 + $phid = $user->getPHID(); 187 + 185 188 $mailer = new PhabricatorMailTestAdapter(); 186 189 187 - $mailer->prepareForSend( 188 - array( 189 - 'supportsMessageIDHeader' => $supports_message_id, 190 - )); 190 + $mailer->setSupportsMessageID($supports_message_id); 191 191 192 - $thread_id = '<somethread-12345@somedomain.tld>'; 192 + $thread_id = 'somethread-12345'; 193 193 194 - $mail = new PhabricatorMetaMTAMail(); 195 - $mail->setThreadID($thread_id, $is_first_mail); 196 - $mail->sendWithMailers(array($mailer)); 194 + $mail = id(new PhabricatorMetaMTAMail()) 195 + ->setThreadID($thread_id, $is_first_mail) 196 + ->addTos(array($phid)) 197 + ->sendWithMailers(array($mailer)); 197 198 198 199 $guts = $mailer->getGuts(); 199 - $dict = ipull($guts['headers'], 1, 0); 200 + 201 + $headers = idx($guts, 'headers', array()); 202 + 203 + $dict = array(); 204 + foreach ($headers as $header) { 205 + list($name, $value) = $header; 206 + $dict[$name] = $value; 207 + } 200 208 201 209 if ($is_first_mail && $supports_message_id) { 202 210 $expect_message_id = true;
+2 -2
src/applications/metamta/util/PhabricatorMailUtil.php
··· 93 93 return true; 94 94 } 95 95 96 - $default_address = id(new PhabricatorMetaMTAMail()) 96 + $default_address = id(new PhabricatorMailEmailEngine()) 97 97 ->newDefaultEmailAddress(); 98 98 if (self::matchAddresses($address, $default_address)) { 99 99 return true; 100 100 } 101 101 102 - $void_address = id(new PhabricatorMetaMTAMail()) 102 + $void_address = id(new PhabricatorMailEmailEngine()) 103 103 ->newVoidEmailAddress(); 104 104 if (self::matchAddresses($address, $void_address)) { 105 105 return true;