diff --git a/scripts/mail/manage_mail.php b/scripts/mail/manage_mail.php index 253629655d..b80bc00b15 100755 --- a/scripts/mail/manage_mail.php +++ b/scripts/mail/manage_mail.php @@ -17,6 +17,8 @@ $args->parseStandardArguments(); $workflows = array( new PhabricatorMailManagementResendWorkflow(), new PhutilHelpArgumentWorkflow(), + new PhabricatorMailManagementShowOutboundWorkflow(), + new PhabricatorMailManagementShowInboundWorkflow(), ); $args->parseWorkflows($workflows); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 866ed861d9..0a5ea21592 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1088,6 +1088,8 @@ phutil_register_library_map(array( 'PhabricatorMailImplementationSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php', 'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php', 'PhabricatorMailManagementResendWorkflow' => 'applications/metamta/management/PhabricatorMailManagementResendWorkflow.php', + 'PhabricatorMailManagementShowInboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php', + 'PhabricatorMailManagementShowOutboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php', 'PhabricatorMailManagementWorkflow' => 'applications/metamta/management/PhabricatorMailManagementWorkflow.php', 'PhabricatorMailReceiver' => 'applications/metamta/receiver/PhabricatorMailReceiver.php', 'PhabricatorMailReceiverTestCase' => 'applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php', @@ -2846,6 +2848,8 @@ phutil_register_library_map(array( 'PhabricatorMailImplementationSendGridAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter', 'PhabricatorMailManagementResendWorkflow' => 'PhabricatorSearchManagementWorkflow', + 'PhabricatorMailManagementShowInboundWorkflow' => 'PhabricatorSearchManagementWorkflow', + 'PhabricatorMailManagementShowOutboundWorkflow' => 'PhabricatorSearchManagementWorkflow', 'PhabricatorMailManagementWorkflow' => 'PhutilArgumentWorkflow', 'PhabricatorMailReceiverTestCase' => 'PhabricatorTestCase', 'PhabricatorMailingListsController' => 'PhabricatorController', diff --git a/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php new file mode 100644 index 0000000000..6e307735ba --- /dev/null +++ b/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php @@ -0,0 +1,97 @@ +setName('show-inbound') + ->setSynopsis('Show diagnostic details about inbound mail.') + ->setExamples( + "**show-inbound** --id 1 --id 2") + ->setArguments( + array( + array( + 'name' => 'id', + 'param' => 'id', + 'help' => 'Show details about inbound mail with given ID.', + 'repeat' => true, + ), + )); + } + + public function execute(PhutilArgumentParser $args) { + $console = PhutilConsole::getConsole(); + + $ids = $args->getArg('id'); + if (!$ids) { + throw new PhutilArgumentUsageException( + "Use the '--id' flag to specify one or more messages to show."); + } + + $messages = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere( + 'id IN (%Ld)', + $ids); + + if ($ids) { + $ids = array_fuse($ids); + $missing = array_diff_key($ids, $messages); + if ($missing) { + throw new PhutilArgumentUsageException( + "Some specified messages do not exist: ". + implode(', ', array_keys($missing))); + } + } + + $last_key = last_key($messages); + foreach ($messages as $message_key => $message) { + $info = array(); + + $info[] = pht('PROPERTIES'); + $info[] = pht('ID: %d', $message->getID()); + $info[] = pht('Status: %s', $message->getStatus()); + $info[] = pht('Related PHID: %s', $message->getRelatedPHID()); + $info[] = pht('Author PHID: %s', $message->getAuthorPHID()); + $info[] = pht('Message ID Hash: %s', $message->getMessageIDHash()); + + $info[] = null; + $info[] = pht('HEADERS'); + foreach ($message->getHeaders() as $key => $value) { + $info[] = pht('%s: %s', $key, $value); + } + + $bodies = $message->getBodies(); + + $last_body = last_key($bodies); + + $info[] = null; + $info[] = pht('BODIES'); + foreach ($bodies as $key => $value) { + $info[] = pht('Body "%s"', $key); + $info[] = $value; + if ($key != $last_body) { + $info[] = null; + } + } + + $attachments = $message->getAttachments(); + + $info[] = null; + $info[] = pht('ATTACHMENTS'); + if (!$attachments) { + $info[] = pht('No attachments.'); + } else { + foreach ($attachments as $attachment) { + $info[] = pht('File PHID: %s', $attachment); + } + } + + $console->writeOut("%s\n", implode("\n", $info)); + + if ($message_key != $last_key) { + $console->writeOut("\n%s\n\n", str_repeat('-', 80)); + } + } + } + +} diff --git a/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php new file mode 100644 index 0000000000..9bdd2a054b --- /dev/null +++ b/src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php @@ -0,0 +1,84 @@ +setName('show-outbound') + ->setSynopsis('Show diagnostic details about outbound mail.') + ->setExamples( + "**show-outbound** --id 1 --id 2") + ->setArguments( + array( + array( + 'name' => 'id', + 'param' => 'id', + 'help' => 'Show details about outbound mail with given ID.', + 'repeat' => true, + ), + )); + } + + public function execute(PhutilArgumentParser $args) { + $console = PhutilConsole::getConsole(); + + $ids = $args->getArg('id'); + if (!$ids) { + throw new PhutilArgumentUsageException( + "Use the '--id' flag to specify one or more messages to show."); + } + + $messages = id(new PhabricatorMetaMTAMail())->loadAllWhere( + 'id IN (%Ld)', + $ids); + + if ($ids) { + $ids = array_fuse($ids); + $missing = array_diff_key($ids, $messages); + if ($missing) { + throw new PhutilArgumentUsageException( + "Some specified messages do not exist: ". + implode(', ', array_keys($missing))); + } + } + + $last_key = last_key($messages); + foreach ($messages as $message_key => $message) { + $info = array(); + + $info[] = pht('PROPERTIES'); + $info[] = pht('ID: %d', $message->getID()); + $info[] = pht('Status: %s', $message->getStatus()); + $info[] = pht('Retry Count: %s', $message->getRetryCount()); + $info[] = pht('Next Retry: %s', $message->getNextRetry()); + $info[] = pht('Related PHID: %s', $message->getRelatedPHID()); + $info[] = pht('Message: %s', $message->getMessage()); + + $info[] = null; + $info[] = pht('PARAMETERS'); + foreach ($message->getParameters() as $key => $value) { + if ($key == 'body') { + continue; + } + + if (!is_scalar($value)) { + $value = json_encode($value); + } + + $info[] = pht('%s: %s', $key, $value); + } + + $info[] = null; + $info[] = pht('BODY'); + $info[] = $message->getBody(); + + $console->writeOut('%s', implode("\n", $info)); + + if ($message_key != $last_key) { + $console->writeOut("\n%s\n\n", str_repeat('-', 80)); + } + } + } + +}