3 final class PhabricatorMailManagementVolumeWorkflow
4 extends PhabricatorMailManagementWorkflow
{
6 protected function didConstruct() {
10 pht('Show how much mail users have received recently.'))
20 'Number of days back (default 30).'),
25 public function execute(PhutilArgumentParser
$args) {
26 $console = PhutilConsole
::getConsole();
27 $viewer = $this->getViewer();
29 $days = (int)$args->getArg('days');
31 throw new PhutilArgumentUsageException(
33 'Period specified with --days must be at least 1.'));
36 $duration = phutil_units("{$days} days in seconds");
38 $since = (PhabricatorTime
::getNow() - $duration);
39 $until = PhabricatorTime
::getNow();
41 $mails = id(new PhabricatorMetaMTAMailQuery())
43 ->withDateCreatedBetween($since, $until)
46 $unfiltered = array();
49 foreach ($mails as $mail) {
50 // Count messages we attempted to deliver. This includes messages which
51 // were voided by preferences or other rules.
52 $unfiltered_actors = mpull($mail->loadAllActors(), 'getPHID');
53 foreach ($unfiltered_actors as $phid) {
54 if (empty($unfiltered[$phid])) {
55 $unfiltered[$phid] = 0;
60 // Now, count mail we actually delivered.
61 $result = $mail->getDeliveredActors();
63 foreach ($result as $actor_phid => $actor_info) {
64 if (!$actor_info['deliverable']) {
67 if (empty($delivered[$actor_phid])) {
68 $delivered[$actor_phid] = 0;
70 $delivered[$actor_phid]++
;
75 // Sort users by delivered mail, then unfiltered mail.
78 $delivered = $delivered +
array_fill_keys(array_keys($unfiltered), 0);
80 $table = id(new PhutilConsoleTable())
85 'title' => pht('User'),
90 'title' => pht('Unfiltered'),
95 'title' => pht('Delivered'),
98 $handles = $viewer->loadHandles(array_keys($unfiltered));
99 $names = mpull(iterator_to_array($handles), 'getName', 'getPHID');
101 foreach ($delivered as $phid => $delivered_count) {
102 $unfiltered_count = idx($unfiltered, $phid, 0);
105 'user' => idx($names, $phid),
106 'unfiltered' => $unfiltered_count,
107 'delivered' => $delivered_count,
115 'Mail sent in the last %s day(s).',
116 new PhutilNumber($days))."\n";
118 '"Unfiltered" is raw volume before rules applied.')."\n";
120 '"Delivered" shows email actually sent.')."\n";