Path: blob/master/src/applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php
12256 views
<?php12final class PhabricatorMailManagementShowInboundWorkflow3extends PhabricatorMailManagementWorkflow {45protected function didConstruct() {6$this7->setName('show-inbound')8->setSynopsis(pht('Show diagnostic details about inbound mail.'))9->setExamples(10'**show-inbound** --id 1 --id 2')11->setArguments(12array(13array(14'name' => 'id',15'param' => 'id',16'help' => pht('Show details about inbound mail with given ID.'),17'repeat' => true,18),19));20}2122public function execute(PhutilArgumentParser $args) {23$console = PhutilConsole::getConsole();2425$ids = $args->getArg('id');26if (!$ids) {27throw new PhutilArgumentUsageException(28pht(29"Use the '%s' flag to specify one or more messages to show.",30'--id'));31}3233$messages = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere(34'id IN (%Ld)',35$ids);3637if ($ids) {38$ids = array_fuse($ids);39$missing = array_diff_key($ids, $messages);40if ($missing) {41throw new PhutilArgumentUsageException(42pht(43'Some specified messages do not exist: %s',44implode(', ', array_keys($missing))));45}46}4748$last_key = last_key($messages);49foreach ($messages as $message_key => $message) {50$info = array();5152$info[] = pht('PROPERTIES');53$info[] = pht('ID: %d', $message->getID());54$info[] = pht('Status: %s', $message->getStatus());55$info[] = pht('Related PHID: %s', $message->getRelatedPHID());56$info[] = pht('Author PHID: %s', $message->getAuthorPHID());57$info[] = pht('Message ID Hash: %s', $message->getMessageIDHash());5859if ($message->getMessage()) {60$info[] = null;61$info[] = pht('MESSAGE');62$info[] = $message->getMessage();63}6465$info[] = null;66$info[] = pht('HEADERS');67foreach ($message->getHeaders() as $key => $value) {68if (is_array($value)) {69$value = implode("\n", $value);70}71$info[] = pht('%s: %s', $key, $value);72}7374$bodies = $message->getBodies();7576$last_body = last_key($bodies);7778$info[] = null;79$info[] = pht('BODIES');80foreach ($bodies as $key => $value) {81$info[] = pht('Body "%s"', $key);82$info[] = $value;83if ($key != $last_body) {84$info[] = null;85}86}8788$attachments = $message->getAttachments();8990$info[] = null;91$info[] = pht('ATTACHMENTS');92if (!$attachments) {93$info[] = pht('No attachments.');94} else {95foreach ($attachments as $attachment) {96$info[] = pht('File PHID: %s', $attachment);97}98}99100$console->writeOut("%s\n", implode("\n", $info));101102if ($message_key != $last_key) {103$console->writeOut("\n%s\n\n", str_repeat('-', 80));104}105}106}107108}109110111