diff --git a/scripts/mail/manage_mail.php b/scripts/mail/manage_mail.php index a64ce6dbec..3824d7c5e5 100755 --- a/scripts/mail/manage_mail.php +++ b/scripts/mail/manage_mail.php @@ -21,6 +21,7 @@ $workflows = array( new PhabricatorMailManagementShowInboundWorkflow(), new PhabricatorMailManagementSendTestWorkflow(), new PhabricatorMailManagementReceiveTestWorkflow(), + new PhabricatorMailManagementListInboundWorkflow(), ); $args->parseWorkflows($workflows); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index fccee3c83c..b08ee014bc 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1211,6 +1211,7 @@ phutil_register_library_map(array( 'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationPHPMailerLiteAdapter.php', 'PhabricatorMailImplementationSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php', 'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php', + 'PhabricatorMailManagementListInboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php', 'PhabricatorMailManagementReceiveTestWorkflow' => 'applications/metamta/management/PhabricatorMailManagementReceiveTestWorkflow.php', 'PhabricatorMailManagementResendWorkflow' => 'applications/metamta/management/PhabricatorMailManagementResendWorkflow.php', 'PhabricatorMailManagementSendTestWorkflow' => 'applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php', @@ -1248,7 +1249,6 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAMailBodyTestCase' => 'applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php', 'PhabricatorMetaMTAMailTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php', 'PhabricatorMetaMTAMailingList' => 'applications/mailinglists/storage/PhabricatorMetaMTAMailingList.php', - 'PhabricatorMetaMTAReceivedListController' => 'applications/metamta/controller/PhabricatorMetaMTAReceivedListController.php', 'PhabricatorMetaMTAReceivedMail' => 'applications/metamta/storage/PhabricatorMetaMTAReceivedMail.php', 'PhabricatorMetaMTAReceivedMailProcessingException' => 'applications/metamta/exception/PhabricatorMetaMTAReceivedMailProcessingException.php', 'PhabricatorMetaMTAReceivedMailTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMetaMTAReceivedMailTestCase.php', @@ -3168,6 +3168,7 @@ phutil_register_library_map(array( 'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailImplementationSendGridAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter', + 'PhabricatorMailManagementListInboundWorkflow' => 'PhabricatorSearchManagementWorkflow', 'PhabricatorMailManagementReceiveTestWorkflow' => 'PhabricatorSearchManagementWorkflow', 'PhabricatorMailManagementResendWorkflow' => 'PhabricatorSearchManagementWorkflow', 'PhabricatorMailManagementSendTestWorkflow' => 'PhabricatorSearchManagementWorkflow', @@ -3196,7 +3197,6 @@ phutil_register_library_map(array( 'PhabricatorMetaMTAMailBodyTestCase' => 'PhabricatorTestCase', 'PhabricatorMetaMTAMailTestCase' => 'PhabricatorTestCase', 'PhabricatorMetaMTAMailingList' => 'PhabricatorMetaMTADAO', - 'PhabricatorMetaMTAReceivedListController' => 'PhabricatorMetaMTAController', 'PhabricatorMetaMTAReceivedMail' => 'PhabricatorMetaMTADAO', 'PhabricatorMetaMTAReceivedMailProcessingException' => 'Exception', 'PhabricatorMetaMTAReceivedMailTestCase' => 'PhabricatorTestCase', diff --git a/src/applications/metamta/application/PhabricatorApplicationMetaMTA.php b/src/applications/metamta/application/PhabricatorApplicationMetaMTA.php index 4e114a1acc..ebaaddf813 100644 --- a/src/applications/metamta/application/PhabricatorApplicationMetaMTA.php +++ b/src/applications/metamta/application/PhabricatorApplicationMetaMTA.php @@ -31,7 +31,6 @@ final class PhabricatorApplicationMetaMTA extends PhabricatorApplication { $this->getBaseURI() => array( '' => 'PhabricatorMetaMTAListController', 'view/(?P[1-9]\d*)/' => 'PhabricatorMetaMTAViewController', - 'received/' => 'PhabricatorMetaMTAReceivedListController', 'sendgrid/' => 'PhabricatorMetaMTASendGridReceiveController', ), ); diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAController.php b/src/applications/metamta/controller/PhabricatorMetaMTAController.php index ac3d174bf1..48b8235d4a 100644 --- a/src/applications/metamta/controller/PhabricatorMetaMTAController.php +++ b/src/applications/metamta/controller/PhabricatorMetaMTAController.php @@ -12,7 +12,6 @@ abstract class PhabricatorMetaMTAController extends PhabricatorController { $nav->addLabel(pht('Mail Logs')); $nav->addFilter('sent', pht('Sent Mail'), $this->getApplicationURI()); - $nav->addFilter('received', pht('Received Mail')); return $nav; } diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAReceivedListController.php b/src/applications/metamta/controller/PhabricatorMetaMTAReceivedListController.php deleted file mode 100644 index 6ae4c74b0d..0000000000 --- a/src/applications/metamta/controller/PhabricatorMetaMTAReceivedListController.php +++ /dev/null @@ -1,81 +0,0 @@ -getRequest(); - $user = $request->getUser(); - - $pager = new AphrontPagerView(); - $pager->setOffset($request->getInt('page')); - $pager->setURI($request->getRequestURI(), 'page'); - - $mails = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere( - '1 = 1 ORDER BY id DESC LIMIT %d, %d', - $pager->getOffset(), - $pager->getPageSize() + 1); - $mails = $pager->sliceResults($mails); - - $phids = array_merge( - mpull($mails, 'getAuthorPHID'), - mpull($mails, 'getRelatedPHID')); - $phids = array_unique(array_filter($phids)); - - $handles = $this->loadViewerHandles($phids); - - $rows = array(); - foreach ($mails as $mail) { - $rows[] = array( - $mail->getID(), - phabricator_date($mail->getDateCreated(), $user), - phabricator_time($mail->getDateCreated(), $user), - $mail->getAuthorPHID() - ? $handles[$mail->getAuthorPHID()]->renderLink() - : '-', - $mail->getRelatedPHID() - ? $handles[$mail->getRelatedPHID()]->renderLink() - : '-', - $mail->getMessage(), - ); - } - - $table = new AphrontTableView($rows); - $table->setHeaders( - array( - pht('ID'), - pht('Date'), - pht('Time'), - pht('Author'), - pht('Object'), - pht('Message'), - )); - $table->setColumnClasses( - array( - null, - null, - 'right', - null, - null, - 'wide', - )); - - $panel = new AphrontPanelView(); - $panel->setHeader(pht('Received Mail')); - $panel->appendChild($table); - $panel->appendChild($pager); - $panel->setNoBackground(); - - $nav = $this->buildSideNavView(); - $nav->selectFilter('received'); - $nav->appendChild($panel); - - return $this->buildApplicationPage( - $nav, - array( - 'title' => pht('Received Mail'), - 'device' => true, - )); - } -} diff --git a/src/applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php new file mode 100644 index 0000000000..91718d5f98 --- /dev/null +++ b/src/applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php @@ -0,0 +1,63 @@ +setName('list-inbound') + ->setSynopsis('List inbound messages received by Phabricator.') + ->setExamples( + "**list-inbound**") + ->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 PhabricatorMetaMTAReceivedMail())->loadAllWhere( + '1 = 1 ORDER BY id DESC LIMIT %d', + $args->getArg('limit')); + + if (!$mails) { + $console->writeErr("%s\n", "No received mail."); + return 0; + } + + $phids = array_merge( + mpull($mails, 'getRelatedPHID'), + mpull($mails, 'getAuthorPHID')); + $handles = id(new PhabricatorObjectHandleData($phids)) + ->setViewer($viewer) + ->loadHandles(); + + foreach (array_reverse($mails) as $mail) { + $console->writeOut( + "%s\n", + sprintf( + "% 8d %-16s %-20s %s", + $mail->getID(), + $mail->getAuthorPHID() + ? $handles[$mail->getAuthorPHID()]->getName() + : '-', + $mail->getRelatedPHID() + ? $handles[$mail->getRelatedPHID()]->getName() + : '-', + $mail->getSubject() + ? $mail->getSubject() + : pht('(No subject.)'))); + } + + return 0; + } + +}