Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14000624
D13813.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D13813.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
@@ -2257,6 +2257,7 @@
'PhabricatorMailManagementSendTestWorkflow' => 'applications/metamta/management/PhabricatorMailManagementSendTestWorkflow.php',
'PhabricatorMailManagementShowInboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowInboundWorkflow.php',
'PhabricatorMailManagementShowOutboundWorkflow' => 'applications/metamta/management/PhabricatorMailManagementShowOutboundWorkflow.php',
+ 'PhabricatorMailManagementVolumeWorkflow' => 'applications/metamta/management/PhabricatorMailManagementVolumeWorkflow.php',
'PhabricatorMailManagementWorkflow' => 'applications/metamta/management/PhabricatorMailManagementWorkflow.php',
'PhabricatorMailReceiver' => 'applications/metamta/receiver/PhabricatorMailReceiver.php',
'PhabricatorMailReceiverTestCase' => 'applications/metamta/receiver/__tests__/PhabricatorMailReceiverTestCase.php',
@@ -6183,6 +6184,7 @@
'PhabricatorMailManagementSendTestWorkflow' => 'PhabricatorMailManagementWorkflow',
'PhabricatorMailManagementShowInboundWorkflow' => 'PhabricatorMailManagementWorkflow',
'PhabricatorMailManagementShowOutboundWorkflow' => 'PhabricatorMailManagementWorkflow',
+ 'PhabricatorMailManagementVolumeWorkflow' => 'PhabricatorMailManagementWorkflow',
'PhabricatorMailManagementWorkflow' => 'PhabricatorManagementWorkflow',
'PhabricatorMailReceiver' => 'Phobject',
'PhabricatorMailReceiverTestCase' => 'PhabricatorTestCase',
diff --git a/src/applications/metamta/management/PhabricatorMailManagementVolumeWorkflow.php b/src/applications/metamta/management/PhabricatorMailManagementVolumeWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/applications/metamta/management/PhabricatorMailManagementVolumeWorkflow.php
@@ -0,0 +1,79 @@
+<?php
+
+final class PhabricatorMailManagementVolumeWorkflow
+ extends PhabricatorMailManagementWorkflow {
+
+ protected function didConstruct() {
+ $this
+ ->setName('volume')
+ ->setSynopsis(
+ pht('Show how much mail users have received in the last 30 days.'))
+ ->setExamples(
+ '**volume**')
+ ->setArguments(
+ array(
+ ));
+ }
+
+ public function execute(PhutilArgumentParser $args) {
+ $console = PhutilConsole::getConsole();
+ $viewer = $this->getViewer();
+
+ $since = (PhabricatorTime::getNow() - phutil_units('30 days in seconds'));
+ $until = PhabricatorTime::getNow();
+
+ $mails = id(new PhabricatorMetaMTAMailQuery())
+ ->setViewer($viewer)
+ ->withDateCreatedBetween($since, $until)
+ ->execute();
+
+ $unfiltered = array();
+
+ foreach ($mails as $mail) {
+ $unfiltered_actors = mpull($mail->loadAllActors(), 'getPHID');
+ foreach ($unfiltered_actors as $phid) {
+ if (empty($unfiltered[$phid])) {
+ $unfiltered[$phid] = 0;
+ }
+ $unfiltered[$phid]++;
+ }
+ }
+
+ arsort($unfiltered);
+
+ $table = id(new PhutilConsoleTable())
+ ->setBorders(true)
+ ->addColumn(
+ 'user',
+ array(
+ 'title' => pht('User'),
+ ))
+ ->addColumn(
+ 'unfiltered',
+ array(
+ 'title' => pht('Unfiltered'),
+ ));
+
+ $handles = $viewer->loadHandles(array_keys($unfiltered));
+ $names = mpull(iterator_to_array($handles), 'getName', 'getPHID');
+
+ foreach ($unfiltered as $phid => $count) {
+ $table->addRow(
+ array(
+ 'user' => idx($names, $phid),
+ 'unfiltered' => $count,
+ ));
+ }
+
+ $table->draw();
+
+ echo "\n";
+ echo pht('Mail sent in the last 30 days.')."\n";
+ echo pht(
+ '"Unfiltered" is raw volume before preferences were applied.')."\n";
+ echo "\n";
+
+ return 0;
+ }
+
+}
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
@@ -7,6 +7,8 @@
private $phids;
private $actorPHIDs;
private $recipientPHIDs;
+ private $createdMin;
+ private $createdMax;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -28,53 +30,73 @@
return $this;
}
+ public function withDateCreatedBetween($min, $max) {
+ $this->createdMin = $min;
+ $this->createdMax = $max;
+ return $this;
+ }
+
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
- $where = array();
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'mail.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'mail.phid IN (%Ls)',
$this->phids);
}
if ($this->actorPHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'mail.actorPHID IN (%Ls)',
$this->actorPHIDs);
}
if ($this->recipientPHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'recipient.dst IN (%Ls)',
$this->recipientPHIDs);
}
if ($this->actorPHIDs === null && $this->recipientPHIDs === null) {
$viewer = $this->getViewer();
+ if (!$viewer->isOmnipotent()) {
+ $where[] = qsprintf(
+ $conn,
+ 'edge.dst = %s OR actorPHID = %s',
+ $viewer->getPHID(),
+ $viewer->getPHID());
+ }
+ }
+
+ if ($this->createdMin !== null) {
$where[] = qsprintf(
- $conn_r,
- 'edge.dst = %s OR actorPHID = %s',
- $viewer->getPHID(),
- $viewer->getPHID());
+ $conn,
+ 'mail.dateCreated >= %d',
+ $this->createdMin);
}
- $where[] = $this->buildPagingClause($conn_r);
+ if ($this->createdMax !== null) {
+ $where[] = qsprintf(
+ $conn,
+ 'mail.dateCreated <= %d',
+ $this->createdMax);
+ }
- return $this->formatWhereClause($where);
+ return $where;
}
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Oct 25, 11:16 PM (3 w, 21 m ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6744849
Default Alt Text
D13813.diff (6 KB)
Attached To
Mode
D13813: Add a rough `bin/mail volume` command for showing mail volume
Attached
Detach File
Event Timeline
Log In to Comment