[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorMailManagementShowOutboundWorkflow 4 extends PhabricatorMailManagementWorkflow { 5 6 protected function didConstruct() { 7 $this 8 ->setName('show-outbound') 9 ->setSynopsis('Show diagnostic details about outbound mail.') 10 ->setExamples( 11 '**show-outbound** --id 1 --id 2') 12 ->setArguments( 13 array( 14 array( 15 'name' => 'id', 16 'param' => 'id', 17 'help' => 'Show details about outbound mail with given ID.', 18 'repeat' => true, 19 ), 20 array( 21 'name' => 'dump-html', 22 'help' => pht( 23 'Dump the HTML body of the mail. You can redirect it to a '. 24 'file and then open it in a browser.'), 25 ), 26 )); 27 } 28 29 public function execute(PhutilArgumentParser $args) { 30 $console = PhutilConsole::getConsole(); 31 32 $ids = $args->getArg('id'); 33 if (!$ids) { 34 throw new PhutilArgumentUsageException( 35 "Use the '--id' flag to specify one or more messages to show."); 36 } 37 38 $messages = id(new PhabricatorMetaMTAMail())->loadAllWhere( 39 'id IN (%Ld)', 40 $ids); 41 42 if ($ids) { 43 $ids = array_fuse($ids); 44 $missing = array_diff_key($ids, $messages); 45 if ($missing) { 46 throw new PhutilArgumentUsageException( 47 'Some specified messages do not exist: '. 48 implode(', ', array_keys($missing))); 49 } 50 } 51 52 $last_key = last_key($messages); 53 foreach ($messages as $message_key => $message) { 54 if ($args->getArg('dump-html')) { 55 $html_body = $message->getHTMLBody(); 56 if (strlen($html_body)) { 57 $template = 58 "<!doctype html><html><body>{$html_body}</body></html>"; 59 $console->writeOut("%s\n", $html_body); 60 } else { 61 $console->writeErr( 62 "%s\n", 63 pht('(This message has no HTML body.)')); 64 } 65 continue; 66 } 67 68 $info = array(); 69 70 $info[] = pht('PROPERTIES'); 71 $info[] = pht('ID: %d', $message->getID()); 72 $info[] = pht('Status: %s', $message->getStatus()); 73 $info[] = pht('Related PHID: %s', $message->getRelatedPHID()); 74 $info[] = pht('Message: %s', $message->getMessage()); 75 76 $info[] = null; 77 $info[] = pht('PARAMETERS'); 78 $parameters = $message->getParameters(); 79 foreach ($parameters as $key => $value) { 80 if ($key == 'body') { 81 continue; 82 } 83 84 if ($key == 'html-body') { 85 continue; 86 } 87 88 if ($key == 'headers') { 89 continue; 90 } 91 92 if ($key == 'attachments') { 93 continue; 94 } 95 96 if (!is_scalar($value)) { 97 $value = json_encode($value); 98 } 99 100 $info[] = pht('%s: %s', $key, $value); 101 } 102 103 $info[] = null; 104 $info[] = pht('HEADERS'); 105 foreach (idx($parameters, 'headers', array()) as $header) { 106 list($name, $value) = $header; 107 $info[] = "{$name}: {$value}"; 108 } 109 110 $attachments = idx($parameters, 'attachments'); 111 if ($attachments) { 112 $info[] = null; 113 $info[] = pht('ATTACHMENTS'); 114 foreach ($attachments as $attachment) { 115 $info[] = idx($attachment, 'filename', pht('Unnamed File')); 116 } 117 } 118 119 $actors = $message->loadAllActors(); 120 $actors = array_select_keys( 121 $actors, 122 array_merge($message->getToPHIDs(), $message->getCcPHIDs())); 123 $info[] = null; 124 $info[] = pht('RECIPIENTS'); 125 foreach ($actors as $actor) { 126 if ($actor->isDeliverable()) { 127 $info[] = ' '.coalesce($actor->getName(), $actor->getPHID()); 128 } else { 129 $info[] = '! '.coalesce($actor->getName(), $actor->getPHID()); 130 foreach ($actor->getUndeliverableReasons() as $reason) { 131 $info[] = ' - '.$reason; 132 } 133 } 134 } 135 136 $info[] = null; 137 $info[] = pht('TEXT BODY'); 138 if (strlen($message->getBody())) { 139 $info[] = $message->getBody(); 140 } else { 141 $info[] = pht('(This message has no text body.)'); 142 } 143 144 $info[] = null; 145 $info[] = pht('HTML BODY'); 146 if (strlen($message->getHTMLBody())) { 147 $info[] = $message->getHTMLBody(); 148 $info[] = null; 149 } else { 150 $info[] = pht('(This message has no HTML body.)'); 151 } 152 153 $console->writeOut('%s', implode("\n", $info)); 154 155 if ($message_key != $last_key) { 156 $console->writeOut("\n%s\n\n", str_repeat('-', 80)); 157 } 158 } 159 } 160 161 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |