1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-13 18:32:41 +01:00
phorge-phorge/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php
epriestley e4525f9de1 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
2013-05-20 10:13:42 -07:00

97 lines
2.6 KiB
PHP

<?php
final class PhabricatorMailManagementShowInboundWorkflow
extends PhabricatorSearchManagementWorkflow {
protected function didConstruct() {
$this
->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));
}
}
}
}