From 544a84ebb97685d119c3e6731c8849fe5651a498 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 10 Jul 2013 18:52:22 -0700 Subject: [PATCH] Move outbound mail lists to CLI and enhance details Summary: Finish off moving all this stuff to the CLI. Ref T3306. Test Plan: PROPERTIES ID: 6483 Status: void Retry Count: 0 Next Retry: 1373494457 Related PHID: PHID-DREV-5bnb33yeuhuaulyc3exg Message: Message has no valid recipients: all To/Cc are disabled, invalid, or configured not to receive this mail. PARAMETERS from: PHID-USER-lqiz3yd7wmk64ejugvov is-html: parent-message-id: null thread-id: differential-rev-PHID-DREV-5bnb33yeuhuaulyc3exg-req is-first-message: null is-bulk: 1 mailtags: ["differential-comment"] cc: ["PHID-USER-cluwcdowc35gmperlkbi"] subject: D22: quack quack subject-prefix: [Differential] vary-subject-prefix: [Commented On] worker-task: 936546 HEADERS Thread-Topic: D22: quack quack X-Herald-Rules: none X-Differential-Author: X-Differential-CC: X-Differential-CC: X-Differential-CC: X-Differential-CC: X-Differential-CC: X-Differential-CC: X-Differential-CCs: , , , , , X-Differential-Explicit-CC: X-Differential-Explicit-CC: X-Differential-Explicit-CC: X-Differential-Explicit-CC: X-Differential-Explicit-CC: X-Differential-Explicit-CC: X-Differential-Explicit-CCs: , , , , , X-Phabricator-To: X-Phabricator-Cc: X-Phabricator-Cc: X-Phabricator-Cc: X-Phabricator-Cc: X-Phabricator-Cc: X-Phabricator-Cc: RECIPIENTS ! dog (dog) - This user is disabled; disabled users do not receive mail. BODY epriestley has commented on the revision "quack quack". zxcbzxcb REVISION DETAIL http://local.aphront.com:8080/D22 To: epriestley Cc: Unknown User, dog, list, duck, epriestley992, asana Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3306 Differential Revision: https://secure.phabricator.com/D6423 --- scripts/mail/manage_mail.php | 3 +- src/__phutil_library_map__.php | 4 +- .../PhabricatorApplicationMetaMTA.php | 14 +- .../PhabricatorMetaMTAController.php | 14 -- .../PhabricatorMetaMTAListController.php | 121 ------------------ ...icatorMetaMTASendGridReceiveController.php | 4 - .../PhabricatorMetaMTAViewController.php | 83 ------------ ...catorMailManagementListInboundWorkflow.php | 2 +- ...atorMailManagementListOutboundWorkflow.php | 49 +++++++ ...atorMailManagementShowOutboundWorkflow.php | 44 ++++++- .../query/PhabricatorMetaMTAActorQuery.php | 1 + 11 files changed, 106 insertions(+), 233 deletions(-) delete mode 100644 src/applications/metamta/controller/PhabricatorMetaMTAListController.php delete mode 100644 src/applications/metamta/controller/PhabricatorMetaMTAViewController.php create mode 100644 src/applications/metamta/management/PhabricatorMailManagementListOutboundWorkflow.php diff --git a/scripts/mail/manage_mail.php b/scripts/mail/manage_mail.php index 3824d7c5e5..66ecaea18e 100755 --- a/scripts/mail/manage_mail.php +++ b/scripts/mail/manage_mail.php @@ -15,13 +15,14 @@ EOSYNOPSIS $args->parseStandardArguments(); $workflows = array( - new PhabricatorMailManagementResendWorkflow(), new PhutilHelpArgumentWorkflow(), + new PhabricatorMailManagementResendWorkflow(), new PhabricatorMailManagementShowOutboundWorkflow(), new PhabricatorMailManagementShowInboundWorkflow(), new PhabricatorMailManagementSendTestWorkflow(), new PhabricatorMailManagementReceiveTestWorkflow(), new PhabricatorMailManagementListInboundWorkflow(), + new PhabricatorMailManagementListOutboundWorkflow(), ); $args->parseWorkflows($workflows); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b08ee014bc..1bc84b4569 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1212,6 +1212,7 @@ phutil_register_library_map(array( 'PhabricatorMailImplementationSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php', 'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php', 'PhabricatorMailManagementListInboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php', + 'PhabricatorMailManagementListOutboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementListOutboundWorkflow.php', 'PhabricatorMailManagementReceiveTestWorkflow' => 'applications/metamta/management/PhabricatorMailManagementReceiveTestWorkflow.php', 'PhabricatorMailManagementResendWorkflow' => 'applications/metamta/management/PhabricatorMailManagementResendWorkflow.php', 'PhabricatorMailManagementSendTestWorkflow' => 'applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php', @@ -1243,7 +1244,6 @@ phutil_register_library_map(array( 'PhabricatorMetaMTADAO' => 'applications/metamta/storage/PhabricatorMetaMTADAO.php', 'PhabricatorMetaMTAEmailBodyParser' => 'applications/metamta/parser/PhabricatorMetaMTAEmailBodyParser.php', 'PhabricatorMetaMTAEmailBodyParserTestCase' => 'applications/metamta/parser/__tests__/PhabricatorMetaMTAEmailBodyParserTestCase.php', - 'PhabricatorMetaMTAListController' => 'applications/metamta/controller/PhabricatorMetaMTAListController.php', 'PhabricatorMetaMTAMail' => 'applications/metamta/storage/PhabricatorMetaMTAMail.php', 'PhabricatorMetaMTAMailBody' => 'applications/metamta/view/PhabricatorMetaMTAMailBody.php', 'PhabricatorMetaMTAMailBodyTestCase' => 'applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php', @@ -3169,6 +3169,7 @@ phutil_register_library_map(array( 'PhabricatorMailImplementationSendGridAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailManagementListInboundWorkflow' => 'PhabricatorSearchManagementWorkflow', + 'PhabricatorMailManagementListOutboundWorkflow' => 'PhabricatorSearchManagementWorkflow', 'PhabricatorMailManagementReceiveTestWorkflow' => 'PhabricatorSearchManagementWorkflow', 'PhabricatorMailManagementResendWorkflow' => 'PhabricatorSearchManagementWorkflow', 'PhabricatorMailManagementSendTestWorkflow' => 'PhabricatorSearchManagementWorkflow', @@ -3192,7 +3193,6 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAController' => 'PhabricatorController', 'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO', 'PhabricatorMetaMTAEmailBodyParserTestCase' => 'PhabricatorTestCase', - 'PhabricatorMetaMTAListController' => 'PhabricatorMetaMTAController', 'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO', 'PhabricatorMetaMTAMailBodyTestCase' => 'PhabricatorTestCase', 'PhabricatorMetaMTAMailTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/metamta/application/PhabricatorApplicationMetaMTA.php b/src/applications/metamta/application/PhabricatorApplicationMetaMTA.php index ebaaddf813..d993aedfd9 100644 --- a/src/applications/metamta/application/PhabricatorApplicationMetaMTA.php +++ b/src/applications/metamta/application/PhabricatorApplicationMetaMTA.php @@ -6,10 +6,6 @@ final class PhabricatorApplicationMetaMTA extends PhabricatorApplication { return '/mail/'; } - public function getShortDescription() { - return pht('View Mail Logs'); - } - public function getIconName() { return 'metamta'; } @@ -26,11 +22,17 @@ final class PhabricatorApplicationMetaMTA extends PhabricatorApplication { return false; } + public function shouldAppearInLaunchView() { + return false; + } + + public function getTypeaheadURI() { + return null; + } + public function getRoutes() { return array( $this->getBaseURI() => array( - '' => 'PhabricatorMetaMTAListController', - 'view/(?P[1-9]\d*)/' => 'PhabricatorMetaMTAViewController', 'sendgrid/' => 'PhabricatorMetaMTASendGridReceiveController', ), ); diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAController.php b/src/applications/metamta/controller/PhabricatorMetaMTAController.php index 48b8235d4a..cb89aa606d 100644 --- a/src/applications/metamta/controller/PhabricatorMetaMTAController.php +++ b/src/applications/metamta/controller/PhabricatorMetaMTAController.php @@ -2,18 +2,4 @@ abstract class PhabricatorMetaMTAController extends PhabricatorController { - public function shouldRequireAdmin() { - return true; - } - - public function buildSideNavView() { - $nav = new AphrontSideNavFilterView(); - $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); - - $nav->addLabel(pht('Mail Logs')); - $nav->addFilter('sent', pht('Sent Mail'), $this->getApplicationURI()); - - return $nav; - } - } diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAListController.php b/src/applications/metamta/controller/PhabricatorMetaMTAListController.php deleted file mode 100644 index f7eb0ffbe6..0000000000 --- a/src/applications/metamta/controller/PhabricatorMetaMTAListController.php +++ /dev/null @@ -1,121 +0,0 @@ -getRequest(); - $user = $request->getUser(); - $offset = $request->getInt('offset', 0); - $related_phid = $request->getStr('phid'); - $status = $request->getStr('status'); - - $pager = new AphrontPagerView(); - $pager->setOffset($offset); - $pager->setURI($request->getRequestURI(), 'offset'); - - $mail = new PhabricatorMetaMTAMail(); - $conn_r = $mail->establishConnection('r'); - - $wheres = array(); - if ($status) { - $wheres[] = qsprintf( - $conn_r, - 'status = %s', - $status); - } - if ($related_phid) { - $wheres[] = qsprintf( - $conn_r, - 'relatedPHID = %s', - $related_phid); - } - if (count($wheres)) { - $where_clause = 'WHERE '.implode($wheres, ' AND '); - } else { - $where_clause = 'WHERE 1 = 1'; - } - - $data = queryfx_all( - $conn_r, - 'SELECT * FROM %T - %Q - ORDER BY id DESC - LIMIT %d, %d', - $mail->getTableName(), - $where_clause, - $pager->getOffset(), $pager->getPageSize() + 1); - $data = $pager->sliceResults($data); - - $mails = $mail->loadAllFromArray($data); - - // Render the details table. - $rows = array(); - foreach ($mails as $mail) { - $next_retry = $mail->getNextRetry() - time(); - if ($next_retry <= 0) { - $next_retry = "None"; - } else { - $next_retry = phabricator_format_relative_time_detailed($next_retry); - } - - $rows[] = array( - PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()), - $mail->getRetryCount(), - $next_retry, - phabricator_datetime($mail->getDateCreated(), $user), - phabricator_format_relative_time_detailed( - time() - $mail->getDateModified()), - $mail->getSubject(), - phutil_tag( - 'a', - array( - 'class' => 'button small grey', - 'href' => $this->getApplicationURI('/view/'.$mail->getID().'/'), - ), - pht('View')), - ); - } - - $table = new AphrontTableView($rows); - $table->setHeaders( - array( - pht('Status'), - pht('Retry'), - pht('Next'), - pht('Created'), - pht('Updated'), - pht('Subject'), - '', - )); - $table->setColumnClasses( - array( - null, - null, - null, - null, - null, - 'wide', - 'action', - )); - - // Render the whole page. - $panel = new AphrontPanelView(); - $panel->appendChild($table); - $panel->setHeader(pht('MetaMTA Messages')); - $panel->appendChild($pager); - $panel->setNoBackground(); - - $nav = $this->buildSideNavView(); - $nav->selectFilter('sent'); - $nav->appendChild($panel); - - return $this->buildApplicationPage( - $nav, - array( - 'title' => pht('Sent Mail'), - 'device' => true, - )); - } -} diff --git a/src/applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php b/src/applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php index 1a6a1ad837..7df1539946 100644 --- a/src/applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php +++ b/src/applications/metamta/controller/PhabricatorMetaMTASendGridReceiveController.php @@ -7,10 +7,6 @@ final class PhabricatorMetaMTASendGridReceiveController return false; } - public function shouldRequireAdmin() { - return false; - } - public function processRequest() { // No CSRF for SendGrid. diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAViewController.php b/src/applications/metamta/controller/PhabricatorMetaMTAViewController.php deleted file mode 100644 index c0a2576b66..0000000000 --- a/src/applications/metamta/controller/PhabricatorMetaMTAViewController.php +++ /dev/null @@ -1,83 +0,0 @@ -id = $data['id']; - } - - public function processRequest() { - - $request = $this->getRequest(); - $user = $request->getUser(); - - $mail = id(new PhabricatorMetaMTAMail())->load($this->id); - if (!$mail) { - return new Aphront404Response(); - } - - $crumbs = $this->buildApplicationCrumbs(); - $crumbs->addCrumb( - id(new PhabricatorCrumbView()) - ->setName(pht('Mail %d', $mail->getID()))); - - $header = id(new PhabricatorHeaderView()) - ->setHeader(pht('Mail: %s', $mail->getSubject())); - - $properties = $this->buildPropertyListView($mail); - - return $this->buildApplicationPage( - array( - $crumbs, - $header, - $properties, - ), - array( - 'title' => pht('View Mail'), - 'device' => true, - 'dust' => true, - )); - } - - private function buildPropertyListView(PhabricatorMetaMTAMail $mail) { - $viewer = $this->getRequest()->getUser(); - - $related_phid = $mail->getRelatedPHID(); - - $view = id(new PhabricatorPropertyListView()) - ->setUser($viewer); - - $view->addProperty( - pht('Status'), - PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus())); - - $view->addProperty( - pht('Retry Count'), - $mail->getRetryCount()); - - $view->addProperty( - pht('Delivery Message'), - nonempty($mail->getMessage(), '-')); - - $view->addProperty( - pht('Created'), - phabricator_datetime($mail->getDateCreated(), $viewer)); - - $phids = array(); - $phids[] = $related_phid; - $handles = $this->loadViewerHandles($phids); - - if ($related_phid) { - $related_object = $handles[$related_phid]->renderLink(); - } else { - $related_object = phutil_tag('em', array(), pht('None')); - } - - $view->addProperty(pht('Related Object'), $related_object); - - return $view; - } -} diff --git a/src/applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php index 91718d5f98..92a3ccc197 100644 --- a/src/applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php +++ b/src/applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php @@ -29,7 +29,7 @@ final class PhabricatorMailManagementListInboundWorkflow $args->getArg('limit')); if (!$mails) { - $console->writeErr("%s\n", "No received mail."); + $console->writeErr("%s\n", pht("No received mail.")); return 0; } diff --git a/src/applications/metamta/management/PhabricatorMailManagementListOutboundWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementListOutboundWorkflow.php new file mode 100644 index 0000000000..0d0a9a59bc --- /dev/null +++ b/src/applications/metamta/management/PhabricatorMailManagementListOutboundWorkflow.php @@ -0,0 +1,49 @@ +setName('list-outbound') + ->setSynopsis('List outbound messages sent by Phabricator.') + ->setExamples( + "**list-outbound**") + ->setArguments( + array( + array( + 'name' => 'limit', + 'param' => 'N', + 'default' => 100, + 'help' => 'Show a specific number of messages (default 100).', + ), + )); + } + + public function execute(PhutilArgumentParser $args) { + $console = PhutilConsole::getConsole(); + $viewer = PhabricatorUser::getOmnipotentUser(); + + $mails = id(new PhabricatorMetaMTAMail())->loadAllWhere( + '1 = 1 ORDER BY id DESC LIMIT %d', + $args->getArg('limit')); + + if (!$mails) { + $console->writeErr("%s\n", pht("No sent mail.")); + return 0; + } + + foreach (array_reverse($mails) as $mail) { + $console->writeOut( + "%s\n", + sprintf( + "% 8d %-8s %s", + $mail->getID(), + PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()), + $mail->getSubject())); + } + + return 0; + } + +} diff --git a/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php index 9bdd2a054b..81967b2bdb 100644 --- a/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php +++ b/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php @@ -57,11 +57,20 @@ final class PhabricatorMailManagementShowOutboundWorkflow $info[] = null; $info[] = pht('PARAMETERS'); - foreach ($message->getParameters() as $key => $value) { + $parameters = $message->getParameters(); + foreach ($parameters as $key => $value) { if ($key == 'body') { continue; } + if ($key == 'headers') { + continue; + } + + if ($key == 'attachments') { + continue; + } + if (!is_scalar($value)) { $value = json_encode($value); } @@ -69,6 +78,39 @@ final class PhabricatorMailManagementShowOutboundWorkflow $info[] = pht('%s: %s', $key, $value); } + $info[] = null; + $info[] = pht('HEADERS'); + foreach (idx($parameters, 'headers', array()) as $header) { + list($name, $value) = $header; + $info[] = "{$name}: {$value}"; + } + + $attachments = idx($parameters, 'attachments'); + if ($attachments) { + $info[] = null; + $info[] = pht('ATTACHMENTS'); + foreach ($attachments as $attachment) { + $info[] = $attachment['filename']; + } + } + + $actors = $message->loadAllActors(); + $actors = array_select_keys( + $actors, + array_merge($message->getToPHIDs(), $message->getCcPHIDs())); + $info[] = null; + $info[] = pht('RECIPIENTS'); + foreach ($actors as $actor) { + if ($actor->isDeliverable()) { + $info[] = ' '.coalesce($actor->getName(), $actor->getPHID()); + } else { + $info[] = '! '.coalesce($actor->getName(), $actor->getPHID()); + foreach ($actor->getUndeliverableReasons() as $reason) { + $info[] = ' - '.$reason; + } + } + } + $info[] = null; $info[] = pht('BODY'); $info[] = $message->getBody(); diff --git a/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php b/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php index 6df46bb7a6..e2f87dc8dc 100644 --- a/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php +++ b/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php @@ -130,6 +130,7 @@ final class PhabricatorMetaMTAActorQuery extends PhabricatorQuery { $lists = id(new PhabricatorMetaMTAMailingList())->loadAllWhere( 'phid IN (%Ls)', $phids); + $lists = mpull($lists, null, 'getPHID'); foreach ($phids as $phid) { $actor = $actors[$phid];