mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
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:
parent
2676e91dd8
commit
a548773209
3 changed files with 63 additions and 5 deletions
|
@ -3,6 +3,7 @@
|
|||
final class DiffusionCommitQuery
|
||||
extends PhabricatorCursorPagedPolicyAwareQuery {
|
||||
|
||||
private $ids;
|
||||
private $identifiers;
|
||||
private $phids;
|
||||
private $defaultRepository;
|
||||
|
@ -32,6 +33,11 @@ final class DiffusionCommitQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
$this->ids = $ids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withPHIDs(array $phids) {
|
||||
$this->phids = $phids;
|
||||
return $this;
|
||||
|
@ -164,6 +170,13 @@ final class DiffusionCommitQuery
|
|||
$where[] = '('.implode(' OR ', $sql).')';
|
||||
}
|
||||
|
||||
if ($this->ids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
|
|
|
@ -19,23 +19,64 @@ final class PhabricatorMetaMTAReceiveController
|
|||
|
||||
if (!empty($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)) {
|
||||
$header_content['to'] = $to;
|
||||
} 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) {
|
||||
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(
|
||||
$receiver->getMailKey(),
|
||||
$object->getMailKey(),
|
||||
$user->getPHID());
|
||||
|
||||
$header_content['to'] =
|
||||
$to.'+'.$user->getID().'+'.$hash.'@';
|
||||
$header_content['to'] = $to.'+'.$user->getID().'+'.$hash.'@test.com';
|
||||
}
|
||||
|
||||
$received->setHeaders($header_content);
|
||||
|
|
|
@ -26,6 +26,10 @@ abstract class PhabricatorObjectMailReceiver extends PhabricatorMailReceiver {
|
|||
*/
|
||||
abstract protected function loadObject($pattern, PhabricatorUser $viewer);
|
||||
|
||||
public function loadMailReceiverObject($pattern, PhabricatorUser $viewer) {
|
||||
return $this->loadObject($pattern, $viewer);
|
||||
}
|
||||
|
||||
|
||||
public function validateSender(
|
||||
PhabricatorMetaMTAReceivedMail $mail,
|
||||
|
|
Loading…
Reference in a new issue