From 21ebd1a609e20780440e8402cb188a20580aa821 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 20 Aug 2012 14:08:45 -0700 Subject: [PATCH] Fix an issue with To/CC placeholders Summary: Currently, if no placeholder is configured we always move "Cc" up to "To", even if we have a valid "To". Instead, move "Cc" to "To" only if there's no "To" and no placeholder. Test Plan: Sent email with "to" and "cc", email with "cc" only with a placeholder, and email with "cc" only without a placeholder. Verified recipients ended up in the right location in all cases. Reviewers: nh, btrahan Reviewed By: btrahan CC: klimek, aran Differential Revision: https://secure.phabricator.com/D3342 --- .../storage/PhabricatorMetaMTAMail.php | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php index b78aa1e47b..f99fe17414 100644 --- a/src/applications/metamta/storage/PhabricatorMetaMTAMail.php +++ b/src/applications/metamta/storage/PhabricatorMetaMTAMail.php @@ -616,22 +616,6 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { $add_cc = array_diff_key($add_cc, $exclude); } - - $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 ($empty_to !== null) { - $mailer->addCCs($add_cc); - } else { - $mailer->addTos($add_cc); - } - } if (!$add_to && !$add_cc) { $this->setStatus(self::STATUS_VOID); $this->setMessage( @@ -640,6 +624,24 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO { return $this->save(); } + // Some mailers require a valid "To:" in order to deliver mail. If we + // don't have any "To:", try to fill it in with a placeholder "To:". + // If that also fails, move the "Cc:" line to "To:". + if (!$add_to) { + $placeholder_key = 'metamta.placeholder-to-recipient'; + $placeholder = PhabricatorEnv::getEnvConfig($placeholder_key); + if ($placeholder !== null) { + $add_to = array($placeholder); + } else { + $add_to = $add_cc; + $add_cc = array(); + } + } + + $mailer->addTos($add_to); + if ($add_cc) { + $mailer->addCCs($add_cc); + } } catch (Exception $ex) { $this->setStatus(self::STATUS_FAIL); $this->setMessage($ex->getMessage());