From 7e0249d68c47180f069615078d728024c7e3cc80 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Tue, 23 Jun 2015 12:55:44 -0700 Subject: [PATCH] MetaMTA - more progress to mail app Summary: Ref T5791. This diff adds a "sensitive" flag to `PhabricatorMetaMTAMail`, defaults it to true in the constructor, and then sets it to false in teh application transaction editor. Assumption here is that sensitive emails are basically all the emails that don't flow through the application transaction editor. This diff also gets a basic "mail view" page up and going. This diff also fixes a bug writing recipient edges; the actor was being included. This bug also fixes a querying bug; we shouldn't do the automagic join of $viewer is recipient or $viewer is actor if folks are querying for recipients or actors already. The bug manifested itself as having the "inbox" be inbox + outbox. Test Plan: viewd list of messages. viewed message detail. Reviewers: epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T5791 Differential Revision: https://secure.phabricator.com/D13406 --- .../PhabricatorMetaMTAApplication.php | 4 + .../PhabricatorMetaMTAMailViewController.php | 83 ++++++++++++++++++- .../query/PhabricatorMetaMTAMailQuery.php | 26 +++--- .../PhabricatorMetaMTAMailSearchEngine.php | 15 +++- .../storage/PhabricatorMetaMTAMail.php | 25 ++++-- ...habricatorApplicationTransactionEditor.php | 1 + 6 files changed, 134 insertions(+), 20 deletions(-) diff --git a/src/applications/metamta/application/PhabricatorMetaMTAApplication.php b/src/applications/metamta/application/PhabricatorMetaMTAApplication.php index ce38ef8313..9f6633f9c4 100644 --- a/src/applications/metamta/application/PhabricatorMetaMTAApplication.php +++ b/src/applications/metamta/application/PhabricatorMetaMTAApplication.php @@ -6,6 +6,10 @@ final class PhabricatorMetaMTAApplication extends PhabricatorApplication { return pht('MetaMTA'); } + public function getBaseURI() { + return '/mail/'; + } + public function getFontIcon() { return 'fa-send'; } diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php b/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php index 56b8f895b4..859b2baf88 100644 --- a/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php +++ b/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php @@ -4,7 +4,88 @@ final class PhabricatorMetaMTAMailViewController extends PhabricatorMetaMTAController { public function handleRequest(AphrontRequest $request) { - // TODO + $viewer = $request->getUser(); + + $mail = id(new PhabricatorMetaMTAMailQuery()) + ->setViewer($viewer) + ->withIDs(array($request->getURIData('id'))) + ->executeOne(); + if (!$mail) { + return new Aphront404Response(); + } + + if ($mail->hasSensitiveContent()) { + $title = pht('Content Redacted'); + } else { + $title = $mail->getSubject(); + } + $header = id(new PHUIHeaderView()) + ->setHeader($title) + ->setUser($this->getRequest()->getUser()) + ->setPolicyObject($mail); + + $crumbs = $this->buildApplicationCrumbs() + ->addTextCrumb( + 'Mail '.$mail->getID()); + $object_box = id(new PHUIObjectBoxView()) + ->setHeader($header) + ->addPropertyList($this->buildPropertyView($mail)); + + return $this->buildApplicationPage( + array( + $crumbs, + $object_box, + ), + array( + 'title' => $title, + 'pageObjects' => array($mail->getPHID()), + )); + } + + private function buildPropertyView(PhabricatorMetaMTAMail $mail) { + $viewer = $this->getViewer(); + + $properties = id(new PHUIPropertyListView()) + ->setUser($viewer) + ->setObject($mail); + + if ($mail->getActorPHID()) { + $actor_str = $viewer->renderHandle($mail->getActorPHID()); + } else { + $actor_str = pht('Generated by Phabricator'); + } + $properties->addProperty( + pht('Actor'), + $actor_str); + + if ($mail->getFrom()) { + $from_str = $viewer->renderHandle($mail->getFrom()); + } else { + $from_str = pht('Sent by Phabricator'); + } + $properties->addProperty( + pht('From'), + $from_str); + + if ($mail->getToPHIDs()) { + $to_list = $viewer->renderHandleList($mail->getToPHIDs()); + } else { + $to_list = pht('None'); + } + $properties->addProperty( + pht('To'), + $to_list); + + if ($mail->getCcPHIDs()) { + $cc_list = $viewer->renderHandleList($mail->getCcPHIDs()); + } else { + $cc_list = pht('None'); + } + $properties->addProperty( + pht('Cc'), + $cc_list); + + return $properties; } } diff --git a/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php b/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php index f4d22bc0e7..a0965b7133 100644 --- a/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php +++ b/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php @@ -63,12 +63,14 @@ final class PhabricatorMetaMTAMailQuery $this->recipientPHIDs); } - $viewer = $this->getViewer(); - $where[] = qsprintf( - $conn_r, - 'edge.dst = %s OR actorPHID = %s', - $viewer->getPHID(), - $viewer->getPHID()); + if ($this->actorPHIDs === null && $this->recipientPHIDs === null) { + $viewer = $this->getViewer(); + $where[] = qsprintf( + $conn_r, + 'edge.dst = %s OR actorPHID = %s', + $viewer->getPHID(), + $viewer->getPHID()); + } $where[] = $this->buildPagingClause($conn_r); @@ -78,11 +80,13 @@ final class PhabricatorMetaMTAMailQuery protected function buildJoinClause(AphrontDatabaseConnection $conn) { $joins = array(); - $joins[] = qsprintf( - $conn, - 'LEFT JOIN %T edge ON mail.phid = edge.src AND edge.type = %d', - PhabricatorEdgeConfig::TABLE_NAME_EDGE, - PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST); + if ($this->actorPHIDs === null && $this->recipientPHIDs === null) { + $joins[] = qsprintf( + $conn, + 'LEFT JOIN %T edge ON mail.phid = edge.src AND edge.type = %d', + PhabricatorEdgeConfig::TABLE_NAME_EDGE, + PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST); + } if ($this->recipientPHIDs !== null) { $joins[] = qsprintf( diff --git a/src/applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php b/src/applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php index f385dd1fee..04055e756b 100644 --- a/src/applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php +++ b/src/applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php @@ -100,10 +100,21 @@ final class PhabricatorMetaMTAMailSearchEngine $list = new PHUIObjectItemListView(); foreach ($mails as $mail) { + if ($mail->hasSensitiveContent()) { + $header = pht( + 'Mail %d: < content redacted >', + $mail->getID()); + } else { + $header = pht( + 'Mail %d: %s', + $mail->getID(), + $mail->getSubject()); + } - $header = pht('Mail %d: TODO.', $mail->getID()); $item = id(new PHUIObjectItemView()) - ->setHeader($header); + ->setObject($mail) + ->setHeader($header) + ->setHref($this->getURI('detail/'.$mail->getID())); $list->addItem($item); } diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index 5d7bb37a6a..ad7c07ed8e 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -25,7 +25,7 @@ final class PhabricatorMetaMTAMail public function __construct() { $this->status = self::STATUS_QUEUE; - $this->parameters = array(); + $this->parameters = array('sensitive' => true); parent::__construct(); } @@ -262,6 +262,15 @@ final class PhabricatorMetaMTAMail return $this; } + public function setSensitiveContent($bool) { + $this->setParam('sensitive', $bool); + return $this; + } + + public function hasSensitiveContent() { + return $this->getParam('sensitive', true); + } + public function setHTMLBody($html) { $this->setParam('html-body', $html); return $this; @@ -372,11 +381,15 @@ final class PhabricatorMetaMTAMail // Write the recipient edges. $editor = new PhabricatorEdgeEditor(); $edge_type = PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST; - $actor_phids = array_unique(array_merge( - $this->getAllActorPHIDs(), - $this->getExpandedRecipientPHIDs())); - foreach ($actor_phids as $actor_phid) { - $editor->addEdge($this->getPHID(), $edge_type, $actor_phid); + $recipient_phids = array_merge( + $this->getToPHIDs(), + $this->getCcPHIDs()); + $expanded_phids = $this->expandRecipients($recipient_phids); + $all_phids = array_unique(array_merge( + $recipient_phids, + $expanded_phids)); + foreach ($all_phids as $curr_phid) { + $editor->addEdge($this->getPHID(), $edge_type, $curr_phid); } $editor->save(); diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index ea541e3cdc..eb53b3b2e0 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -2334,6 +2334,7 @@ abstract class PhabricatorApplicationTransactionEditor } $mail + ->setSensitiveContent(false) ->setFrom($this->getActingAsPHID()) ->setSubjectPrefix($this->getMailSubjectPrefix()) ->setVarySubjectPrefix('['.$action.']')