Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15457791
D13397.id32464.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D13397.id32464.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2108,10 +2108,14 @@
'PhabricatorMetaMTAMail' => 'applications/metamta/storage/PhabricatorMetaMTAMail.php',
'PhabricatorMetaMTAMailBody' => 'applications/metamta/view/PhabricatorMetaMTAMailBody.php',
'PhabricatorMetaMTAMailBodyTestCase' => 'applications/metamta/view/__tests__/PhabricatorMetaMTAMailBodyTestCase.php',
+ 'PhabricatorMetaMTAMailHasRecipientEdgeType' => 'applications/metamta/edge/PhabricatorMetaMTAMailHasRecipientEdgeType.php',
+ 'PhabricatorMetaMTAMailListController' => 'applications/metamta/controller/PhabricatorMetaMTAMailListController.php',
'PhabricatorMetaMTAMailPHIDType' => 'applications/metamta/phid/PhabricatorMetaMTAMailPHIDType.php',
'PhabricatorMetaMTAMailQuery' => 'applications/metamta/query/PhabricatorMetaMTAMailQuery.php',
+ 'PhabricatorMetaMTAMailSearchEngine' => 'applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php',
'PhabricatorMetaMTAMailSection' => 'applications/metamta/view/PhabricatorMetaMTAMailSection.php',
'PhabricatorMetaMTAMailTestCase' => 'applications/metamta/storage/__tests__/PhabricatorMetaMTAMailTestCase.php',
+ 'PhabricatorMetaMTAMailViewController' => 'applications/metamta/controller/PhabricatorMetaMTAMailViewController.php',
'PhabricatorMetaMTAMailableDatasource' => 'applications/metamta/typeahead/PhabricatorMetaMTAMailableDatasource.php',
'PhabricatorMetaMTAMailableFunctionDatasource' => 'applications/metamta/typeahead/PhabricatorMetaMTAMailableFunctionDatasource.php',
'PhabricatorMetaMTAMailgunReceiveController' => 'applications/metamta/controller/PhabricatorMetaMTAMailgunReceiveController.php',
@@ -5754,10 +5758,14 @@
),
'PhabricatorMetaMTAMailBody' => 'Phobject',
'PhabricatorMetaMTAMailBodyTestCase' => 'PhabricatorTestCase',
+ 'PhabricatorMetaMTAMailHasRecipientEdgeType' => 'PhabricatorEdgeType',
+ 'PhabricatorMetaMTAMailListController' => 'PhabricatorMetaMTAController',
'PhabricatorMetaMTAMailPHIDType' => 'PhabricatorPHIDType',
'PhabricatorMetaMTAMailQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'PhabricatorMetaMTAMailSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorMetaMTAMailSection' => 'Phobject',
'PhabricatorMetaMTAMailTestCase' => 'PhabricatorTestCase',
+ 'PhabricatorMetaMTAMailViewController' => 'PhabricatorMetaMTAController',
'PhabricatorMetaMTAMailableDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorMetaMTAMailableFunctionDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorMetaMTAMailgunReceiveController' => 'PhabricatorMetaMTAController',
diff --git a/src/applications/metamta/application/PhabricatorMetaMTAApplication.php b/src/applications/metamta/application/PhabricatorMetaMTAApplication.php
--- a/src/applications/metamta/application/PhabricatorMetaMTAApplication.php
+++ b/src/applications/metamta/application/PhabricatorMetaMTAApplication.php
@@ -37,6 +37,9 @@
public function getRoutes() {
return array(
'/mail/' => array(
+ '(query/(?P<queryKey>[^/]+)/)?' =>
+ 'PhabricatorMetaMTAMailListController',
+ 'detail/(?P<id>[1-9]\d*)/' => 'PhabricatorMetaMTAMailViewController',
'sendgrid/' => 'PhabricatorMetaMTASendGridReceiveController',
'mailgun/' => 'PhabricatorMetaMTAMailgunReceiveController',
),
diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAMailListController.php b/src/applications/metamta/controller/PhabricatorMetaMTAMailListController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/metamta/controller/PhabricatorMetaMTAMailListController.php
@@ -0,0 +1,30 @@
+<?php
+
+final class PhabricatorMetaMTAMailListController
+ extends PhabricatorMetaMTAController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $controller = id(new PhabricatorApplicationSearchController())
+ ->setQueryKey($request->getURIData('queryKey'))
+ ->setSearchEngine(new PhabricatorMetaMTAMailSearchEngine())
+ ->setNavigation($this->buildSideNav());
+
+ return $this->delegateToController($controller);
+ }
+
+ public function buildSideNav() {
+ $user = $this->getRequest()->getUser();
+
+ $nav = new AphrontSideNavFilterView();
+ $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
+
+ id(new PhabricatorMetaMTAMailSearchEngine())
+ ->setViewer($user)
+ ->addNavigationItems($nav->getMenu());
+
+ $nav->selectFilter(null);
+
+ return $nav;
+ }
+
+}
diff --git a/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php b/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/metamta/controller/PhabricatorMetaMTAMailViewController.php
@@ -0,0 +1,10 @@
+<?php
+
+final class PhabricatorMetaMTAMailViewController
+ extends PhabricatorMetaMTAController {
+
+ public function handleRequest(AphrontRequest $request) {
+ // TODO
+ }
+
+}
diff --git a/src/applications/metamta/edge/PhabricatorMetaMTAMailHasRecipientEdgeType.php b/src/applications/metamta/edge/PhabricatorMetaMTAMailHasRecipientEdgeType.php
new file mode 100644
--- /dev/null
+++ b/src/applications/metamta/edge/PhabricatorMetaMTAMailHasRecipientEdgeType.php
@@ -0,0 +1,8 @@
+<?php
+
+final class PhabricatorMetaMTAMailHasRecipientEdgeType
+ extends PhabricatorEdgeType {
+
+ const EDGECONST = 57;
+
+}
diff --git a/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php b/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php
--- a/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php
+++ b/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php
@@ -5,6 +5,8 @@
private $ids;
private $phids;
+ private $actorPHIDs;
+ private $recipientPHIDs;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -16,6 +18,16 @@
return $this;
}
+ public function withActorPHIDs(array $phids) {
+ $this->actorPHIDs = $phids;
+ return $this;
+ }
+
+ public function withRecipientPHIDs(array $phids) {
+ $this->recipientPHIDs = $phids;
+ return $this;
+ }
+
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
@@ -37,11 +49,53 @@
$this->phids);
}
+ if ($this->actorPHIDs !== null) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'mail.actorPHID IN (%Ls)',
+ $this->actorPHIDs);
+ }
+
+ if ($this->recipientPHIDs !== null) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'recipient.dst IN (%Ls)',
+ $this->recipientPHIDs);
+ }
+
+ $viewer = $this->getViewer();
+ $where[] = qsprintf(
+ $conn_r,
+ 'edge.dst = %s OR actorPHID = %s',
+ $viewer->getPHID(),
+ $viewer->getPHID());
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
+ 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->recipientPHIDs !== null) {
+ $joins[] = qsprintf(
+ $conn,
+ 'LEFT JOIN %T recipient '.
+ 'ON mail.phid = recipient.src AND recipient.type = %d',
+ PhabricatorEdgeConfig::TABLE_NAME_EDGE,
+ PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST);
+ }
+
+ return implode(' ', $joins);
+ }
+
protected function getPrimaryTableAlias() {
return 'mail';
}
diff --git a/src/applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php b/src/applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php
new file mode 100644
--- /dev/null
+++ b/src/applications/metamta/query/PhabricatorMetaMTAMailSearchEngine.php
@@ -0,0 +1,112 @@
+<?php
+
+final class PhabricatorMetaMTAMailSearchEngine
+ extends PhabricatorApplicationSearchEngine {
+
+ public function getResultTypeDescription() {
+ return pht('MetaMTA Mails');
+ }
+
+ public function getApplicationClassName() {
+ return 'PhabricatorMetaMTAApplication';
+ }
+
+ public function newQuery() {
+ return new PhabricatorMetaMTAMailQuery();
+ }
+
+ protected function shouldShowOrderField() {
+ return false;
+ }
+
+ protected function buildCustomSearchFields() {
+ return array(
+ id(new PhabricatorSearchUsersField())
+ ->setLabel(pht('Actors'))
+ ->setKey('actorPHIDs')
+ ->setAliases(array('actor', 'actors')),
+ id(new PhabricatorSearchUsersField())
+ ->setLabel(pht('Recipients'))
+ ->setKey('recipientPHIDs')
+ ->setAliases(array('recipient', 'recipients')),
+ );
+ }
+
+ protected function buildQueryFromParameters(array $map) {
+ $query = $this->newQuery();
+
+ if ($map['actorPHIDs']) {
+ $query->withActorPHIDs($map['actorPHIDs']);
+ }
+
+ if ($map['recipientPHIDs']) {
+ $query->withRecipientPHIDs($map['recipientPHIDs']);
+ }
+
+ return $query;
+ }
+
+ protected function getURI($path) {
+ return '/mail/'.$path;
+ }
+
+ protected function getBuiltinQueryNames() {
+ $names = array(
+ 'inbox' => pht('Inbox'),
+ 'outbox' => pht('Outbox'),
+ );
+
+ return $names;
+ }
+
+ public function buildSavedQueryFromBuiltin($query_key) {
+ $viewer = $this->requireViewer();
+
+ $query = $this->newSavedQuery();
+ $query->setQueryKey($query_key);
+
+ switch ($query_key) {
+ case 'inbox':
+ return $query->setParameter(
+ 'recipientPHIDs',
+ array($viewer->getPHID()));
+ case 'outbox':
+ return $query->setParameter(
+ 'actorPHIDs',
+ array($viewer->getPHID()));
+ }
+
+ return parent::buildSavedQueryFromBuiltin($query_key);
+ }
+
+ protected function getRequiredHandlePHIDsForResultList(
+ array $objects,
+ PhabricatorSavedQuery $query) {
+
+ $phids = array();
+ foreach ($objects as $mail) {
+ $phids[] = $mail->getExpandedRecipientPHIDs();
+ }
+ return array_mergev($phids);
+ }
+
+ protected function renderResultList(
+ array $mails,
+ PhabricatorSavedQuery $query,
+ array $handles) {
+
+ assert_instances_of($mails, 'PhabricatorMetaMTAMail');
+ $viewer = $this->requireViewer();
+ $list = new PHUIObjectItemListView();
+
+ foreach ($mails as $mail) {
+
+ $header = pht('Mail %d: TODO.', $mail->getID());
+ $item = id(new PHUIObjectItemView())
+ ->setHeader($header);
+ $list->addItem($item);
+ }
+
+ return $list;
+ }
+}
diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php
--- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php
+++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php
@@ -366,9 +366,20 @@
// method.
$this->openTransaction();
- // Save to generate a task ID.
+ // Save to generate a mail ID and PHID.
$result = parent::save();
+ // 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);
+ }
+ $editor->save();
+
// Queue a task to send this mail.
$mailer_task = PhabricatorWorker::scheduleTask(
'PhabricatorMetaMTAWorker',
@@ -813,11 +824,15 @@
}
public function loadAllActors() {
- $actor_phids = $this->getAllActorPHIDs();
- $actor_phids = $this->expandRecipients($actor_phids);
+ $actor_phids = $this->getExpandedRecipientPHIDs();
return $this->loadActors($actor_phids);
}
+ public function getExpandedRecipientPHIDs() {
+ $actor_phids = $this->getAllActorPHIDs();
+ return $this->expandRecipients($actor_phids);
+ }
+
private function getAllActorPHIDs() {
return array_merge(
array($this->getParam('from')),
@@ -1025,8 +1040,7 @@
}
public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
- $actor_phids = $this->getAllActorPHIDs();
- $actor_phids = $this->expandRecipients($actor_phids);
+ $actor_phids = $this->getExpandedRecipientPHIDs();
return in_array($viewer->getPHID(), $actor_phids);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Mar 31, 6:58 PM (2 d, 2 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7390336
Default Alt Text
D13397.id32464.diff (12 KB)
Attached To
Mode
D13397: MetaMTA - more progress towards a mail application
Attached
Detach File
Event Timeline
Log In to Comment