1 | <?php |
||
39 | class Message implements IMessage { |
||
40 | /** @var Swift_Message */ |
||
41 | private $swiftMessage; |
||
42 | |||
43 | /** |
||
44 | * @param Swift_Message $swiftMessage |
||
45 | */ |
||
46 | public function __construct(Swift_Message $swiftMessage) { |
||
49 | |||
50 | /** |
||
51 | * @param IAttachment $attachment |
||
52 | * @return $this |
||
53 | * @since 13.0.0 |
||
54 | */ |
||
55 | public function attach(IAttachment $attachment): IMessage { |
||
60 | |||
61 | /** |
||
62 | * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
||
63 | * FIXME: Remove this once SwiftMailer supports IDN |
||
64 | * |
||
65 | * @param array $addresses Array of mail addresses, key will get converted |
||
66 | * @return array Converted addresses if `idn_to_ascii` exists |
||
67 | */ |
||
68 | protected function convertAddresses(array $addresses): array { |
||
69 | if (!function_exists('idn_to_ascii') || !defined('INTL_IDNA_VARIANT_UTS46')) { |
||
70 | return $addresses; |
||
71 | } |
||
72 | |||
73 | $convertedAddresses = []; |
||
74 | |||
75 | foreach($addresses as $email => $readableName) { |
||
76 | if(!is_numeric($email)) { |
||
77 | list($name, $domain) = explode('@', $email, 2); |
||
78 | $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
||
79 | $convertedAddresses[$name.'@'.$domain] = $readableName; |
||
80 | } else { |
||
81 | list($name, $domain) = explode('@', $readableName, 2); |
||
82 | $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
||
83 | $convertedAddresses[$email] = $name.'@'.$domain; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | return $convertedAddresses; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Set the from address of this message. |
||
92 | * |
||
93 | * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
||
94 | * |
||
95 | * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setFrom(array $addresses): IMessage { |
||
104 | |||
105 | /** |
||
106 | * Get the from address of this message. |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | public function getFrom(): array { |
||
113 | |||
114 | /** |
||
115 | * Set the Reply-To address of this message |
||
116 | * |
||
117 | * @param array $addresses |
||
118 | * @return $this |
||
119 | */ |
||
120 | public function setReplyTo(array $addresses): IMessage { |
||
126 | |||
127 | /** |
||
128 | * Returns the Reply-To address of this message |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getReplyTo(): string { |
||
135 | |||
136 | /** |
||
137 | * Set the to addresses of this message. |
||
138 | * |
||
139 | * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
||
140 | * @return $this |
||
141 | */ |
||
142 | public function setTo(array $recipients): IMessage { |
||
148 | |||
149 | /** |
||
150 | * Get the to address of this message. |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | public function getTo(): array { |
||
157 | |||
158 | /** |
||
159 | * Set the CC recipients of this message. |
||
160 | * |
||
161 | * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
||
162 | * @return $this |
||
163 | */ |
||
164 | public function setCc(array $recipients): IMessage { |
||
170 | |||
171 | /** |
||
172 | * Get the cc address of this message. |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | public function getCc(): array { |
||
179 | |||
180 | /** |
||
181 | * Set the BCC recipients of this message. |
||
182 | * |
||
183 | * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
||
184 | * @return $this |
||
185 | */ |
||
186 | public function setBcc(array $recipients): IMessage { |
||
192 | |||
193 | /** |
||
194 | * Get the Bcc address of this message. |
||
195 | * |
||
196 | * @return array |
||
197 | */ |
||
198 | public function getBcc(): array { |
||
201 | |||
202 | /** |
||
203 | * Set the subject of this message. |
||
204 | * |
||
205 | * @param string $subject |
||
206 | * @return IMessage |
||
207 | */ |
||
208 | public function setSubject(string $subject): IMessage { |
||
212 | |||
213 | /** |
||
214 | * Get the from subject of this message. |
||
215 | * |
||
216 | * @return string |
||
217 | */ |
||
218 | public function getSubject(): string { |
||
221 | |||
222 | /** |
||
223 | * Set the plain-text body of this message. |
||
224 | * |
||
225 | * @param string $body |
||
226 | * @return $this |
||
227 | */ |
||
228 | public function setPlainBody(string $body): IMessage { |
||
232 | |||
233 | /** |
||
234 | * Get the plain body of this message. |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | public function getPlainBody(): string { |
||
241 | |||
242 | /** |
||
243 | * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one. |
||
244 | * |
||
245 | * @param string $body |
||
246 | * @return $this |
||
247 | */ |
||
248 | public function setHtmlBody($body) { |
||
252 | |||
253 | /** |
||
254 | * Get's the underlying SwiftMessage |
||
255 | * @return Swift_Message |
||
256 | */ |
||
257 | public function getSwiftMessage(): Swift_Message { |
||
260 | |||
261 | /** |
||
262 | * @param string $body |
||
263 | * @param string $contentType |
||
264 | * @return $this |
||
265 | */ |
||
266 | public function setBody($body, $contentType) { |
||
270 | |||
271 | /** |
||
272 | * @param IEMailTemplate $emailTemplate |
||
273 | * @return $this |
||
274 | */ |
||
275 | public function useTemplate(IEMailTemplate $emailTemplate): IMessage { |
||
281 | } |
||
282 |