Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/replyhandler/PhabricatorMailTarget.php
12256 views
1
<?php
2
3
final class PhabricatorMailTarget extends Phobject {
4
5
private $viewer;
6
private $replyTo;
7
private $toMap = array();
8
private $ccMap = array();
9
private $rawToPHIDs;
10
private $rawCCPHIDs;
11
12
public function setRawToPHIDs(array $to_phids) {
13
$this->rawToPHIDs = $to_phids;
14
return $this;
15
}
16
17
public function setRawCCPHIDs(array $cc_phids) {
18
$this->rawCCPHIDs = $cc_phids;
19
return $this;
20
}
21
22
public function setCCMap(array $cc_map) {
23
$this->ccMap = $cc_map;
24
return $this;
25
}
26
27
public function getCCMap() {
28
return $this->ccMap;
29
}
30
31
public function setToMap(array $to_map) {
32
$this->toMap = $to_map;
33
return $this;
34
}
35
36
public function getToMap() {
37
return $this->toMap;
38
}
39
40
public function setReplyTo($reply_to) {
41
$this->replyTo = $reply_to;
42
return $this;
43
}
44
45
public function getReplyTo() {
46
return $this->replyTo;
47
}
48
49
public function setViewer($viewer) {
50
$this->viewer = $viewer;
51
return $this;
52
}
53
54
public function getViewer() {
55
return $this->viewer;
56
}
57
58
public function willSendMail(PhabricatorMetaMTAMail $mail) {
59
$viewer = $this->getViewer();
60
61
$show_stamps = $mail->shouldRenderMailStampsInBody($viewer);
62
63
$body = $mail->getBody();
64
$html_body = $mail->getHTMLBody();
65
$has_html = (strlen($html_body) > 0);
66
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";
75
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',
84
),
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);
90
}
91
}
92
}
93
94
$mail->addPHIDHeaders('X-Phabricator-To', $this->rawToPHIDs);
95
$mail->addPHIDHeaders('X-Phabricator-Cc', $this->rawCCPHIDs);
96
97
$to_handles = $viewer->loadHandles($this->rawToPHIDs);
98
$cc_handles = $viewer->loadHandles($this->rawCCPHIDs);
99
100
$body .= "\n";
101
$body .= $this->getRecipientsSummary($to_handles, $cc_handles);
102
103
if ($has_html) {
104
$html_body .= hsprintf(
105
'%s',
106
$this->getRecipientsSummaryHTML($to_handles, $cc_handles));
107
}
108
109
$mail->setBody($body);
110
$mail->setHTMLBody($html_body);
111
112
$reply_to = $this->getReplyTo();
113
if ($reply_to) {
114
$mail->setReplyTo($reply_to);
115
}
116
117
$to = array_keys($this->getToMap());
118
if ($to) {
119
$mail->addTos($to);
120
}
121
122
$cc = array_keys($this->getCCMap());
123
if ($cc) {
124
$mail->addCCs($cc);
125
}
126
127
return $mail;
128
}
129
130
private function getRecipientsSummary(
131
PhabricatorHandleList $to_handles,
132
PhabricatorHandleList $cc_handles) {
133
134
if (!PhabricatorEnv::getEnvConfig('metamta.recipients.show-hints')) {
135
return '';
136
}
137
138
$to_handles = iterator_to_array($to_handles);
139
$cc_handles = iterator_to_array($cc_handles);
140
141
$body = '';
142
143
if ($to_handles) {
144
$to_names = mpull($to_handles, 'getCommandLineObjectName');
145
$body .= "To: ".implode(', ', $to_names)."\n";
146
}
147
148
if ($cc_handles) {
149
$cc_names = mpull($cc_handles, 'getCommandLineObjectName');
150
$body .= "Cc: ".implode(', ', $cc_names)."\n";
151
}
152
153
return $body;
154
}
155
156
private function getRecipientsSummaryHTML(
157
PhabricatorHandleList $to_handles,
158
PhabricatorHandleList $cc_handles) {
159
160
if (!PhabricatorEnv::getEnvConfig('metamta.recipients.show-hints')) {
161
return '';
162
}
163
164
$to_handles = iterator_to_array($to_handles);
165
$cc_handles = iterator_to_array($cc_handles);
166
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');
172
}
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');
177
}
178
return phutil_tag('div', array(), $body);
179
}
180
181
182
}
183
184