Make "Receive Test" mail form use MailReceivers
Summary: Currently this is fairly hard-coded. Instead, make it use available receivers. Ref T1205. Test Plan: Used mail form to send mail to various objects (Dnn, Tnn, Cnn, etc.). Only some of these work right now because the receiver thing still hard-codes a bunch of junk. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1205 Differential Revision: https://secure.phabricator.com/D5944
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
final class DiffusionCommitQuery
|
final class DiffusionCommitQuery
|
||||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||||
|
|
||||||
|
private $ids;
|
||||||
private $identifiers;
|
private $identifiers;
|
||||||
private $phids;
|
private $phids;
|
||||||
private $defaultRepository;
|
private $defaultRepository;
|
||||||
@@ -32,6 +33,11 @@ final class DiffusionCommitQuery
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withIDs(array $ids) {
|
||||||
|
$this->ids = $ids;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withPHIDs(array $phids) {
|
public function withPHIDs(array $phids) {
|
||||||
$this->phids = $phids;
|
$this->phids = $phids;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -164,6 +170,13 @@ final class DiffusionCommitQuery
|
|||||||
$where[] = '('.implode(' OR ', $sql).')';
|
$where[] = '('.implode(' OR ', $sql).')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->ids) {
|
||||||
|
$where[] = qsprintf(
|
||||||
|
$conn_r,
|
||||||
|
'id IN (%Ld)',
|
||||||
|
$this->ids);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->phids) {
|
if ($this->phids) {
|
||||||
$where[] = qsprintf(
|
$where[] = qsprintf(
|
||||||
$conn_r,
|
$conn_r,
|
||||||
|
|||||||
@@ -19,23 +19,64 @@ final class PhabricatorMetaMTAReceiveController
|
|||||||
|
|
||||||
if (!empty($from)) {
|
if (!empty($from)) {
|
||||||
$header_content['from'] = $from;
|
$header_content['from'] = $from;
|
||||||
|
} else {
|
||||||
|
// If the user doesn't provide a "From" address, use their primary
|
||||||
|
// address.
|
||||||
|
$header_content['from'] = $user->loadPrimaryEmail()->getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preg_match('/.+@.+/', $to)) {
|
if (preg_match('/.+@.+/', $to)) {
|
||||||
$header_content['to'] = $to;
|
$header_content['to'] = $to;
|
||||||
} else {
|
} else {
|
||||||
$receiver = PhabricatorMetaMTAReceivedMail::loadReceiverObject($to);
|
|
||||||
|
// We allow the user to use an object name instead of a real address
|
||||||
|
// as a convenience. To build the mail, we build a similar message and
|
||||||
|
// look for a receiver which will accept it.
|
||||||
|
$pseudohash = PhabricatorObjectMailReceiver::computeMailHash('x', 'y');
|
||||||
|
$pseudomail = id(new PhabricatorMetaMTAReceivedMail())
|
||||||
|
->setHeaders(
|
||||||
|
array(
|
||||||
|
'to' => $to.'+1+'.$pseudohash,
|
||||||
|
));
|
||||||
|
|
||||||
|
$receivers = id(new PhutilSymbolLoader())
|
||||||
|
->setAncestorClass('PhabricatorMailReceiver')
|
||||||
|
->loadObjects();
|
||||||
|
|
||||||
|
$receiver = null;
|
||||||
|
foreach ($receivers as $possible_receiver) {
|
||||||
|
if (!$possible_receiver->isEnabled()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!$possible_receiver->canAcceptMail($pseudomail)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$receiver = $possible_receiver;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$receiver) {
|
if (!$receiver) {
|
||||||
throw new Exception(pht("No such task or revision!"));
|
throw new Exception(
|
||||||
|
"No configured mail receiver can accept mail to '{$to}'.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!($receiver instanceof PhabricatorObjectMailReceiver)) {
|
||||||
|
$class = get_class($receiver);
|
||||||
|
throw new Exception(
|
||||||
|
"Receiver '{$class}' accepts mail to '{$to}', but is not a ".
|
||||||
|
"subclass of PhabricatorObjectMailReceiver.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = $receiver->loadMailReceiverObject($to, $user);
|
||||||
|
if (!$object) {
|
||||||
|
throw new Exception("No such object '{$to}'!");
|
||||||
}
|
}
|
||||||
|
|
||||||
$hash = PhabricatorObjectMailReceiver::computeMailHash(
|
$hash = PhabricatorObjectMailReceiver::computeMailHash(
|
||||||
$receiver->getMailKey(),
|
$object->getMailKey(),
|
||||||
$user->getPHID());
|
$user->getPHID());
|
||||||
|
|
||||||
$header_content['to'] =
|
$header_content['to'] = $to.'+'.$user->getID().'+'.$hash.'@test.com';
|
||||||
$to.'+'.$user->getID().'+'.$hash.'@';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$received->setHeaders($header_content);
|
$received->setHeaders($header_content);
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ abstract class PhabricatorObjectMailReceiver extends PhabricatorMailReceiver {
|
|||||||
*/
|
*/
|
||||||
abstract protected function loadObject($pattern, PhabricatorUser $viewer);
|
abstract protected function loadObject($pattern, PhabricatorUser $viewer);
|
||||||
|
|
||||||
|
public function loadMailReceiverObject($pattern, PhabricatorUser $viewer) {
|
||||||
|
return $this->loadObject($pattern, $viewer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function validateSender(
|
public function validateSender(
|
||||||
PhabricatorMetaMTAReceivedMail $mail,
|
PhabricatorMetaMTAReceivedMail $mail,
|
||||||
|
|||||||
Reference in New Issue
Block a user