1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

Move outbound mail lists to CLI and enhance details

Summary: Finish off moving all this stuff to the CLI. Ref T3306.

Test Plan:
  PROPERTIES
  ID: 6483
  Status: void
  Retry Count: 0
  Next Retry: 1373494457
  Related PHID: PHID-DREV-5bnb33yeuhuaulyc3exg
  Message: Message has no valid recipients: all To/Cc are disabled, invalid, or configured not to receive this mail.

  PARAMETERS
  from: PHID-USER-lqiz3yd7wmk64ejugvov
  is-html:
  parent-message-id: null
  thread-id: differential-rev-PHID-DREV-5bnb33yeuhuaulyc3exg-req
  is-first-message: null
  is-bulk: 1
  mailtags: ["differential-comment"]
  cc: ["PHID-USER-cluwcdowc35gmperlkbi"]
  subject: D22: quack quack
  subject-prefix: [Differential]
  vary-subject-prefix: [Commented On]
  worker-task: 936546

  HEADERS
  Thread-Topic: D22: quack quack
  X-Herald-Rules: none
  X-Differential-Author: <PHID-USER-lqiz3yd7wmk64ejugvov>
  X-Differential-CC: <PHID-USER-ly3pvrtdkw7lbgs72jvr>
  X-Differential-CC: <PHID-USER-cluwcdowc35gmperlkbi>
  X-Differential-CC: <PHID-MLST-wkxaantg3q6pgdkty5pt>
  X-Differential-CC: <PHID-USER-aeabc4ipqbifny3rw4ok>
  X-Differential-CC: <PHID-USER-zqxtb3oi4pouwxnxlv3f>
  X-Differential-CC: <PHID-USER-cknqtm2dzw7twnwyiaye>
  X-Differential-CCs: <PHID-USER-ly3pvrtdkw7lbgs72jvr>, <PHID-USER-cluwcdowc35gmperlkbi>, <PHID-MLST-wkxaantg3q6pgdkty5pt>, <PHID-USER-aeabc4ipqbifny3rw4ok>, <PHID-USER-zqxtb3oi4pouwxnxlv3f>, <PHID-USER-cknqtm2dzw7twnwyiaye>
  X-Differential-Explicit-CC: <PHID-USER-ly3pvrtdkw7lbgs72jvr>
  X-Differential-Explicit-CC: <PHID-USER-cluwcdowc35gmperlkbi>
  X-Differential-Explicit-CC: <PHID-MLST-wkxaantg3q6pgdkty5pt>
  X-Differential-Explicit-CC: <PHID-USER-aeabc4ipqbifny3rw4ok>
  X-Differential-Explicit-CC: <PHID-USER-zqxtb3oi4pouwxnxlv3f>
  X-Differential-Explicit-CC: <PHID-USER-cknqtm2dzw7twnwyiaye>
  X-Differential-Explicit-CCs: <PHID-USER-ly3pvrtdkw7lbgs72jvr>, <PHID-USER-cluwcdowc35gmperlkbi>, <PHID-MLST-wkxaantg3q6pgdkty5pt>, <PHID-USER-aeabc4ipqbifny3rw4ok>, <PHID-USER-zqxtb3oi4pouwxnxlv3f>, <PHID-USER-cknqtm2dzw7twnwyiaye>
  X-Phabricator-To: <PHID-USER-lqiz3yd7wmk64ejugvov>
  X-Phabricator-Cc: <PHID-USER-ly3pvrtdkw7lbgs72jvr>
  X-Phabricator-Cc: <PHID-USER-cluwcdowc35gmperlkbi>
  X-Phabricator-Cc: <PHID-MLST-wkxaantg3q6pgdkty5pt>
  X-Phabricator-Cc: <PHID-USER-aeabc4ipqbifny3rw4ok>
  X-Phabricator-Cc: <PHID-USER-zqxtb3oi4pouwxnxlv3f>
  X-Phabricator-Cc: <PHID-USER-cknqtm2dzw7twnwyiaye>

  RECIPIENTS
  ! dog (dog)
      - This user is disabled; disabled users do not receive mail.

  BODY
  epriestley has commented on the revision "quack quack".

    zxcbzxcb

  REVISION DETAIL
    http://local.aphront.com:8080/D22

  To: epriestley
  Cc: Unknown User, dog, list, duck, epriestley992, asana

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3306

Differential Revision: https://secure.phabricator.com/D6423
This commit is contained in:
epriestley 2013-07-10 18:52:22 -07:00
parent fb9282452b
commit 544a84ebb9
11 changed files with 106 additions and 233 deletions

View file

@ -15,13 +15,14 @@ EOSYNOPSIS
$args->parseStandardArguments();
$workflows = array(
new PhabricatorMailManagementResendWorkflow(),
new PhutilHelpArgumentWorkflow(),
new PhabricatorMailManagementResendWorkflow(),
new PhabricatorMailManagementShowOutboundWorkflow(),
new PhabricatorMailManagementShowInboundWorkflow(),
new PhabricatorMailManagementSendTestWorkflow(),
new PhabricatorMailManagementReceiveTestWorkflow(),
new PhabricatorMailManagementListInboundWorkflow(),
new PhabricatorMailManagementListOutboundWorkflow(),
);
$args->parseWorkflows($workflows);

View file

@ -1212,6 +1212,7 @@ phutil_register_library_map(array(
'PhabricatorMailImplementationSendGridAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationSendGridAdapter.php',
'PhabricatorMailImplementationTestAdapter' => 'applications/metamta/adapter/PhabricatorMailImplementationTestAdapter.php',
'PhabricatorMailManagementListInboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementListInboundWorkflow.php',
'PhabricatorMailManagementListOutboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementListOutboundWorkflow.php',
'PhabricatorMailManagementReceiveTestWorkflow' => 'applications/metamta/management/PhabricatorMailManagementReceiveTestWorkflow.php',
'PhabricatorMailManagementResendWorkflow' => 'applications/metamta/management/PhabricatorMailManagementResendWorkflow.php',
'PhabricatorMailManagementSendTestWorkflow' => 'applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php',
@ -1243,7 +1244,6 @@ phutil_register_library_map(array(
'PhabricatorMetaMTADAO' => 'applications/metamta/storage/PhabricatorMetaMTADAO.php',
'PhabricatorMetaMTAEmailBodyParser' => 'applications/metamta/parser/PhabricatorMetaMTAEmailBodyParser.php',
'PhabricatorMetaMTAEmailBodyParserTestCase' => 'applications/metamta/parser/__tests__/PhabricatorMetaMTAEmailBodyParserTestCase.php',
'PhabricatorMetaMTAListController' => 'applications/metamta/controller/PhabricatorMetaMTAListController.php',
'PhabricatorMetaMTAMail' => 'applications/metamta/storage/PhabricatorMetaMTAMail.php',
'PhabricatorMetaMTAMailBody' => 'applications/metamta/view/PhabricatorMetaMTAMailBody.php',
'PhabricatorMetaMTAMailBodyTestCase' => 'applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php',
@ -3169,6 +3169,7 @@ phutil_register_library_map(array(
'PhabricatorMailImplementationSendGridAdapter' => 'PhabricatorMailImplementationAdapter',
'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter',
'PhabricatorMailManagementListInboundWorkflow' => 'PhabricatorSearchManagementWorkflow',
'PhabricatorMailManagementListOutboundWorkflow' => 'PhabricatorSearchManagementWorkflow',
'PhabricatorMailManagementReceiveTestWorkflow' => 'PhabricatorSearchManagementWorkflow',
'PhabricatorMailManagementResendWorkflow' => 'PhabricatorSearchManagementWorkflow',
'PhabricatorMailManagementSendTestWorkflow' => 'PhabricatorSearchManagementWorkflow',
@ -3192,7 +3193,6 @@ phutil_register_library_map(array(
'PhabricatorMetaMTAController' => 'PhabricatorController',
'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO',
'PhabricatorMetaMTAEmailBodyParserTestCase' => 'PhabricatorTestCase',
'PhabricatorMetaMTAListController' => 'PhabricatorMetaMTAController',
'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO',
'PhabricatorMetaMTAMailBodyTestCase' => 'PhabricatorTestCase',
'PhabricatorMetaMTAMailTestCase' => 'PhabricatorTestCase',

View file

@ -6,10 +6,6 @@ final class PhabricatorApplicationMetaMTA extends PhabricatorApplication {
return '/mail/';
}
public function getShortDescription() {
return pht('View Mail Logs');
}
public function getIconName() {
return 'metamta';
}
@ -26,11 +22,17 @@ final class PhabricatorApplicationMetaMTA extends PhabricatorApplication {
return false;
}
public function shouldAppearInLaunchView() {
return false;
}
public function getTypeaheadURI() {
return null;
}
public function getRoutes() {
return array(
$this->getBaseURI() => array(
'' => 'PhabricatorMetaMTAListController',
'view/(?P<id>[1-9]\d*)/' => 'PhabricatorMetaMTAViewController',
'sendgrid/' => 'PhabricatorMetaMTASendGridReceiveController',
),
);

View file

@ -2,18 +2,4 @@
abstract class PhabricatorMetaMTAController extends PhabricatorController {
public function shouldRequireAdmin() {
return true;
}
public function buildSideNavView() {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$nav->addLabel(pht('Mail Logs'));
$nav->addFilter('sent', pht('Sent Mail'), $this->getApplicationURI());
return $nav;
}
}

View file

@ -1,121 +0,0 @@
<?php
final class PhabricatorMetaMTAListController
extends PhabricatorMetaMTAController {
public function processRequest() {
// Get a page of mails together with pager.
$request = $this->getRequest();
$user = $request->getUser();
$offset = $request->getInt('offset', 0);
$related_phid = $request->getStr('phid');
$status = $request->getStr('status');
$pager = new AphrontPagerView();
$pager->setOffset($offset);
$pager->setURI($request->getRequestURI(), 'offset');
$mail = new PhabricatorMetaMTAMail();
$conn_r = $mail->establishConnection('r');
$wheres = array();
if ($status) {
$wheres[] = qsprintf(
$conn_r,
'status = %s',
$status);
}
if ($related_phid) {
$wheres[] = qsprintf(
$conn_r,
'relatedPHID = %s',
$related_phid);
}
if (count($wheres)) {
$where_clause = 'WHERE '.implode($wheres, ' AND ');
} else {
$where_clause = 'WHERE 1 = 1';
}
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T
%Q
ORDER BY id DESC
LIMIT %d, %d',
$mail->getTableName(),
$where_clause,
$pager->getOffset(), $pager->getPageSize() + 1);
$data = $pager->sliceResults($data);
$mails = $mail->loadAllFromArray($data);
// Render the details table.
$rows = array();
foreach ($mails as $mail) {
$next_retry = $mail->getNextRetry() - time();
if ($next_retry <= 0) {
$next_retry = "None";
} else {
$next_retry = phabricator_format_relative_time_detailed($next_retry);
}
$rows[] = array(
PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()),
$mail->getRetryCount(),
$next_retry,
phabricator_datetime($mail->getDateCreated(), $user),
phabricator_format_relative_time_detailed(
time() - $mail->getDateModified()),
$mail->getSubject(),
phutil_tag(
'a',
array(
'class' => 'button small grey',
'href' => $this->getApplicationURI('/view/'.$mail->getID().'/'),
),
pht('View')),
);
}
$table = new AphrontTableView($rows);
$table->setHeaders(
array(
pht('Status'),
pht('Retry'),
pht('Next'),
pht('Created'),
pht('Updated'),
pht('Subject'),
'',
));
$table->setColumnClasses(
array(
null,
null,
null,
null,
null,
'wide',
'action',
));
// Render the whole page.
$panel = new AphrontPanelView();
$panel->appendChild($table);
$panel->setHeader(pht('MetaMTA Messages'));
$panel->appendChild($pager);
$panel->setNoBackground();
$nav = $this->buildSideNavView();
$nav->selectFilter('sent');
$nav->appendChild($panel);
return $this->buildApplicationPage(
$nav,
array(
'title' => pht('Sent Mail'),
'device' => true,
));
}
}

View file

@ -7,10 +7,6 @@ final class PhabricatorMetaMTASendGridReceiveController
return false;
}
public function shouldRequireAdmin() {
return false;
}
public function processRequest() {
// No CSRF for SendGrid.

View file

@ -1,83 +0,0 @@
<?php
final class PhabricatorMetaMTAViewController
extends PhabricatorMetaMTAController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$mail = id(new PhabricatorMetaMTAMail())->load($this->id);
if (!$mail) {
return new Aphront404Response();
}
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('Mail %d', $mail->getID())));
$header = id(new PhabricatorHeaderView())
->setHeader(pht('Mail: %s', $mail->getSubject()));
$properties = $this->buildPropertyListView($mail);
return $this->buildApplicationPage(
array(
$crumbs,
$header,
$properties,
),
array(
'title' => pht('View Mail'),
'device' => true,
'dust' => true,
));
}
private function buildPropertyListView(PhabricatorMetaMTAMail $mail) {
$viewer = $this->getRequest()->getUser();
$related_phid = $mail->getRelatedPHID();
$view = id(new PhabricatorPropertyListView())
->setUser($viewer);
$view->addProperty(
pht('Status'),
PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()));
$view->addProperty(
pht('Retry Count'),
$mail->getRetryCount());
$view->addProperty(
pht('Delivery Message'),
nonempty($mail->getMessage(), '-'));
$view->addProperty(
pht('Created'),
phabricator_datetime($mail->getDateCreated(), $viewer));
$phids = array();
$phids[] = $related_phid;
$handles = $this->loadViewerHandles($phids);
if ($related_phid) {
$related_object = $handles[$related_phid]->renderLink();
} else {
$related_object = phutil_tag('em', array(), pht('None'));
}
$view->addProperty(pht('Related Object'), $related_object);
return $view;
}
}

View file

@ -29,7 +29,7 @@ final class PhabricatorMailManagementListInboundWorkflow
$args->getArg('limit'));
if (!$mails) {
$console->writeErr("%s\n", "No received mail.");
$console->writeErr("%s\n", pht("No received mail."));
return 0;
}

View file

@ -0,0 +1,49 @@
<?php
final class PhabricatorMailManagementListOutboundWorkflow
extends PhabricatorSearchManagementWorkflow {
protected function didConstruct() {
$this
->setName('list-outbound')
->setSynopsis('List outbound messages sent by Phabricator.')
->setExamples(
"**list-outbound**")
->setArguments(
array(
array(
'name' => 'limit',
'param' => 'N',
'default' => 100,
'help' => 'Show a specific number of messages (default 100).',
),
));
}
public function execute(PhutilArgumentParser $args) {
$console = PhutilConsole::getConsole();
$viewer = PhabricatorUser::getOmnipotentUser();
$mails = id(new PhabricatorMetaMTAMail())->loadAllWhere(
'1 = 1 ORDER BY id DESC LIMIT %d',
$args->getArg('limit'));
if (!$mails) {
$console->writeErr("%s\n", pht("No sent mail."));
return 0;
}
foreach (array_reverse($mails) as $mail) {
$console->writeOut(
"%s\n",
sprintf(
"% 8d %-8s %s",
$mail->getID(),
PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()),
$mail->getSubject()));
}
return 0;
}
}

View file

@ -57,11 +57,20 @@ final class PhabricatorMailManagementShowOutboundWorkflow
$info[] = null;
$info[] = pht('PARAMETERS');
foreach ($message->getParameters() as $key => $value) {
$parameters = $message->getParameters();
foreach ($parameters as $key => $value) {
if ($key == 'body') {
continue;
}
if ($key == 'headers') {
continue;
}
if ($key == 'attachments') {
continue;
}
if (!is_scalar($value)) {
$value = json_encode($value);
}
@ -69,6 +78,39 @@ final class PhabricatorMailManagementShowOutboundWorkflow
$info[] = pht('%s: %s', $key, $value);
}
$info[] = null;
$info[] = pht('HEADERS');
foreach (idx($parameters, 'headers', array()) as $header) {
list($name, $value) = $header;
$info[] = "{$name}: {$value}";
}
$attachments = idx($parameters, 'attachments');
if ($attachments) {
$info[] = null;
$info[] = pht('ATTACHMENTS');
foreach ($attachments as $attachment) {
$info[] = $attachment['filename'];
}
}
$actors = $message->loadAllActors();
$actors = array_select_keys(
$actors,
array_merge($message->getToPHIDs(), $message->getCcPHIDs()));
$info[] = null;
$info[] = pht('RECIPIENTS');
foreach ($actors as $actor) {
if ($actor->isDeliverable()) {
$info[] = ' '.coalesce($actor->getName(), $actor->getPHID());
} else {
$info[] = '! '.coalesce($actor->getName(), $actor->getPHID());
foreach ($actor->getUndeliverableReasons() as $reason) {
$info[] = ' - '.$reason;
}
}
}
$info[] = null;
$info[] = pht('BODY');
$info[] = $message->getBody();

View file

@ -130,6 +130,7 @@ final class PhabricatorMetaMTAActorQuery extends PhabricatorQuery {
$lists = id(new PhabricatorMetaMTAMailingList())->loadAllWhere(
'phid IN (%Ls)',
$phids);
$lists = mpull($lists, null, 'getPHID');
foreach ($phids as $phid) {
$actor = $actors[$phid];