public function willSendMail(PhabricatorMetaMTAMail $mail) { $viewer = $this->getViewer(); $mail->addPHIDHeaders('X-Phabricator-To', $this->rawToPHIDs); $mail->addPHIDHeaders('X-Phabricator-Cc', $this->rawCCPHIDs); $to_handles = $viewer->loadHandles($this->rawToPHIDs); $cc_handles = $viewer->loadHandles($this->rawCCPHIDs); $body = $mail->getBody(); $body .= "\n"; $body .= $this->getRecipientsSummary($to_handles, $cc_handles); $mail->setBody($body); $html_body = $mail->getHTMLBody(); if (strlen($html_body)) { $html_body .= hsprintf('%s', $this->getRecipientsSummaryHTML($to_handles, $cc_handles)); } $mail->setHTMLBody($html_body); $reply_to = $this->getReplyTo(); if ($reply_to) { $mail->setReplyTo($reply_to); } $to = array_keys($this->getToMap()); if ($to) { $mail->addTos($to); } $cc = array_keys($this->getCCMap()); if ($cc) { $mail->addCCs($cc); } return $mail; }
public final function multiplexMail(PhabricatorMetaMTAMail $mail_template, array $to_handles, array $cc_handles) { assert_instances_of($to_handles, 'PhabricatorObjectHandle'); assert_instances_of($cc_handles, 'PhabricatorObjectHandle'); $result = array(); // If MetaMTA is configured to always multiplex, skip the single-email // case. if (!PhabricatorMetaMTAMail::shouldMultiplexAllMail()) { // If private replies are not supported, simply send one email to all // recipients and CCs. This covers cases where we have no reply handler, // or we have a public reply handler. if (!$this->supportsPrivateReplies()) { $mail = clone $mail_template; $mail->addTos(mpull($to_handles, 'getPHID')); $mail->addCCs(mpull($cc_handles, 'getPHID')); if ($this->supportsPublicReplies()) { $reply_to = $this->getPublicReplyHandlerEmailAddress(); $mail->setReplyTo($reply_to); } $result[] = $mail; return $result; } } // Merge all the recipients together. TODO: We could keep the CCs as real // CCs and send to a "*****@*****.**" type address, but keep it simple // for now. $recipients = mpull($to_handles, null, 'getPHID') + mpull($cc_handles, null, 'getPHID'); // When multiplexing mail, explicitly include To/Cc information in the // message body and headers. $add_headers = array(); $body = $mail_template->getBody(); $body .= "\n"; if ($to_handles) { $body .= "To: " . implode(', ', mpull($to_handles, 'getName')) . "\n"; $add_headers['X-Phabricator-To'] = $this->formatPHIDList($to_handles); } if ($cc_handles) { $body .= "Cc: " . implode(', ', mpull($cc_handles, 'getName')) . "\n"; $add_headers['X-Phabricator-Cc'] = $this->formatPHIDList($cc_handles); } foreach ($recipients as $recipient) { $mail = clone $mail_template; $mail->addTos(array($recipient->getPHID())); $mail->setBody($body); foreach ($add_headers as $header => $value) { $mail->addHeader($header, $value); } $reply_to = null; if (!$reply_to && $this->supportsPrivateReplies()) { $reply_to = $this->getPrivateReplyHandlerEmailAddress($recipient); } if (!$reply_to && $this->supportsPublicReplies()) { $reply_to = $this->getPublicReplyHandlerEmailAddress(); } if ($reply_to) { $mail->setReplyTo($reply_to); } $result[] = $mail; } return $result; }
public final function multiplexMail(PhabricatorMetaMTAMail $mail_template, array $to_handles, array $cc_handles) { $result = array(); // If private replies are not supported, simply send one email to all // recipients and CCs. This covers cases where we have no reply handler, // or we have a public reply handler. if (!$this->supportsPrivateReplies()) { $mail = clone $mail_template; $mail->addTos(mpull($to_handles, 'getPHID')); $mail->addCCs(mpull($cc_handles, 'getPHID')); if ($this->supportsPublicReplies()) { $reply_to = $this->getPublicReplyHandlerEmailAddress(); $mail->setReplyTo($reply_to); } $result[] = $mail; return $result; } // Merge all the recipients together. TODO: We could keep the CCs as real // CCs and send to a "*****@*****.**" type address, but keep it simple // for now. $recipients = mpull($to_handles, null, 'getPHID') + mpull($cc_handles, null, 'getPHID'); // This grouping is just so we can use the public reply-to for any // recipients without a private reply-to, e.g. mailing lists. $groups = array(); foreach ($recipients as $recipient) { $private = $this->getPrivateReplyHandlerEmailAddress($recipient); $groups[$private][] = $recipient; } // When multiplexing mail, explicitly include To/Cc information in the // message body and headers. $add_headers = array(); $body = $mail_template->getBody(); $body .= "\n"; if ($to_handles) { $body .= "To: " . implode(', ', mpull($to_handles, 'getName')) . "\n"; $add_headers['X-Phabricator-To'] = $this->formatPHIDList($to_handles); } if ($cc_handles) { $body .= "Cc: " . implode(', ', mpull($cc_handles, 'getName')) . "\n"; $add_headers['X-Phabricator-Cc'] = $this->formatPHIDList($cc_handles); } foreach ($groups as $reply_to => $group) { $mail = clone $mail_template; $mail->addTos(mpull($group, 'getPHID')); $mail->setBody($body); foreach ($add_headers as $header => $value) { $mail->addHeader($header, $value); } if (!$reply_to && $this->supportsPublicReplies()) { $reply_to = $this->getPublicReplyHandlerEmailAddress(); } if ($reply_to) { $mail->setReplyTo($reply_to); } $result[] = $mail; } return $result; }