Differential D19021 Diff 45616 src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php
<?php | <?php | ||||
abstract class PhabricatorMailReplyHandler extends Phobject { | abstract class PhabricatorMailReplyHandler extends Phobject { | ||||
private $mailReceiver; | private $mailReceiver; | ||||
private $applicationEmail; | private $applicationEmail; | ||||
private $actor; | private $actor; | ||||
private $excludePHIDs = array(); | private $excludePHIDs = array(); | ||||
private $unexpandablePHIDs = array(); | |||||
final public function setMailReceiver($mail_receiver) { | final public function setMailReceiver($mail_receiver) { | ||||
$this->validateMailReceiver($mail_receiver); | $this->validateMailReceiver($mail_receiver); | ||||
$this->mailReceiver = $mail_receiver; | $this->mailReceiver = $mail_receiver; | ||||
return $this; | return $this; | ||||
} | } | ||||
final public function getMailReceiver() { | final public function getMailReceiver() { | ||||
Show All 23 Lines | final public function setExcludeMailRecipientPHIDs(array $exclude) { | ||||
$this->excludePHIDs = $exclude; | $this->excludePHIDs = $exclude; | ||||
return $this; | return $this; | ||||
} | } | ||||
final public function getExcludeMailRecipientPHIDs() { | final public function getExcludeMailRecipientPHIDs() { | ||||
return $this->excludePHIDs; | return $this->excludePHIDs; | ||||
} | } | ||||
public function setUnexpandablePHIDs(array $phids) { | |||||
$this->unexpandablePHIDs = $phids; | |||||
return $this; | |||||
} | |||||
public function getUnexpandablePHIDs() { | |||||
return $this->unexpandablePHIDs; | |||||
} | |||||
abstract public function validateMailReceiver($mail_receiver); | abstract public function validateMailReceiver($mail_receiver); | ||||
abstract public function getPrivateReplyHandlerEmailAddress( | abstract public function getPrivateReplyHandlerEmailAddress( | ||||
PhabricatorUser $user); | PhabricatorUser $user); | ||||
public function getReplyHandlerDomain() { | public function getReplyHandlerDomain() { | ||||
return PhabricatorEnv::getEnvConfig('metamta.reply-handler-domain'); | return PhabricatorEnv::getEnvConfig('metamta.reply-handler-domain'); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 236 Lines • ▼ Show 20 Lines | abstract class PhabricatorMailReplyHandler extends Phobject { | ||||
* @param list<phid> List of To PHIDs. | * @param list<phid> List of To PHIDs. | ||||
* @param list<phid> List of CC PHIDs. | * @param list<phid> List of CC PHIDs. | ||||
* @return pair<list<phid>, list<phid>> Expanded PHID lists. | * @return pair<list<phid>, list<phid>> Expanded PHID lists. | ||||
*/ | */ | ||||
private function expandRecipientPHIDs(array $to, array $cc) { | private function expandRecipientPHIDs(array $to, array $cc) { | ||||
$to_result = array(); | $to_result = array(); | ||||
$cc_result = array(); | $cc_result = array(); | ||||
// "Unexpandable" users have disengaged from an object (for example, | |||||
// by resigning from a revision). | |||||
// If such a user is still a direct recipient (for example, they're still | |||||
// on the Subscribers list) they're fair game, but group targets (like | |||||
// projects) will no longer include them when expanded. | |||||
$unexpandable = $this->getUnexpandablePHIDs(); | |||||
$unexpandable = array_fuse($unexpandable); | |||||
$all_phids = array_merge($to, $cc); | $all_phids = array_merge($to, $cc); | ||||
if ($all_phids) { | if ($all_phids) { | ||||
$map = id(new PhabricatorMetaMTAMemberQuery()) | $map = id(new PhabricatorMetaMTAMemberQuery()) | ||||
->setViewer(PhabricatorUser::getOmnipotentUser()) | ->setViewer(PhabricatorUser::getOmnipotentUser()) | ||||
->withPHIDs($all_phids) | ->withPHIDs($all_phids) | ||||
->execute(); | ->execute(); | ||||
foreach ($to as $phid) { | foreach ($to as $phid) { | ||||
foreach ($map[$phid] as $expanded) { | foreach ($map[$phid] as $expanded) { | ||||
if ($expanded !== $phid) { | |||||
if (isset($unexpandable[$expanded])) { | |||||
continue; | |||||
} | |||||
} | |||||
$to_result[$expanded] = $expanded; | $to_result[$expanded] = $expanded; | ||||
} | } | ||||
} | } | ||||
foreach ($cc as $phid) { | foreach ($cc as $phid) { | ||||
foreach ($map[$phid] as $expanded) { | foreach ($map[$phid] as $expanded) { | ||||
if ($expanded !== $phid) { | |||||
if (isset($unexpandable[$expanded])) { | |||||
continue; | |||||
} | |||||
} | |||||
$cc_result[$expanded] = $expanded; | $cc_result[$expanded] = $expanded; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Remove recipients from "CC" if they're also present in "To". | // Remove recipients from "CC" if they're also present in "To". | ||||
$cc_result = array_diff_key($cc_result, $to_result); | $cc_result = array_diff_key($cc_result, $to_result); | ||||
▲ Show 20 Lines • Show All 86 Lines • Show Last 20 Lines |