@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.

Allow MetaMTA adapters to indicate that a mail is permanently undeliverable

Summary: Currently, adapters can only fail mail temporarily. Allow them to indicate a permanent failure by throwing a special exception.

Test Plan: Added and ran unit tests.

Reviewers: wez, btrahan

Reviewed By: btrahan

CC: aran

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

+84
+2
src/__phutil_library_map__.php
··· 1302 1302 'PhabricatorMetaMTAMailBodyTestCase' => 'applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php', 1303 1303 'PhabricatorMetaMTAMailTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php', 1304 1304 'PhabricatorMetaMTAMailingList' => 'applications/mailinglists/storage/PhabricatorMetaMTAMailingList.php', 1305 + 'PhabricatorMetaMTAPermanentFailureException' => 'applications/metamta/exception/PhabricatorMetaMTAPermanentFailureException.php', 1305 1306 'PhabricatorMetaMTAReceivedMail' => 'applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php', 1306 1307 'PhabricatorMetaMTAReceivedMailProcessingException' => 'applications/metamta/exception/PhabricatorMetaMTAReceivedMailProcessingException.php', 1307 1308 'PhabricatorMetaMTAReceivedMailTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMetaMTAReceivedMailTestCase.php', ··· 3387 3388 0 => 'PhabricatorMetaMTADAO', 3388 3389 1 => 'PhabricatorPolicyInterface', 3389 3390 ), 3391 + 'PhabricatorMetaMTAPermanentFailureException' => 'Exception', 3390 3392 'PhabricatorMetaMTAReceivedMail' => 'PhabricatorMetaMTADAO', 3391 3393 'PhabricatorMetaMTAReceivedMailProcessingException' => 'Exception', 3392 3394 'PhabricatorMetaMTAReceivedMailTestCase' => 'PhabricatorTestCase',
+12
src/applications/metamta/adapter/PhabricatorMailImplementationAdapter.php
··· 18 18 */ 19 19 abstract public function supportsMessageIDHeader(); 20 20 21 + 22 + /** 23 + * Send the message. Generally, this means connecting to some service and 24 + * handing data to it. 25 + * 26 + * If the adapter determines that the mail will never be deliverable, it 27 + * should throw a @{class:PhabricatorMetaMTAPermanentFailureException}. 28 + * 29 + * For temporary failures, throw some other exception or return `false`. 30 + * 31 + * @return bool True on success. 32 + */ 21 33 abstract public function send(); 22 34 23 35 }
+20
src/applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php
··· 79 79 } 80 80 81 81 public function send() { 82 + if (!empty($this->guts['fail-permanently'])) { 83 + throw new PhabricatorMetaMTAPermanentFailureException( 84 + 'Unit Test (Permanent)'); 85 + } 86 + 87 + if (!empty($this->guts['fail-temporarily'])) { 88 + throw new Exception( 89 + 'Unit Test (Temporary)'); 90 + } 91 + 82 92 $this->guts['did-send'] = true; 83 93 return true; 84 94 } 85 95 86 96 public function getGuts() { 87 97 return $this->guts; 98 + } 99 + 100 + public function setFailPermanently($fail) { 101 + $this->guts['fail-permanently'] = $fail; 102 + return $this; 103 + } 104 + 105 + public function setFailTemporarily($fail) { 106 + $this->guts['fail-temporarily'] = $fail; 107 + return $this; 88 108 } 89 109 90 110 }
+6
src/applications/metamta/exception/PhabricatorMetaMTAPermanentFailureException.php
··· 1 + <?php 2 + 3 + final class PhabricatorMetaMTAPermanentFailureException 4 + extends Exception { 5 + 6 + }
+4
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
··· 627 627 try { 628 628 $ok = $mailer->send(); 629 629 $error = null; 630 + } catch (PhabricatorMetaMTAPermanentFailureException $ex) { 631 + $this->setStatus(self::STATUS_FAIL); 632 + $this->setMessage($ex->getMessage()); 633 + return $this->save(); 630 634 } catch (Exception $ex) { 631 635 $ok = false; 632 636 $error = $ex->getMessage()."\n".$ex->getTraceAsString();
+40
src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
··· 8 8 ); 9 9 } 10 10 11 + public function testMailSendFailures() { 12 + $user = $this->generateNewTestUser(); 13 + $phid = $user->getPHID(); 14 + 15 + 16 + // Normally, the send should succeed. 17 + $mail = new PhabricatorMetaMTAMail(); 18 + $mail->addTos(array($phid)); 19 + 20 + $mailer = new PhabricatorMailImplementationTestAdapter(); 21 + $mail->sendNow($force = true, $mailer); 22 + $this->assertEqual( 23 + PhabricatorMetaMTAMail::STATUS_SENT, 24 + $mail->getStatus()); 25 + 26 + 27 + // When the mailer fails temporarily, the mail should remain queued. 28 + $mail = new PhabricatorMetaMTAMail(); 29 + $mail->addTos(array($phid)); 30 + 31 + $mailer = new PhabricatorMailImplementationTestAdapter(); 32 + $mailer->setFailTemporarily(true); 33 + $mail->sendNow($force = true, $mailer); 34 + $this->assertEqual( 35 + PhabricatorMetaMTAMail::STATUS_QUEUE, 36 + $mail->getStatus()); 37 + 38 + 39 + // When the mailer fails permanently, the mail should be failed. 40 + $mail = new PhabricatorMetaMTAMail(); 41 + $mail->addTos(array($phid)); 42 + 43 + $mailer = new PhabricatorMailImplementationTestAdapter(); 44 + $mailer->setFailPermanently(true); 45 + $mail->sendNow($force = true, $mailer); 46 + $this->assertEqual( 47 + PhabricatorMetaMTAMail::STATUS_FAIL, 48 + $mail->getStatus()); 49 + } 50 + 11 51 public function testRecipients() { 12 52 $user = $this->generateNewTestUser(); 13 53 $phid = $user->getPHID();