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

Consolidate outbound mail status in a new class

Summary: Ref T5791. This collects outbound mail status in one place and makes the list view a little spiffier.

Test Plan: Looked at list and detail views. Grepped for changed classes/constants.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T5791

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

+78 -68
+3 -3
src/__phutil_library_map__.php
··· 1248 1248 'ManiphestTransactionSaveController' => 'applications/maniphest/controller/ManiphestTransactionSaveController.php', 1249 1249 'ManiphestUpdateConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestUpdateConduitAPIMethod.php', 1250 1250 'ManiphestView' => 'applications/maniphest/view/ManiphestView.php', 1251 - 'MetaMTAConstants' => 'applications/metamta/constants/MetaMTAConstants.php', 1252 1251 'MetaMTAEmailTransactionCommand' => 'applications/metamta/command/MetaMTAEmailTransactionCommand.php', 1253 1252 'MetaMTAEmailTransactionCommandTestCase' => 'applications/metamta/command/__tests__/MetaMTAEmailTransactionCommandTestCase.php', 1254 1253 'MetaMTAMailReceivedGarbageCollector' => 'applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php', ··· 2258 2257 'PhabricatorMailManagementShowOutboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php', 2259 2258 'PhabricatorMailManagementVolumeWorkflow' => 'applications/metamta/management/PhabricatorMailManagementVolumeWorkflow.php', 2260 2259 'PhabricatorMailManagementWorkflow' => 'applications/metamta/management/PhabricatorMailManagementWorkflow.php', 2260 + 'PhabricatorMailOutboundStatus' => 'applications/metamta/constants/PhabricatorMailOutboundStatus.php', 2261 2261 'PhabricatorMailReceiver' => 'applications/metamta/receiver/PhabricatorMailReceiver.php', 2262 2262 'PhabricatorMailReceiverTestCase' => 'applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php', 2263 2263 'PhabricatorMailReplyHandler' => 'applications/metamta/replyhandler/PhabricatorMailReplyHandler.php', ··· 5012 5012 'ManiphestTransactionSaveController' => 'ManiphestController', 5013 5013 'ManiphestUpdateConduitAPIMethod' => 'ManiphestConduitAPIMethod', 5014 5014 'ManiphestView' => 'AphrontView', 5015 - 'MetaMTAConstants' => 'Phobject', 5016 5015 'MetaMTAEmailTransactionCommand' => 'Phobject', 5017 5016 'MetaMTAEmailTransactionCommandTestCase' => 'PhabricatorTestCase', 5018 5017 'MetaMTAMailReceivedGarbageCollector' => 'PhabricatorGarbageCollector', 5019 5018 'MetaMTAMailSentGarbageCollector' => 'PhabricatorGarbageCollector', 5020 - 'MetaMTAReceivedMailStatus' => 'MetaMTAConstants', 5019 + 'MetaMTAReceivedMailStatus' => 'Phobject', 5021 5020 'MultimeterContext' => 'MultimeterDimension', 5022 5021 'MultimeterControl' => 'Phobject', 5023 5022 'MultimeterController' => 'PhabricatorController', ··· 6182 6181 'PhabricatorMailManagementShowOutboundWorkflow' => 'PhabricatorMailManagementWorkflow', 6183 6182 'PhabricatorMailManagementVolumeWorkflow' => 'PhabricatorMailManagementWorkflow', 6184 6183 'PhabricatorMailManagementWorkflow' => 'PhabricatorManagementWorkflow', 6184 + 'PhabricatorMailOutboundStatus' => 'Phobject', 6185 6185 'PhabricatorMailReceiver' => 'Phobject', 6186 6186 'PhabricatorMailReceiverTestCase' => 'PhabricatorTestCase', 6187 6187 'PhabricatorMailReplyHandler' => 'Phobject',
+1 -1
src/applications/metamta/PhabricatorMetaMTAWorker.php
··· 18 18 pht('Unable to load message!')); 19 19 } 20 20 21 - if ($message->getStatus() != PhabricatorMetaMTAMail::STATUS_QUEUE) { 21 + if ($message->getStatus() != PhabricatorMailOutboundStatus::STATUS_QUEUE) { 22 22 return; 23 23 } 24 24
-3
src/applications/metamta/constants/MetaMTAConstants.php
··· 1 - <?php 2 - 3 - abstract class MetaMTAConstants extends Phobject {}
+1 -1
src/applications/metamta/constants/MetaMTAReceivedMailStatus.php
··· 1 1 <?php 2 2 3 3 final class MetaMTAReceivedMailStatus 4 - extends MetaMTAConstants { 4 + extends Phobject { 5 5 6 6 const STATUS_DUPLICATE = 'err:duplicate'; 7 7 const STATUS_FROM_PHABRICATOR = 'err:self';
+44
src/applications/metamta/constants/PhabricatorMailOutboundStatus.php
··· 1 + <?php 2 + 3 + final class PhabricatorMailOutboundStatus 4 + extends Phobject { 5 + 6 + const STATUS_QUEUE = 'queued'; 7 + const STATUS_SENT = 'sent'; 8 + const STATUS_FAIL = 'fail'; 9 + const STATUS_VOID = 'void'; 10 + 11 + 12 + public static function getStatusName($status_code) { 13 + $names = array( 14 + self::STATUS_QUEUE => pht('Queued'), 15 + self::STATUS_FAIL => pht('Delivery Failed'), 16 + self::STATUS_SENT => pht('Sent'), 17 + self::STATUS_VOID => pht('Voided'), 18 + ); 19 + $status_code = coalesce($status_code, '?'); 20 + return idx($names, $status_code, $status_code); 21 + } 22 + 23 + public static function getStatusIcon($status_code) { 24 + $icons = array( 25 + self::STATUS_QUEUE => 'fa-clock-o', 26 + self::STATUS_FAIL => 'fa-warning', 27 + self::STATUS_SENT => 'fa-envelope', 28 + self::STATUS_VOID => 'fa-trash', 29 + ); 30 + return idx($icons, $status_code, 'fa-question-circle'); 31 + } 32 + 33 + public static function getStatusColor($status_code) { 34 + $colors = array( 35 + self::STATUS_QUEUE => 'blue', 36 + self::STATUS_FAIL => 'red', 37 + self::STATUS_SENT => 'green', 38 + self::STATUS_VOID => 'black', 39 + ); 40 + 41 + return idx($colors, $status_code, 'yellow'); 42 + } 43 + 44 + }
+6 -28
src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php
··· 25 25 ->setUser($viewer) 26 26 ->setPolicyObject($mail); 27 27 28 - switch ($mail->getStatus()) { 29 - case PhabricatorMetaMTAMail::STATUS_QUEUE: 30 - $icon = 'fa-clock-o'; 31 - $color = 'blue'; 32 - $name = pht('Queued'); 33 - break; 34 - case PhabricatorMetaMTAMail::STATUS_SENT: 35 - $icon = 'fa-envelope'; 36 - $color = 'green'; 37 - $name = pht('Sent'); 38 - break; 39 - case PhabricatorMetaMTAMail::STATUS_FAIL: 40 - $icon = 'fa-envelope'; 41 - $color = 'red'; 42 - $name = pht('Delivery Failed'); 43 - break; 44 - case PhabricatorMetaMTAMail::STATUS_VOID: 45 - $icon = 'fa-envelope'; 46 - $color = 'black'; 47 - $name = pht('Voided'); 48 - break; 49 - default: 50 - $icon = 'fa-question-circle'; 51 - $color = 'yellow'; 52 - $name = pht('Unknown'); 53 - break; 54 - } 55 - 28 + $status = $mail->getStatus(); 29 + $name = PhabricatorMailOutboundStatus::getStatusName($status); 30 + $icon = PhabricatorMailOutboundStatus::getStatusIcon($status); 31 + $color = PhabricatorMailOutboundStatus::getStatusColor($status); 56 32 $header->setStatus($icon, $color, $name); 57 33 58 34 $crumbs = $this->buildApplicationCrumbs() ··· 248 224 249 225 $properties = id(new PHUIPropertyListView()) 250 226 ->setUser($viewer); 227 + 228 + $properties->addProperty(pht('Message PHID'), $mail->getPHID()); 251 229 252 230 $details = $mail->getMessage(); 253 231 if (!strlen($details)) {
+1 -1
src/applications/metamta/management/PhabricatorMailManagementListOutboundWorkflow.php
··· 45 45 46 46 $table->addRow(array( 47 47 'id' => $mail->getID(), 48 - 'status' => PhabricatorMetaMTAMail::getReadableStatus($status), 48 + 'status' => PhabricatorMailOutboundStatus::getStatusName($status), 49 49 'subject' => $mail->getSubject(), 50 50 )); 51 51 }
+1 -1
src/applications/metamta/management/PhabricatorMailManagementResendWorkflow.php
··· 47 47 } 48 48 49 49 foreach ($messages as $message) { 50 - $message->setStatus(PhabricatorMetaMTAMail::STATUS_QUEUE); 50 + $message->setStatus(PhabricatorMailOutboundStatus::STATUS_QUEUE); 51 51 $message->save(); 52 52 53 53 $mailer_task = PhabricatorWorker::scheduleTask(
+10 -3
src/applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php
··· 101 101 102 102 foreach ($mails as $mail) { 103 103 if ($mail->hasSensitiveContent()) { 104 - $header = pht('< content redacted >'); 104 + $header = phutil_tag('em', array(), pht('Content Redacted')); 105 105 } else { 106 106 $header = $mail->getSubject(); 107 107 } ··· 110 110 ->setUser($viewer) 111 111 ->setObject($mail) 112 112 ->setEpoch($mail->getDateCreated()) 113 - ->setObjectName('Mail '.$mail->getID()) 113 + ->setObjectName(pht('Mail %d', $mail->getID())) 114 114 ->setHeader($header) 115 - ->setHref($this->getURI('detail/'.$mail->getID())); 115 + ->setHref($this->getURI('detail/'.$mail->getID().'/')); 116 + 117 + $status = $mail->getStatus(); 118 + $status_name = PhabricatorMailOutboundStatus::getStatusName($status); 119 + $status_icon = PhabricatorMailOutboundStatus::getStatusIcon($status); 120 + $status_color = PhabricatorMailOutboundStatus::getStatusColor($status); 121 + $item->setStatusIcon($status_icon.' '.$status_color, $status_name); 122 + 116 123 $list->addItem($item); 117 124 } 118 125
+8 -24
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
··· 7 7 extends PhabricatorMetaMTADAO 8 8 implements PhabricatorPolicyInterface { 9 9 10 - const STATUS_QUEUE = 'queued'; 11 - const STATUS_SENT = 'sent'; 12 - const STATUS_FAIL = 'fail'; 13 - const STATUS_VOID = 'void'; 14 - 15 10 const RETRY_DELAY = 5; 16 11 17 12 protected $actorPHID; ··· 24 19 25 20 public function __construct() { 26 21 27 - $this->status = self::STATUS_QUEUE; 22 + $this->status = PhabricatorMailOutboundStatus::STATUS_QUEUE; 28 23 $this->parameters = array('sensitive' => true); 29 24 30 25 parent::__construct(); ··· 430 425 } 431 426 432 427 if (!$force_send) { 433 - if ($this->getStatus() != self::STATUS_QUEUE) { 428 + if ($this->getStatus() != PhabricatorMailOutboundStatus::STATUS_QUEUE) { 434 429 throw new Exception(pht('Trying to send an already-sent mail!')); 435 430 } 436 431 } ··· 662 657 $this->setParam('actors.sent', $actor_list); 663 658 664 659 if (!$add_to && !$add_cc) { 665 - $this->setStatus(self::STATUS_VOID); 660 + $this->setStatus(PhabricatorMailOutboundStatus::STATUS_VOID); 666 661 $this->setMessage( 667 662 pht( 668 663 'Message has no valid recipients: all To/Cc are disabled, '. ··· 673 668 if ($this->getIsErrorEmail()) { 674 669 $all_recipients = array_merge($add_to, $add_cc); 675 670 if ($this->shouldRateLimitMail($all_recipients)) { 676 - $this->setStatus(self::STATUS_VOID); 671 + $this->setStatus(PhabricatorMailOutboundStatus::STATUS_VOID); 677 672 $this->setMessage( 678 673 pht( 679 674 'This is an error email, but one or more recipients have '. ··· 684 679 } 685 680 686 681 if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { 687 - $this->setStatus(self::STATUS_VOID); 682 + $this->setStatus(PhabricatorMailOutboundStatus::STATUS_VOID); 688 683 $this->setMessage( 689 684 pht( 690 685 'Phabricator is running in silent mode. See `%s` '. ··· 716 711 } 717 712 } catch (Exception $ex) { 718 713 $this 719 - ->setStatus(self::STATUS_FAIL) 714 + ->setStatus(PhabricatorMailOutboundStatus::STATUS_FAIL) 720 715 ->setMessage($ex->getMessage()) 721 716 ->save(); 722 717 ··· 732 727 pht('Mail adapter encountered an unexpected, unspecified failure.')); 733 728 } 734 729 735 - $this->setStatus(self::STATUS_SENT); 730 + $this->setStatus(PhabricatorMailOutboundStatus::STATUS_SENT); 736 731 $this->save(); 737 732 738 733 return $this; 739 734 } catch (PhabricatorMetaMTAPermanentFailureException $ex) { 740 735 $this 741 - ->setStatus(self::STATUS_FAIL) 736 + ->setStatus(PhabricatorMailOutboundStatus::STATUS_FAIL) 742 737 ->setMessage($ex->getMessage()) 743 738 ->save(); 744 739 ··· 750 745 751 746 throw $ex; 752 747 } 753 - } 754 - 755 - public static function getReadableStatus($status_code) { 756 - $readable = array( 757 - self::STATUS_QUEUE => pht('Queued for Delivery'), 758 - self::STATUS_FAIL => pht('Delivery Failed'), 759 - self::STATUS_SENT => pht('Sent'), 760 - self::STATUS_VOID => pht('Void'), 761 - ); 762 - $status_code = coalesce($status_code, '?'); 763 - return idx($readable, $status_code, $status_code); 764 748 } 765 749 766 750 private function generateThreadIndex($seed, $is_first_mail) {
+3 -3
src/applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php
··· 20 20 $mailer = new PhabricatorMailImplementationTestAdapter(); 21 21 $mail->sendNow($force = true, $mailer); 22 22 $this->assertEqual( 23 - PhabricatorMetaMTAMail::STATUS_SENT, 23 + PhabricatorMailOutboundStatus::STATUS_SENT, 24 24 $mail->getStatus()); 25 25 26 26 ··· 36 36 // Ignore. 37 37 } 38 38 $this->assertEqual( 39 - PhabricatorMetaMTAMail::STATUS_QUEUE, 39 + PhabricatorMailOutboundStatus::STATUS_QUEUE, 40 40 $mail->getStatus()); 41 41 42 42 ··· 52 52 // Ignore. 53 53 } 54 54 $this->assertEqual( 55 - PhabricatorMetaMTAMail::STATUS_FAIL, 55 + PhabricatorMailOutboundStatus::STATUS_FAIL, 56 56 $mail->getStatus()); 57 57 } 58 58