3 final class PhabricatorMailTarget
extends Phobject
{
7 private $toMap = array();
8 private $ccMap = array();
12 public function setRawToPHIDs(array $to_phids) {
13 $this->rawToPHIDs
= $to_phids;
17 public function setRawCCPHIDs(array $cc_phids) {
18 $this->rawCCPHIDs
= $cc_phids;
22 public function setCCMap(array $cc_map) {
23 $this->ccMap
= $cc_map;
27 public function getCCMap() {
31 public function setToMap(array $to_map) {
32 $this->toMap
= $to_map;
36 public function getToMap() {
40 public function setReplyTo($reply_to) {
41 $this->replyTo
= $reply_to;
45 public function getReplyTo() {
46 return $this->replyTo
;
49 public function setViewer($viewer) {
50 $this->viewer
= $viewer;
54 public function getViewer() {
58 public function willSendMail(PhabricatorMetaMTAMail
$mail) {
59 $viewer = $this->getViewer();
61 $show_stamps = $mail->shouldRenderMailStampsInBody($viewer);
63 $body = $mail->getBody();
64 $html_body = $mail->getHTMLBody();
65 $has_html = (strlen($html_body) > 0);
68 $stamps = $mail->getMailStamps();
71 $body .= pht('STAMPS');
73 $body .= implode(' ', $stamps);
78 $html[] = phutil_tag('strong', array(), pht('STAMPS'));
79 $html[] = phutil_tag('br');
83 'style' => 'font-size: smaller; color: #92969D',
85 phutil_implode_html(' ', $stamps));
86 $html[] = phutil_tag('br');
87 $html[] = phutil_tag('br');
88 $html = phutil_tag('div', array(), $html);
89 $html_body .= hsprintf('%s', $html);
94 $mail->addPHIDHeaders('X-Phabricator-To', $this->rawToPHIDs
);
95 $mail->addPHIDHeaders('X-Phabricator-Cc', $this->rawCCPHIDs
);
97 $to_handles = $viewer->loadHandles($this->rawToPHIDs
);
98 $cc_handles = $viewer->loadHandles($this->rawCCPHIDs
);
101 $body .= $this->getRecipientsSummary($to_handles, $cc_handles);
104 $html_body .= hsprintf(
106 $this->getRecipientsSummaryHTML($to_handles, $cc_handles));
109 $mail->setBody($body);
110 $mail->setHTMLBody($html_body);
112 $reply_to = $this->getReplyTo();
114 $mail->setReplyTo($reply_to);
117 $to = array_keys($this->getToMap());
122 $cc = array_keys($this->getCCMap());
130 private function getRecipientsSummary(
131 PhabricatorHandleList
$to_handles,
132 PhabricatorHandleList
$cc_handles) {
134 if (!PhabricatorEnv
::getEnvConfig('metamta.recipients.show-hints')) {
138 $to_handles = iterator_to_array($to_handles);
139 $cc_handles = iterator_to_array($cc_handles);
144 $to_names = mpull($to_handles, 'getCommandLineObjectName');
145 $body .= "To: ".implode(', ', $to_names)."\n";
149 $cc_names = mpull($cc_handles, 'getCommandLineObjectName');
150 $body .= "Cc: ".implode(', ', $cc_names)."\n";
156 private function getRecipientsSummaryHTML(
157 PhabricatorHandleList
$to_handles,
158 PhabricatorHandleList
$cc_handles) {
160 if (!PhabricatorEnv
::getEnvConfig('metamta.recipients.show-hints')) {
164 $to_handles = iterator_to_array($to_handles);
165 $cc_handles = iterator_to_array($cc_handles);
169 $body[] = phutil_tag('strong', array(), 'To: ');
170 $body[] = phutil_implode_html(', ', mpull($to_handles, 'getName'));
171 $body[] = phutil_tag('br');
174 $body[] = phutil_tag('strong', array(), 'Cc: ');
175 $body[] = phutil_implode_html(', ', mpull($cc_handles, 'getName'));
176 $body[] = phutil_tag('br');
178 return phutil_tag('div', array(), $body);