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

Provide some diagnostic tools for examining inbound and outbound mail

Summary: We can't show this stuff on the web UI because it has password reset links and private reply-to addresses, but we can provide easier CLI tools than "root around in the database". Land a rough version of `bin/mail show-inbound` and `bin/mail show-outbound`.

Test Plan: Used both commands to examine mail from the CLI.

Reviewers: btrahan

Reviewed By: btrahan

CC: tido, euresti, aran

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

+187
+2
scripts/mail/manage_mail.php
··· 17 17 $workflows = array( 18 18 new PhabricatorMailManagementResendWorkflow(), 19 19 new PhutilHelpArgumentWorkflow(), 20 + new PhabricatorMailManagementShowOutboundWorkflow(), 21 + new PhabricatorMailManagementShowInboundWorkflow(), 20 22 ); 21 23 22 24 $args->parseWorkflows($workflows);
+4
src/__phutil_library_map__.php
··· 1088 1088 'PhabricatorMailImplementationSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php', 1089 1089 'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php', 1090 1090 'PhabricatorMailManagementResendWorkflow' => 'applications/metamta/management/PhabricatorMailManagementResendWorkflow.php', 1091 + 'PhabricatorMailManagementShowInboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php', 1092 + 'PhabricatorMailManagementShowOutboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php', 1091 1093 'PhabricatorMailManagementWorkflow' => 'applications/metamta/management/PhabricatorMailManagementWorkflow.php', 1092 1094 'PhabricatorMailReceiver' => 'applications/metamta/receiver/PhabricatorMailReceiver.php', 1093 1095 'PhabricatorMailReceiverTestCase' => 'applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php', ··· 2846 2848 'PhabricatorMailImplementationSendGridAdapter' => 'PhabricatorMailImplementationAdapter', 2847 2849 'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter', 2848 2850 'PhabricatorMailManagementResendWorkflow' => 'PhabricatorSearchManagementWorkflow', 2851 + 'PhabricatorMailManagementShowInboundWorkflow' => 'PhabricatorSearchManagementWorkflow', 2852 + 'PhabricatorMailManagementShowOutboundWorkflow' => 'PhabricatorSearchManagementWorkflow', 2849 2853 'PhabricatorMailManagementWorkflow' => 'PhutilArgumentWorkflow', 2850 2854 'PhabricatorMailReceiverTestCase' => 'PhabricatorTestCase', 2851 2855 'PhabricatorMailingListsController' => 'PhabricatorController',
+97
src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php
··· 1 + <?php 2 + 3 + final class PhabricatorMailManagementShowInboundWorkflow 4 + extends PhabricatorSearchManagementWorkflow { 5 + 6 + protected function didConstruct() { 7 + $this 8 + ->setName('show-inbound') 9 + ->setSynopsis('Show diagnostic details about inbound mail.') 10 + ->setExamples( 11 + "**show-inbound** --id 1 --id 2") 12 + ->setArguments( 13 + array( 14 + array( 15 + 'name' => 'id', 16 + 'param' => 'id', 17 + 'help' => 'Show details about inbound mail with given ID.', 18 + 'repeat' => true, 19 + ), 20 + )); 21 + } 22 + 23 + public function execute(PhutilArgumentParser $args) { 24 + $console = PhutilConsole::getConsole(); 25 + 26 + $ids = $args->getArg('id'); 27 + if (!$ids) { 28 + throw new PhutilArgumentUsageException( 29 + "Use the '--id' flag to specify one or more messages to show."); 30 + } 31 + 32 + $messages = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere( 33 + 'id IN (%Ld)', 34 + $ids); 35 + 36 + if ($ids) { 37 + $ids = array_fuse($ids); 38 + $missing = array_diff_key($ids, $messages); 39 + if ($missing) { 40 + throw new PhutilArgumentUsageException( 41 + "Some specified messages do not exist: ". 42 + implode(', ', array_keys($missing))); 43 + } 44 + } 45 + 46 + $last_key = last_key($messages); 47 + foreach ($messages as $message_key => $message) { 48 + $info = array(); 49 + 50 + $info[] = pht('PROPERTIES'); 51 + $info[] = pht('ID: %d', $message->getID()); 52 + $info[] = pht('Status: %s', $message->getStatus()); 53 + $info[] = pht('Related PHID: %s', $message->getRelatedPHID()); 54 + $info[] = pht('Author PHID: %s', $message->getAuthorPHID()); 55 + $info[] = pht('Message ID Hash: %s', $message->getMessageIDHash()); 56 + 57 + $info[] = null; 58 + $info[] = pht('HEADERS'); 59 + foreach ($message->getHeaders() as $key => $value) { 60 + $info[] = pht('%s: %s', $key, $value); 61 + } 62 + 63 + $bodies = $message->getBodies(); 64 + 65 + $last_body = last_key($bodies); 66 + 67 + $info[] = null; 68 + $info[] = pht('BODIES'); 69 + foreach ($bodies as $key => $value) { 70 + $info[] = pht('Body "%s"', $key); 71 + $info[] = $value; 72 + if ($key != $last_body) { 73 + $info[] = null; 74 + } 75 + } 76 + 77 + $attachments = $message->getAttachments(); 78 + 79 + $info[] = null; 80 + $info[] = pht('ATTACHMENTS'); 81 + if (!$attachments) { 82 + $info[] = pht('No attachments.'); 83 + } else { 84 + foreach ($attachments as $attachment) { 85 + $info[] = pht('File PHID: %s', $attachment); 86 + } 87 + } 88 + 89 + $console->writeOut("%s\n", implode("\n", $info)); 90 + 91 + if ($message_key != $last_key) { 92 + $console->writeOut("\n%s\n\n", str_repeat('-', 80)); 93 + } 94 + } 95 + } 96 + 97 + }
+84
src/applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php
··· 1 + <?php 2 + 3 + final class PhabricatorMailManagementShowOutboundWorkflow 4 + extends PhabricatorSearchManagementWorkflow { 5 + 6 + protected function didConstruct() { 7 + $this 8 + ->setName('show-outbound') 9 + ->setSynopsis('Show diagnostic details about outbound mail.') 10 + ->setExamples( 11 + "**show-outbound** --id 1 --id 2") 12 + ->setArguments( 13 + array( 14 + array( 15 + 'name' => 'id', 16 + 'param' => 'id', 17 + 'help' => 'Show details about outbound mail with given ID.', 18 + 'repeat' => true, 19 + ), 20 + )); 21 + } 22 + 23 + public function execute(PhutilArgumentParser $args) { 24 + $console = PhutilConsole::getConsole(); 25 + 26 + $ids = $args->getArg('id'); 27 + if (!$ids) { 28 + throw new PhutilArgumentUsageException( 29 + "Use the '--id' flag to specify one or more messages to show."); 30 + } 31 + 32 + $messages = id(new PhabricatorMetaMTAMail())->loadAllWhere( 33 + 'id IN (%Ld)', 34 + $ids); 35 + 36 + if ($ids) { 37 + $ids = array_fuse($ids); 38 + $missing = array_diff_key($ids, $messages); 39 + if ($missing) { 40 + throw new PhutilArgumentUsageException( 41 + "Some specified messages do not exist: ". 42 + implode(', ', array_keys($missing))); 43 + } 44 + } 45 + 46 + $last_key = last_key($messages); 47 + foreach ($messages as $message_key => $message) { 48 + $info = array(); 49 + 50 + $info[] = pht('PROPERTIES'); 51 + $info[] = pht('ID: %d', $message->getID()); 52 + $info[] = pht('Status: %s', $message->getStatus()); 53 + $info[] = pht('Retry Count: %s', $message->getRetryCount()); 54 + $info[] = pht('Next Retry: %s', $message->getNextRetry()); 55 + $info[] = pht('Related PHID: %s', $message->getRelatedPHID()); 56 + $info[] = pht('Message: %s', $message->getMessage()); 57 + 58 + $info[] = null; 59 + $info[] = pht('PARAMETERS'); 60 + foreach ($message->getParameters() as $key => $value) { 61 + if ($key == 'body') { 62 + continue; 63 + } 64 + 65 + if (!is_scalar($value)) { 66 + $value = json_encode($value); 67 + } 68 + 69 + $info[] = pht('%s: %s', $key, $value); 70 + } 71 + 72 + $info[] = null; 73 + $info[] = pht('BODY'); 74 + $info[] = $message->getBody(); 75 + 76 + $console->writeOut('%s', implode("\n", $info)); 77 + 78 + if ($message_key != $last_key) { 79 + $console->writeOut("\n%s\n\n", str_repeat('-', 80)); 80 + } 81 + } 82 + } 83 + 84 + }