1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 13:30:55 +01:00

Simplify and demuddle MetaMTA send pathways

Summary:
I pretty shortsightedly made sending a side effect of save() in the case that a
server is configured for immediate sending. Move this out, make it explicit, and
get rid of all the tangles surrounding it.

The web tool now ignores the server setting and only repsects the checkbox,
which makes far more sense.

Test Plan:
Sent mails from Maniphest, Differential, and the web console. Also ran all the
unit tests. Verified headers from Maniphest.

Reviewed By: rm
Reviewers: aran, rm
CC: tuomaspelkonen, rm, jungejason, aran
Differential Revision: 200
This commit is contained in:
epriestley 2011-04-30 22:51:25 -07:00
parent 91d009664b
commit 6bec3d2e4f
7 changed files with 23 additions and 28 deletions

View file

@ -74,9 +74,9 @@ class PhabricatorEmailLoginController extends PhabricatorAuthController {
$target_user->getPHID(), $target_user->getPHID(),
)); ));
$mail->setBody( $mail->setBody(
"blah blah blah ". "here is your link ".
PhabricatorEnv::getURI('/login/etoken/'.$etoken.'/').'?email='.phutil_escape_uri($target_user->getEmail())); PhabricatorEnv::getURI('/login/etoken/'.$etoken.'/').'?email='.phutil_escape_uri($target_user->getEmail()));
$mail->save(); $mail->saveAndSend();
$view = new AphrontRequestFailureView(); $view = new AphrontRequestFailureView();
$view->setHeader('Check Your Email'); $view->setHeader('Check Your Email');

View file

@ -101,8 +101,7 @@ abstract class DifferentialMail {
$mail->setRelatedPHID($this->getRevision()->getPHID()); $mail->setRelatedPHID($this->getRevision()->getPHID());
// Save this to the MetaMTA queue for later delivery to the MTA. $mail->saveAndSend();
$mail->save();
} }
protected function buildSubject() { protected function buildSubject() {

View file

@ -173,10 +173,7 @@ class ManiphestTransactionEditor {
"TASK DETAIL\n". "TASK DETAIL\n".
" ".$task_uri."\n"; " ".$task_uri."\n";
$base = substr(md5($task->getPHID()), 0, 27).' '.pack("N", time()); $thread_id = '<maniphest-task-'.$task->getPHID().'>';
$thread_index = base64_encode($base);
$message_id = '<maniphest-task-'.$task->getPHID().'>';
id(new PhabricatorMetaMTAMail()) id(new PhabricatorMetaMTAMail())
->setSubject( ->setSubject(
@ -184,12 +181,10 @@ class ManiphestTransactionEditor {
->setFrom($transaction->getAuthorPHID()) ->setFrom($transaction->getAuthorPHID())
->addTos($email_to) ->addTos($email_to)
->addCCs($email_cc) ->addCCs($email_cc)
->addHeader('Thread-Index', $thread_index)
->addHeader('Thread-Topic', 'Maniphest Task '.$task->getID()) ->addHeader('Thread-Topic', 'Maniphest Task '.$task->getID())
->addHeader('In-Reply-To', $message_id) ->setThreadID($thread_id, $is_create)
->addHeader('References', $message_id)
->setRelatedPHID($task->getPHID()) ->setRelatedPHID($task->getPHID())
->setBody($body) ->setBody($body)
->save(); ->saveAndSend();
} }
} }

View file

@ -33,9 +33,8 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
$mail->setSimulatedFailureCount($request->getInt('failures')); $mail->setSimulatedFailureCount($request->getInt('failures'));
$mail->setIsHTML($request->getInt('html')); $mail->setIsHTML($request->getInt('html'));
$mail->save(); $mail->save();
if ($request->getInt('immediately') && if ($request->getInt('immediately')) {
!PhabricatorEnv::getEnvConfig('metamta.send-immediately')) { $mail->sendNow();
$mail->sendNow($force_send = true);
} }
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())

View file

@ -9,7 +9,6 @@
phutil_require_module('phabricator', 'aphront/response/redirect'); phutil_require_module('phabricator', 'aphront/response/redirect');
phutil_require_module('phabricator', 'applications/metamta/controller/base'); phutil_require_module('phabricator', 'applications/metamta/controller/base');
phutil_require_module('phabricator', 'applications/metamta/storage/mail'); phutil_require_module('phabricator', 'applications/metamta/storage/mail');
phutil_require_module('phabricator', 'infrastructure/env');
phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/checkbox'); phutil_require_module('phabricator', 'view/form/control/checkbox');
phutil_require_module('phabricator', 'view/form/control/submit'); phutil_require_module('phabricator', 'view/form/control/submit');

View file

@ -35,8 +35,6 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
protected $nextRetry; protected $nextRetry;
protected $relatedPHID; protected $relatedPHID;
private $skipSendOnSave;
public function __construct() { public function __construct() {
$this->status = self::STATUS_QUEUE; $this->status = self::STATUS_QUEUE;
@ -133,20 +131,27 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
return $this; return $this;
} }
public function save() { /**
$try_send = (PhabricatorEnv::getEnvConfig('metamta.send-immediately')) && * Save a newly created mail to the database and attempt to send it
(!$this->getID()) && * immediately if the server is configured for immediate sends. When
(!$this->skipSendOnSave); * applications generate new mail they should generally use this method to
* deliver it. If the server doesn't use immediate sends, this has the same
* effect as calling save(): the mail will eventually be delivered by the
* MetaMTA daemon.
*
* @return this
*/
public function saveAndSend() {
$ret = $this->save();
$ret = parent::save(); if (PhabricatorEnv::getEnvConfig('metamta.send-immediately')) {
if ($try_send) {
$this->sendNow(); $this->sendNow();
} }
return $ret; return $ret;
} }
public function buildDefaultMailer() { public function buildDefaultMailer() {
$class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter'); $class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
PhutilSymbolLoader::loadClass($class_name); PhutilSymbolLoader::loadClass($class_name);
@ -181,8 +186,6 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
} }
} }
$this->skipSendOnSave = true;
try { try {
$parameters = $this->parameters; $parameters = $this->parameters;
$phids = array(); $phids = array();

View file

@ -133,6 +133,6 @@ EOBODY;
$mailer->setFrom($author_phid); $mailer->setFrom($author_phid);
} }
$mailer->save(); $mailer->saveAndSend();
} }
} }