Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / metamta / management / PhabricatorMailManagementListInboundWorkflow.php
blobc19923026d618de813f55b208132e0c44ea307a4
1 <?php
3 final class PhabricatorMailManagementListInboundWorkflow
4 extends PhabricatorMailManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('list-inbound')
9 ->setSynopsis(pht('List inbound messages.'))
10 ->setExamples(
11 '**list-inbound**')
12 ->setArguments(
13 array(
14 array(
15 'name' => 'limit',
16 'param' => 'N',
17 'default' => 100,
18 'help' => pht(
19 'Show a specific number of messages (default 100).'),
21 ));
24 public function execute(PhutilArgumentParser $args) {
25 $console = PhutilConsole::getConsole();
26 $viewer = $this->getViewer();
28 $mails = id(new PhabricatorMetaMTAReceivedMail())->loadAllWhere(
29 '1 = 1 ORDER BY id DESC LIMIT %d',
30 $args->getArg('limit'));
32 if (!$mails) {
33 $console->writeErr("%s\n", pht('No received mail.'));
34 return 0;
37 $phids = array_merge(
38 mpull($mails, 'getRelatedPHID'),
39 mpull($mails, 'getAuthorPHID'));
40 $handles = id(new PhabricatorHandleQuery())
41 ->setViewer($viewer)
42 ->withPHIDs($phids)
43 ->execute();
45 $table = id(new PhutilConsoleTable())
46 ->setShowHeader(false)
47 ->addColumn('id', array('title' => pht('ID')))
48 ->addColumn('author', array('title' => pht('Author')))
49 ->addColumn('phid', array('title' => pht('Related PHID')))
50 ->addColumn('subject', array('title' => pht('Subject')));
52 foreach (array_reverse($mails) as $mail) {
53 $table->addRow(array(
54 'id' => $mail->getID(),
55 'author' => $mail->getAuthorPHID()
56 ? $handles[$mail->getAuthorPHID()]->getName()
57 : '-',
58 'phid' => $mail->getRelatedPHID()
59 ? $handles[$mail->getRelatedPHID()]->getName()
60 : '-',
61 'subject' => $mail->getSubject()
62 ? $mail->getSubject()
63 : pht('(No subject.)'),
64 ));
67 $table->draw();
68 return 0;