[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/metamta/management/ -> PhabricatorMailManagementShowInboundWorkflow.php (source)

   1  <?php
   2  
   3  final class PhabricatorMailManagementShowInboundWorkflow
   4    extends PhabricatorMailManagementWorkflow {
   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        if ($message->getMessage()) {
  58          $info[] = null;
  59          $info[] = pht('MESSAGE');
  60          $info[] = $message->getMessage();
  61        }
  62  
  63        $info[] = null;
  64        $info[] = pht('HEADERS');
  65        foreach ($message->getHeaders() as $key => $value) {
  66          if (is_array($value)) {
  67            $value = implode("\n", $value);
  68          }
  69          $info[] = pht('%s: %s', $key, $value);
  70        }
  71  
  72        $bodies = $message->getBodies();
  73  
  74        $last_body = last_key($bodies);
  75  
  76        $info[] = null;
  77        $info[] = pht('BODIES');
  78        foreach ($bodies as $key => $value) {
  79          $info[] = pht('Body "%s"', $key);
  80          $info[] = $value;
  81          if ($key != $last_body) {
  82            $info[] = null;
  83          }
  84        }
  85  
  86        $attachments = $message->getAttachments();
  87  
  88        $info[] = null;
  89        $info[] = pht('ATTACHMENTS');
  90        if (!$attachments) {
  91          $info[] = pht('No attachments.');
  92        } else {
  93          foreach ($attachments as $attachment) {
  94            $info[] = pht('File PHID: %s', $attachment);
  95          }
  96        }
  97  
  98        $console->writeOut("%s\n", implode("\n", $info));
  99  
 100        if ($message_key != $last_key) {
 101          $console->writeOut("\n%s\n\n", str_repeat('-', 80));
 102        }
 103      }
 104    }
 105  
 106  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1