Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php
12256 views
1
<?php
2
3
final class PhabricatorMailManagementShowInboundWorkflow
4
extends PhabricatorMailManagementWorkflow {
5
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,
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
pht(
30
"Use the '%s' flag to specify one or more messages to show.",
31
'--id'));
32
}
33
34
$messages = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere(
35
'id IN (%Ld)',
36
$ids);
37
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))));
46
}
47
}
48
49
$last_key = last_key($messages);
50
foreach ($messages as $message_key => $message) {
51
$info = array();
52
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());
59
60
if ($message->getMessage()) {
61
$info[] = null;
62
$info[] = pht('MESSAGE');
63
$info[] = $message->getMessage();
64
}
65
66
$info[] = null;
67
$info[] = pht('HEADERS');
68
foreach ($message->getHeaders() as $key => $value) {
69
if (is_array($value)) {
70
$value = implode("\n", $value);
71
}
72
$info[] = pht('%s: %s', $key, $value);
73
}
74
75
$bodies = $message->getBodies();
76
77
$last_body = last_key($bodies);
78
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;
86
}
87
}
88
89
$attachments = $message->getAttachments();
90
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);
98
}
99
}
100
101
$console->writeOut("%s\n", implode("\n", $info));
102
103
if ($message_key != $last_key) {
104
$console->writeOut("\n%s\n\n", str_repeat('-', 80));
105
}
106
}
107
}
108
109
}
110
111