Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / metamta / management / PhabricatorMailManagementShowInboundWorkflow.php
blobb9c0cd7d64c04e0a81993e7ce4842b3ab88f39ec
1 <?php
3 final class PhabricatorMailManagementShowInboundWorkflow
4 extends PhabricatorMailManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('show-inbound')
9 ->setSynopsis(pht('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' => pht('Show details about inbound mail with given ID.'),
18 'repeat' => true,
20 ));
23 public function execute(PhutilArgumentParser $args) {
24 $console = PhutilConsole::getConsole();
26 $ids = $args->getArg('id');
27 if (!$ids) {
28 throw new PhutilArgumentUsageException(
29 pht(
30 "Use the '%s' flag to specify one or more messages to show.",
31 '--id'));
34 $messages = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere(
35 'id IN (%Ld)',
36 $ids);
38 if ($ids) {
39 $ids = array_fuse($ids);
40 $missing = array_diff_key($ids, $messages);
41 if ($missing) {
42 throw new PhutilArgumentUsageException(
43 pht(
44 'Some specified messages do not exist: %s',
45 implode(', ', array_keys($missing))));
49 $last_key = last_key($messages);
50 foreach ($messages as $message_key => $message) {
51 $info = array();
53 $info[] = pht('PROPERTIES');
54 $info[] = pht('ID: %d', $message->getID());
55 $info[] = pht('Status: %s', $message->getStatus());
56 $info[] = pht('Related PHID: %s', $message->getRelatedPHID());
57 $info[] = pht('Author PHID: %s', $message->getAuthorPHID());
58 $info[] = pht('Message ID Hash: %s', $message->getMessageIDHash());
60 if ($message->getMessage()) {
61 $info[] = null;
62 $info[] = pht('MESSAGE');
63 $info[] = $message->getMessage();
66 $info[] = null;
67 $info[] = pht('HEADERS');
68 foreach ($message->getHeaders() as $key => $value) {
69 if (is_array($value)) {
70 $value = implode("\n", $value);
72 $info[] = pht('%s: %s', $key, $value);
75 $bodies = $message->getBodies();
77 $last_body = last_key($bodies);
79 $info[] = null;
80 $info[] = pht('BODIES');
81 foreach ($bodies as $key => $value) {
82 $info[] = pht('Body "%s"', $key);
83 $info[] = $value;
84 if ($key != $last_body) {
85 $info[] = null;
89 $attachments = $message->getAttachments();
91 $info[] = null;
92 $info[] = pht('ATTACHMENTS');
93 if (!$attachments) {
94 $info[] = pht('No attachments.');
95 } else {
96 foreach ($attachments as $attachment) {
97 $info[] = pht('File PHID: %s', $attachment);
101 $console->writeOut("%s\n", implode("\n", $info));
103 if ($message_key != $last_key) {
104 $console->writeOut("\n%s\n\n", str_repeat('-', 80));