From 67c302ae4f90d4b100bf049ee6ba9d629e46dfb0 Mon Sep 17 00:00:00 2001 From: Nick Harper Date: Tue, 17 Jul 2012 16:50:52 -0700 Subject: [PATCH] Send messages with only a CC Summary: This keeps people in the correct To or CC field on multiplexed messages. Test Plan: with multiplexing on, checked that I received an email with me in the CC field instead of the To field for a diff I'm CC'd on. Reviewers: epriestley, jungejason, vrana Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D2999 --- conf/default.conf.php | 6 ++++++ .../PhabricatorMailReplyHandler.php | 11 +++++++++-- .../metamta/storage/PhabricatorMetaMTAMail.php | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/conf/default.conf.php b/conf/default.conf.php index 29c7b716a3..52d8178b1b 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -266,6 +266,12 @@ return array( // sometimes referred to as "multiplexing". 'metamta.one-mail-per-recipient' => true, + // When sending a message that has no To recipient (i.e. all recipients + // are CC'd, for example when multiplexing mail), set the To field to the + // following value. If no value is set, messages with no To will have + // their CCs upgraded to To. + 'metamta.placeholder-to-recipient' => null, + // When a user takes an action which generates an email notification (like // commenting on a Differential revision), Phabricator can either send that // mail "From" the user's email address (like "alincoln@logcabin.com") or diff --git a/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php b/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php index 18a2640f3c..c15057e929 100644 --- a/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php +++ b/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php @@ -142,9 +142,16 @@ abstract class PhabricatorMailReplyHandler { $body .= "\n"; $body .= $this->getRecipientsSummary($to_handles, $cc_handles); - foreach ($recipients as $recipient) { + foreach ($recipients as $phid => $recipient) { $mail = clone $mail_template; - $mail->addTos(array($recipient->getPHID())); + if (isset($to_handles[$phid])) { + $mail->addTos(array($phid)); + } else if (isset($cc_handles[$phid])) { + $mail->addCCs(array($phid)); + } else { + // not good - they should be a to or a cc + continue; + } $mail->setBody($body); diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index c83b3c9f44..5dae327158 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -606,16 +606,22 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { } + $empty_to = + PhabricatorEnv::getEnvConfig('metamta.placeholder-to-recipient'); + if ($empty_to !== null && !$add_to) { + $mailer->addTos(array($empty_to)); + } if ($add_to) { $mailer->addTos($add_to); - if ($add_cc) { + } + if ($add_cc) { + if ($empty_to !== null) { $mailer->addCCs($add_cc); + } else { + $mailer->addTos($add_cc); } - } else if ($add_cc) { - // If we have CC addresses but no "to" address, promote the CCs to - // "to". - $mailer->addTos($add_cc); - } else { + } + if (!$add_to && !$add_cc) { $this->setStatus(self::STATUS_VOID); $this->setMessage( "Message has no valid recipients: all To/CC are disabled or ".