1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 04:20:55 +01:00

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
This commit is contained in:
epriestley 2015-08-14 04:31:42 -07:00
parent 9e306710b3
commit 3b987a93ce
11 changed files with 78 additions and 68 deletions

View file

@ -1248,7 +1248,6 @@ phutil_register_library_map(array(
'ManiphestTransactionSaveController' => 'applications/maniphest/controller/ManiphestTransactionSaveController.php', 'ManiphestTransactionSaveController' => 'applications/maniphest/controller/ManiphestTransactionSaveController.php',
'ManiphestUpdateConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestUpdateConduitAPIMethod.php', 'ManiphestUpdateConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestUpdateConduitAPIMethod.php',
'ManiphestView' => 'applications/maniphest/view/ManiphestView.php', 'ManiphestView' => 'applications/maniphest/view/ManiphestView.php',
'MetaMTAConstants' => 'applications/metamta/constants/MetaMTAConstants.php',
'MetaMTAEmailTransactionCommand' => 'applications/metamta/command/MetaMTAEmailTransactionCommand.php', 'MetaMTAEmailTransactionCommand' => 'applications/metamta/command/MetaMTAEmailTransactionCommand.php',
'MetaMTAEmailTransactionCommandTestCase' => 'applications/metamta/command/__tests__/MetaMTAEmailTransactionCommandTestCase.php', 'MetaMTAEmailTransactionCommandTestCase' => 'applications/metamta/command/__tests__/MetaMTAEmailTransactionCommandTestCase.php',
'MetaMTAMailReceivedGarbageCollector' => 'applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php', 'MetaMTAMailReceivedGarbageCollector' => 'applications/metamta/garbagecollector/MetaMTAMailReceivedGarbageCollector.php',
@ -2258,6 +2257,7 @@ phutil_register_library_map(array(
'PhabricatorMailManagementShowOutboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php', 'PhabricatorMailManagementShowOutboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php',
'PhabricatorMailManagementVolumeWorkflow' => 'applications/metamta/management/PhabricatorMailManagementVolumeWorkflow.php', 'PhabricatorMailManagementVolumeWorkflow' => 'applications/metamta/management/PhabricatorMailManagementVolumeWorkflow.php',
'PhabricatorMailManagementWorkflow' => 'applications/metamta/management/PhabricatorMailManagementWorkflow.php', 'PhabricatorMailManagementWorkflow' => 'applications/metamta/management/PhabricatorMailManagementWorkflow.php',
'PhabricatorMailOutboundStatus' => 'applications/metamta/constants/PhabricatorMailOutboundStatus.php',
'PhabricatorMailReceiver' => 'applications/metamta/receiver/PhabricatorMailReceiver.php', 'PhabricatorMailReceiver' => 'applications/metamta/receiver/PhabricatorMailReceiver.php',
'PhabricatorMailReceiverTestCase' => 'applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php', 'PhabricatorMailReceiverTestCase' => 'applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php',
'PhabricatorMailReplyHandler' => 'applications/metamta/replyhandler/PhabricatorMailReplyHandler.php', 'PhabricatorMailReplyHandler' => 'applications/metamta/replyhandler/PhabricatorMailReplyHandler.php',
@ -5012,12 +5012,11 @@ phutil_register_library_map(array(
'ManiphestTransactionSaveController' => 'ManiphestController', 'ManiphestTransactionSaveController' => 'ManiphestController',
'ManiphestUpdateConduitAPIMethod' => 'ManiphestConduitAPIMethod', 'ManiphestUpdateConduitAPIMethod' => 'ManiphestConduitAPIMethod',
'ManiphestView' => 'AphrontView', 'ManiphestView' => 'AphrontView',
'MetaMTAConstants' => 'Phobject',
'MetaMTAEmailTransactionCommand' => 'Phobject', 'MetaMTAEmailTransactionCommand' => 'Phobject',
'MetaMTAEmailTransactionCommandTestCase' => 'PhabricatorTestCase', 'MetaMTAEmailTransactionCommandTestCase' => 'PhabricatorTestCase',
'MetaMTAMailReceivedGarbageCollector' => 'PhabricatorGarbageCollector', 'MetaMTAMailReceivedGarbageCollector' => 'PhabricatorGarbageCollector',
'MetaMTAMailSentGarbageCollector' => 'PhabricatorGarbageCollector', 'MetaMTAMailSentGarbageCollector' => 'PhabricatorGarbageCollector',
'MetaMTAReceivedMailStatus' => 'MetaMTAConstants', 'MetaMTAReceivedMailStatus' => 'Phobject',
'MultimeterContext' => 'MultimeterDimension', 'MultimeterContext' => 'MultimeterDimension',
'MultimeterControl' => 'Phobject', 'MultimeterControl' => 'Phobject',
'MultimeterController' => 'PhabricatorController', 'MultimeterController' => 'PhabricatorController',
@ -6182,6 +6181,7 @@ phutil_register_library_map(array(
'PhabricatorMailManagementShowOutboundWorkflow' => 'PhabricatorMailManagementWorkflow', 'PhabricatorMailManagementShowOutboundWorkflow' => 'PhabricatorMailManagementWorkflow',
'PhabricatorMailManagementVolumeWorkflow' => 'PhabricatorMailManagementWorkflow', 'PhabricatorMailManagementVolumeWorkflow' => 'PhabricatorMailManagementWorkflow',
'PhabricatorMailManagementWorkflow' => 'PhabricatorManagementWorkflow', 'PhabricatorMailManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorMailOutboundStatus' => 'Phobject',
'PhabricatorMailReceiver' => 'Phobject', 'PhabricatorMailReceiver' => 'Phobject',
'PhabricatorMailReceiverTestCase' => 'PhabricatorTestCase', 'PhabricatorMailReceiverTestCase' => 'PhabricatorTestCase',
'PhabricatorMailReplyHandler' => 'Phobject', 'PhabricatorMailReplyHandler' => 'Phobject',

View file

@ -18,7 +18,7 @@ final class PhabricatorMetaMTAWorker
pht('Unable to load message!')); pht('Unable to load message!'));
} }
if ($message->getStatus() != PhabricatorMetaMTAMail::STATUS_QUEUE) { if ($message->getStatus() != PhabricatorMailOutboundStatus::STATUS_QUEUE) {
return; return;
} }

View file

@ -1,3 +0,0 @@
<?php
abstract class MetaMTAConstants extends Phobject {}

View file

@ -1,7 +1,7 @@
<?php <?php
final class MetaMTAReceivedMailStatus final class MetaMTAReceivedMailStatus
extends MetaMTAConstants { extends Phobject {
const STATUS_DUPLICATE = 'err:duplicate'; const STATUS_DUPLICATE = 'err:duplicate';
const STATUS_FROM_PHABRICATOR = 'err:self'; const STATUS_FROM_PHABRICATOR = 'err:self';

View file

@ -0,0 +1,44 @@
<?php
final class PhabricatorMailOutboundStatus
extends Phobject {
const STATUS_QUEUE = 'queued';
const STATUS_SENT = 'sent';
const STATUS_FAIL = 'fail';
const STATUS_VOID = 'void';
public static function getStatusName($status_code) {
$names = array(
self::STATUS_QUEUE => pht('Queued'),
self::STATUS_FAIL => pht('Delivery Failed'),
self::STATUS_SENT => pht('Sent'),
self::STATUS_VOID => pht('Voided'),
);
$status_code = coalesce($status_code, '?');
return idx($names, $status_code, $status_code);
}
public static function getStatusIcon($status_code) {
$icons = array(
self::STATUS_QUEUE => 'fa-clock-o',
self::STATUS_FAIL => 'fa-warning',
self::STATUS_SENT => 'fa-envelope',
self::STATUS_VOID => 'fa-trash',
);
return idx($icons, $status_code, 'fa-question-circle');
}
public static function getStatusColor($status_code) {
$colors = array(
self::STATUS_QUEUE => 'blue',
self::STATUS_FAIL => 'red',
self::STATUS_SENT => 'green',
self::STATUS_VOID => 'black',
);
return idx($colors, $status_code, 'yellow');
}
}

View file

@ -25,34 +25,10 @@ final class PhabricatorMetaMTAMailViewController
->setUser($viewer) ->setUser($viewer)
->setPolicyObject($mail); ->setPolicyObject($mail);
switch ($mail->getStatus()) { $status = $mail->getStatus();
case PhabricatorMetaMTAMail::STATUS_QUEUE: $name = PhabricatorMailOutboundStatus::getStatusName($status);
$icon = 'fa-clock-o'; $icon = PhabricatorMailOutboundStatus::getStatusIcon($status);
$color = 'blue'; $color = PhabricatorMailOutboundStatus::getStatusColor($status);
$name = pht('Queued');
break;
case PhabricatorMetaMTAMail::STATUS_SENT:
$icon = 'fa-envelope';
$color = 'green';
$name = pht('Sent');
break;
case PhabricatorMetaMTAMail::STATUS_FAIL:
$icon = 'fa-envelope';
$color = 'red';
$name = pht('Delivery Failed');
break;
case PhabricatorMetaMTAMail::STATUS_VOID:
$icon = 'fa-envelope';
$color = 'black';
$name = pht('Voided');
break;
default:
$icon = 'fa-question-circle';
$color = 'yellow';
$name = pht('Unknown');
break;
}
$header->setStatus($icon, $color, $name); $header->setStatus($icon, $color, $name);
$crumbs = $this->buildApplicationCrumbs() $crumbs = $this->buildApplicationCrumbs()
@ -249,6 +225,8 @@ final class PhabricatorMetaMTAMailViewController
$properties = id(new PHUIPropertyListView()) $properties = id(new PHUIPropertyListView())
->setUser($viewer); ->setUser($viewer);
$properties->addProperty(pht('Message PHID'), $mail->getPHID());
$details = $mail->getMessage(); $details = $mail->getMessage();
if (!strlen($details)) { if (!strlen($details)) {
$details = phutil_tag('em', array(), pht('None')); $details = phutil_tag('em', array(), pht('None'));

View file

@ -45,7 +45,7 @@ final class PhabricatorMailManagementListOutboundWorkflow
$table->addRow(array( $table->addRow(array(
'id' => $mail->getID(), 'id' => $mail->getID(),
'status' => PhabricatorMetaMTAMail::getReadableStatus($status), 'status' => PhabricatorMailOutboundStatus::getStatusName($status),
'subject' => $mail->getSubject(), 'subject' => $mail->getSubject(),
)); ));
} }

View file

@ -47,7 +47,7 @@ final class PhabricatorMailManagementResendWorkflow
} }
foreach ($messages as $message) { foreach ($messages as $message) {
$message->setStatus(PhabricatorMetaMTAMail::STATUS_QUEUE); $message->setStatus(PhabricatorMailOutboundStatus::STATUS_QUEUE);
$message->save(); $message->save();
$mailer_task = PhabricatorWorker::scheduleTask( $mailer_task = PhabricatorWorker::scheduleTask(

View file

@ -101,7 +101,7 @@ final class PhabricatorMetaMTAMailSearchEngine
foreach ($mails as $mail) { foreach ($mails as $mail) {
if ($mail->hasSensitiveContent()) { if ($mail->hasSensitiveContent()) {
$header = pht('< content redacted >'); $header = phutil_tag('em', array(), pht('Content Redacted'));
} else { } else {
$header = $mail->getSubject(); $header = $mail->getSubject();
} }
@ -110,9 +110,16 @@ final class PhabricatorMetaMTAMailSearchEngine
->setUser($viewer) ->setUser($viewer)
->setObject($mail) ->setObject($mail)
->setEpoch($mail->getDateCreated()) ->setEpoch($mail->getDateCreated())
->setObjectName('Mail '.$mail->getID()) ->setObjectName(pht('Mail %d', $mail->getID()))
->setHeader($header) ->setHeader($header)
->setHref($this->getURI('detail/'.$mail->getID())); ->setHref($this->getURI('detail/'.$mail->getID().'/'));
$status = $mail->getStatus();
$status_name = PhabricatorMailOutboundStatus::getStatusName($status);
$status_icon = PhabricatorMailOutboundStatus::getStatusIcon($status);
$status_color = PhabricatorMailOutboundStatus::getStatusColor($status);
$item->setStatusIcon($status_icon.' '.$status_color, $status_name);
$list->addItem($item); $list->addItem($item);
} }

View file

@ -7,11 +7,6 @@ final class PhabricatorMetaMTAMail
extends PhabricatorMetaMTADAO extends PhabricatorMetaMTADAO
implements PhabricatorPolicyInterface { implements PhabricatorPolicyInterface {
const STATUS_QUEUE = 'queued';
const STATUS_SENT = 'sent';
const STATUS_FAIL = 'fail';
const STATUS_VOID = 'void';
const RETRY_DELAY = 5; const RETRY_DELAY = 5;
protected $actorPHID; protected $actorPHID;
@ -24,7 +19,7 @@ final class PhabricatorMetaMTAMail
public function __construct() { public function __construct() {
$this->status = self::STATUS_QUEUE; $this->status = PhabricatorMailOutboundStatus::STATUS_QUEUE;
$this->parameters = array('sensitive' => true); $this->parameters = array('sensitive' => true);
parent::__construct(); parent::__construct();
@ -430,7 +425,7 @@ final class PhabricatorMetaMTAMail
} }
if (!$force_send) { if (!$force_send) {
if ($this->getStatus() != self::STATUS_QUEUE) { if ($this->getStatus() != PhabricatorMailOutboundStatus::STATUS_QUEUE) {
throw new Exception(pht('Trying to send an already-sent mail!')); throw new Exception(pht('Trying to send an already-sent mail!'));
} }
} }
@ -662,7 +657,7 @@ final class PhabricatorMetaMTAMail
$this->setParam('actors.sent', $actor_list); $this->setParam('actors.sent', $actor_list);
if (!$add_to && !$add_cc) { if (!$add_to && !$add_cc) {
$this->setStatus(self::STATUS_VOID); $this->setStatus(PhabricatorMailOutboundStatus::STATUS_VOID);
$this->setMessage( $this->setMessage(
pht( pht(
'Message has no valid recipients: all To/Cc are disabled, '. 'Message has no valid recipients: all To/Cc are disabled, '.
@ -673,7 +668,7 @@ final class PhabricatorMetaMTAMail
if ($this->getIsErrorEmail()) { if ($this->getIsErrorEmail()) {
$all_recipients = array_merge($add_to, $add_cc); $all_recipients = array_merge($add_to, $add_cc);
if ($this->shouldRateLimitMail($all_recipients)) { if ($this->shouldRateLimitMail($all_recipients)) {
$this->setStatus(self::STATUS_VOID); $this->setStatus(PhabricatorMailOutboundStatus::STATUS_VOID);
$this->setMessage( $this->setMessage(
pht( pht(
'This is an error email, but one or more recipients have '. 'This is an error email, but one or more recipients have '.
@ -684,7 +679,7 @@ final class PhabricatorMetaMTAMail
} }
if (PhabricatorEnv::getEnvConfig('phabricator.silent')) { if (PhabricatorEnv::getEnvConfig('phabricator.silent')) {
$this->setStatus(self::STATUS_VOID); $this->setStatus(PhabricatorMailOutboundStatus::STATUS_VOID);
$this->setMessage( $this->setMessage(
pht( pht(
'Phabricator is running in silent mode. See `%s` '. 'Phabricator is running in silent mode. See `%s` '.
@ -716,7 +711,7 @@ final class PhabricatorMetaMTAMail
} }
} catch (Exception $ex) { } catch (Exception $ex) {
$this $this
->setStatus(self::STATUS_FAIL) ->setStatus(PhabricatorMailOutboundStatus::STATUS_FAIL)
->setMessage($ex->getMessage()) ->setMessage($ex->getMessage())
->save(); ->save();
@ -732,13 +727,13 @@ final class PhabricatorMetaMTAMail
pht('Mail adapter encountered an unexpected, unspecified failure.')); pht('Mail adapter encountered an unexpected, unspecified failure.'));
} }
$this->setStatus(self::STATUS_SENT); $this->setStatus(PhabricatorMailOutboundStatus::STATUS_SENT);
$this->save(); $this->save();
return $this; return $this;
} catch (PhabricatorMetaMTAPermanentFailureException $ex) { } catch (PhabricatorMetaMTAPermanentFailureException $ex) {
$this $this
->setStatus(self::STATUS_FAIL) ->setStatus(PhabricatorMailOutboundStatus::STATUS_FAIL)
->setMessage($ex->getMessage()) ->setMessage($ex->getMessage())
->save(); ->save();
@ -752,17 +747,6 @@ final class PhabricatorMetaMTAMail
} }
} }
public static function getReadableStatus($status_code) {
$readable = array(
self::STATUS_QUEUE => pht('Queued for Delivery'),
self::STATUS_FAIL => pht('Delivery Failed'),
self::STATUS_SENT => pht('Sent'),
self::STATUS_VOID => pht('Void'),
);
$status_code = coalesce($status_code, '?');
return idx($readable, $status_code, $status_code);
}
private function generateThreadIndex($seed, $is_first_mail) { private function generateThreadIndex($seed, $is_first_mail) {
// When threading, Outlook ignores the 'References' and 'In-Reply-To' // When threading, Outlook ignores the 'References' and 'In-Reply-To'
// headers that most clients use. Instead, it uses a custom 'Thread-Index' // headers that most clients use. Instead, it uses a custom 'Thread-Index'

View file

@ -20,7 +20,7 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
$mailer = new PhabricatorMailImplementationTestAdapter(); $mailer = new PhabricatorMailImplementationTestAdapter();
$mail->sendNow($force = true, $mailer); $mail->sendNow($force = true, $mailer);
$this->assertEqual( $this->assertEqual(
PhabricatorMetaMTAMail::STATUS_SENT, PhabricatorMailOutboundStatus::STATUS_SENT,
$mail->getStatus()); $mail->getStatus());
@ -36,7 +36,7 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
// Ignore. // Ignore.
} }
$this->assertEqual( $this->assertEqual(
PhabricatorMetaMTAMail::STATUS_QUEUE, PhabricatorMailOutboundStatus::STATUS_QUEUE,
$mail->getStatus()); $mail->getStatus());
@ -52,7 +52,7 @@ final class PhabricatorMetaMTAMailTestCase extends PhabricatorTestCase {
// Ignore. // Ignore.
} }
$this->assertEqual( $this->assertEqual(
PhabricatorMetaMTAMail::STATUS_FAIL, PhabricatorMailOutboundStatus::STATUS_FAIL,
$mail->getStatus()); $mail->getStatus());
} }