Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / metamta / replyhandler / PhabricatorMailTarget.php
blob4bd51051355a00c83e61d8ea8d8a7695725534ba
1 <?php
3 final class PhabricatorMailTarget extends Phobject {
5 private $viewer;
6 private $replyTo;
7 private $toMap = array();
8 private $ccMap = array();
9 private $rawToPHIDs;
10 private $rawCCPHIDs;
12 public function setRawToPHIDs(array $to_phids) {
13 $this->rawToPHIDs = $to_phids;
14 return $this;
17 public function setRawCCPHIDs(array $cc_phids) {
18 $this->rawCCPHIDs = $cc_phids;
19 return $this;
22 public function setCCMap(array $cc_map) {
23 $this->ccMap = $cc_map;
24 return $this;
27 public function getCCMap() {
28 return $this->ccMap;
31 public function setToMap(array $to_map) {
32 $this->toMap = $to_map;
33 return $this;
36 public function getToMap() {
37 return $this->toMap;
40 public function setReplyTo($reply_to) {
41 $this->replyTo = $reply_to;
42 return $this;
45 public function getReplyTo() {
46 return $this->replyTo;
49 public function setViewer($viewer) {
50 $this->viewer = $viewer;
51 return $this;
54 public function getViewer() {
55 return $this->viewer;
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);
67 if ($show_stamps) {
68 $stamps = $mail->getMailStamps();
69 if ($stamps) {
70 $body .= "\n";
71 $body .= pht('STAMPS');
72 $body .= "\n";
73 $body .= implode(' ', $stamps);
74 $body .= "\n";
76 if ($has_html) {
77 $html = array();
78 $html[] = phutil_tag('strong', array(), pht('STAMPS'));
79 $html[] = phutil_tag('br');
80 $html[] = phutil_tag(
81 'span',
82 array(
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);
100 $body .= "\n";
101 $body .= $this->getRecipientsSummary($to_handles, $cc_handles);
103 if ($has_html) {
104 $html_body .= hsprintf(
105 '%s',
106 $this->getRecipientsSummaryHTML($to_handles, $cc_handles));
109 $mail->setBody($body);
110 $mail->setHTMLBody($html_body);
112 $reply_to = $this->getReplyTo();
113 if ($reply_to) {
114 $mail->setReplyTo($reply_to);
117 $to = array_keys($this->getToMap());
118 if ($to) {
119 $mail->addTos($to);
122 $cc = array_keys($this->getCCMap());
123 if ($cc) {
124 $mail->addCCs($cc);
127 return $mail;
130 private function getRecipientsSummary(
131 PhabricatorHandleList $to_handles,
132 PhabricatorHandleList $cc_handles) {
134 if (!PhabricatorEnv::getEnvConfig('metamta.recipients.show-hints')) {
135 return '';
138 $to_handles = iterator_to_array($to_handles);
139 $cc_handles = iterator_to_array($cc_handles);
141 $body = '';
143 if ($to_handles) {
144 $to_names = mpull($to_handles, 'getCommandLineObjectName');
145 $body .= "To: ".implode(', ', $to_names)."\n";
148 if ($cc_handles) {
149 $cc_names = mpull($cc_handles, 'getCommandLineObjectName');
150 $body .= "Cc: ".implode(', ', $cc_names)."\n";
153 return $body;
156 private function getRecipientsSummaryHTML(
157 PhabricatorHandleList $to_handles,
158 PhabricatorHandleList $cc_handles) {
160 if (!PhabricatorEnv::getEnvConfig('metamta.recipients.show-hints')) {
161 return '';
164 $to_handles = iterator_to_array($to_handles);
165 $cc_handles = iterator_to_array($cc_handles);
167 $body = array();
168 if ($to_handles) {
169 $body[] = phutil_tag('strong', array(), 'To: ');
170 $body[] = phutil_implode_html(', ', mpull($to_handles, 'getName'));
171 $body[] = phutil_tag('br');
173 if ($cc_handles) {
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);