Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/storage/PhabricatorMetaMTAMail.php
Show All 10 Lines | final class PhabricatorMetaMTAMail | ||||
protected $actorPHID; | protected $actorPHID; | ||||
protected $parameters; | protected $parameters; | ||||
protected $status; | protected $status; | ||||
protected $message; | protected $message; | ||||
protected $relatedPHID; | protected $relatedPHID; | ||||
private $recipientExpansionMap; | private $recipientExpansionMap; | ||||
private $routingMap; | |||||
public function __construct() { | public function __construct() { | ||||
$this->status = PhabricatorMailOutboundStatus::STATUS_QUEUE; | $this->status = PhabricatorMailOutboundStatus::STATUS_QUEUE; | ||||
$this->parameters = array('sensitive' => true); | $this->parameters = array('sensitive' => true); | ||||
parent::__construct(); | parent::__construct(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 624 Lines • ▼ Show 20 Lines | try { | ||||
foreach ($actors as $actor) { | foreach ($actors as $actor) { | ||||
$actor_list[$actor->getPHID()] = array( | $actor_list[$actor->getPHID()] = array( | ||||
'deliverable' => $actor->isDeliverable(), | 'deliverable' => $actor->isDeliverable(), | ||||
'reasons' => $actor->getDeliverabilityReasons(), | 'reasons' => $actor->getDeliverabilityReasons(), | ||||
); | ); | ||||
} | } | ||||
$this->setParam('actors.sent', $actor_list); | $this->setParam('actors.sent', $actor_list); | ||||
$this->setParam('routing.sent', $this->getParam('routing')); | |||||
$this->setParam('routingmap.sent', $this->getRoutingRuleMap()); | |||||
if (!$add_to && !$add_cc) { | if (!$add_to && !$add_cc) { | ||||
$this->setStatus(PhabricatorMailOutboundStatus::STATUS_VOID); | $this->setStatus(PhabricatorMailOutboundStatus::STATUS_VOID); | ||||
$this->setMessage( | $this->setMessage( | ||||
pht( | pht( | ||||
'Message has no valid recipients: all To/Cc are disabled, '. | 'Message has no valid recipients: all To/Cc are disabled, '. | ||||
'invalid, or configured not to receive this mail.')); | 'invalid, or configured not to receive this mail.')); | ||||
return $this->save(); | return $this->save(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 291 Lines • ▼ Show 20 Lines | if ($tags) { | ||||
if (!$send) { | if (!$send) { | ||||
$actors[$phid]->setUndeliverable( | $actors[$phid]->setUndeliverable( | ||||
PhabricatorMetaMTAActor::REASON_MAILTAGS); | PhabricatorMetaMTAActor::REASON_MAILTAGS); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
foreach ($deliverable as $phid) { | |||||
switch ($this->getRoutingRule($phid)) { | |||||
case PhabricatorMailRoutingRule::ROUTE_AS_NOTIFICATION: | |||||
$actors[$phid]->setUndeliverable( | |||||
PhabricatorMetaMTAActor::REASON_ROUTE_AS_NOTIFICATION); | |||||
break; | |||||
case PhabricatorMailRoutingRule::ROUTE_AS_MAIL: | |||||
$actors[$phid]->setDeliverable( | |||||
PhabricatorMetaMTAActor::REASON_ROUTE_AS_MAIL); | |||||
break; | |||||
default: | |||||
// No change. | |||||
break; | |||||
} | |||||
} | |||||
// If recipients were initially deliverable and were added by "Send me an | // If recipients were initially deliverable and were added by "Send me an | ||||
// email" Herald rules, annotate them as such and make them deliverable | // email" Herald rules, annotate them as such and make them deliverable | ||||
// again, overriding any changes made by the "self mail" and "mail tags" | // again, overriding any changes made by the "self mail" and "mail tags" | ||||
// settings. | // settings. | ||||
$force_recipients = $this->getForceHeraldMailRecipientPHIDs(); | $force_recipients = $this->getForceHeraldMailRecipientPHIDs(); | ||||
$force_recipients = array_fuse($force_recipients); | $force_recipients = array_fuse($force_recipients); | ||||
if ($force_recipients) { | if ($force_recipients) { | ||||
foreach ($deliverable as $phid) { | foreach ($deliverable as $phid) { | ||||
if (isset($force_recipients[$phid])) { | if (isset($force_recipients[$phid])) { | ||||
$actors[$phid]->setDeliverable( | $actors[$phid]->setDeliverable( | ||||
PhabricatorMetaMTAActor::REASON_FORCE_HERALD); | PhabricatorMetaMTAActor::REASON_FORCE_HERALD); | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | /* -( Managing Recipients )------------------------------------------------ */ | ||||
public function getDeliveredHeaders() { | public function getDeliveredHeaders() { | ||||
return $this->getParam('headers.sent'); | return $this->getParam('headers.sent'); | ||||
} | } | ||||
public function getDeliveredActors() { | public function getDeliveredActors() { | ||||
return $this->getParam('actors.sent'); | return $this->getParam('actors.sent'); | ||||
} | } | ||||
public function getDeliveredRoutingRules() { | |||||
return $this->getParam('routing.sent'); | |||||
} | |||||
public function getDeliveredRoutingMap() { | |||||
return $this->getParam('routingmap.sent'); | |||||
} | |||||
/* -( Routing )------------------------------------------------------------ */ | |||||
public function addRoutingRule($routing_rule, $phids, $reason_phid) { | |||||
$routing = $this->getParam('routing', array()); | |||||
$routing[] = array( | |||||
'routingRule' => $routing_rule, | |||||
'phids' => $phids, | |||||
'reasonPHID' => $reason_phid, | |||||
); | |||||
$this->setParam('routing', $routing); | |||||
// Throw the routing map away so we rebuild it. | |||||
$this->routingMap = null; | |||||
return $this; | |||||
} | |||||
private function getRoutingRule($phid) { | |||||
$map = $this->getRoutingRuleMap(); | |||||
$info = idx($map, $phid, idx($map, 'default')); | |||||
if ($info) { | |||||
return idx($info, 'rule'); | |||||
} | |||||
return null; | |||||
} | |||||
private function getRoutingRuleMap() { | |||||
if ($this->routingMap === null) { | |||||
$map = array(); | |||||
$routing = $this->getParam('routing', array()); | |||||
foreach ($routing as $route) { | |||||
$phids = $route['phids']; | |||||
if ($phids === null) { | |||||
$phids = array('default'); | |||||
} | |||||
foreach ($phids as $phid) { | |||||
$new_rule = $route['routingRule']; | |||||
$current_rule = idx($map, $phid); | |||||
if ($current_rule === null) { | |||||
$is_stronger = true; | |||||
} else { | |||||
$is_stronger = PhabricatorMailRoutingRule::isStrongerThan( | |||||
$new_rule, | |||||
$current_rule); | |||||
} | |||||
if ($is_stronger) { | |||||
$map[$phid] = array( | |||||
'rule' => $new_rule, | |||||
'reason' => $route['reasonPHID'], | |||||
); | |||||
} | |||||
} | |||||
} | |||||
$this->routingMap = $map; | |||||
} | |||||
return $this->routingMap; | |||||
} | |||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */ | /* -( PhabricatorPolicyInterface )----------------------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
); | ); | ||||
Show All 18 Lines |