@@ -46,302 +46,302 @@ |
||
| 46 | 46 | * @package OC\Mail |
| 47 | 47 | */ |
| 48 | 48 | class Message implements IMessage { |
| 49 | - private Email $symfonyEmail; |
|
| 50 | - private bool $plainTextOnly; |
|
| 51 | - |
|
| 52 | - private array $to; |
|
| 53 | - private array $from; |
|
| 54 | - private array $replyTo; |
|
| 55 | - private array $cc; |
|
| 56 | - private array $bcc; |
|
| 57 | - |
|
| 58 | - public function __construct(Email $symfonyEmail, bool $plainTextOnly) { |
|
| 59 | - $this->symfonyEmail = $symfonyEmail; |
|
| 60 | - $this->plainTextOnly = $plainTextOnly; |
|
| 61 | - $this->to = []; |
|
| 62 | - $this->from = []; |
|
| 63 | - $this->replyTo = []; |
|
| 64 | - $this->cc = []; |
|
| 65 | - $this->bcc = []; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return $this |
|
| 70 | - * @since 13.0.0 |
|
| 71 | - */ |
|
| 72 | - public function attach(IAttachment $attachment): IMessage { |
|
| 73 | - /** @var Attachment $attachment */ |
|
| 74 | - $attachment->attach($this->symfonyEmail); |
|
| 75 | - return $this; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Can be used to "attach content inline" as message parts with specific MIME type and encoding. |
|
| 80 | - * {@inheritDoc} |
|
| 81 | - * @since 26.0.0 |
|
| 82 | - */ |
|
| 83 | - public function attachInline(string $body, string $name, string $contentType = null): IMessage { |
|
| 84 | - # To be sure this works with iCalendar messages, we encode with 8bit instead of |
|
| 85 | - # quoted-printable encoding. We save the current encoder, replace the current |
|
| 86 | - # encoder with an 8bit encoder and after we've finished, we reset the encoder |
|
| 87 | - # to the previous one. Originally intended to be added after the message body, |
|
| 88 | - # as it is curently unknown if all mail clients handle this properly if added |
|
| 89 | - # before. |
|
| 90 | - $this->symfonyEmail->embed($body, $name, $contentType); |
|
| 91 | - return $this; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Converts the [['displayName' => 'email'], ['displayName2' => 'email2']] arrays to valid Adresses |
|
| 96 | - * |
|
| 97 | - * @param array $addresses Array of mail addresses |
|
| 98 | - * @return Address[] |
|
| 99 | - * @throws RfcComplianceException|InvalidArgumentException |
|
| 100 | - */ |
|
| 101 | - protected function convertAddresses(array $addresses): array { |
|
| 102 | - $convertedAddresses = []; |
|
| 103 | - |
|
| 104 | - if (empty($addresses)) { |
|
| 105 | - return []; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - array_walk($addresses, function ($readableName, $email) use (&$convertedAddresses) { |
|
| 109 | - if (is_numeric($email)) { |
|
| 110 | - $convertedAddresses[] = new Address($readableName); |
|
| 111 | - } else { |
|
| 112 | - $convertedAddresses[] = new Address($email, $readableName); |
|
| 113 | - } |
|
| 114 | - }); |
|
| 115 | - |
|
| 116 | - return $convertedAddresses; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Set the from address of this message. |
|
| 121 | - * |
|
| 122 | - * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 123 | - * |
|
| 124 | - * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 125 | - * @return $this |
|
| 126 | - */ |
|
| 127 | - public function setFrom(array $addresses): IMessage { |
|
| 128 | - $this->from = $addresses; |
|
| 129 | - return $this; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Get the from address of this message. |
|
| 134 | - */ |
|
| 135 | - public function getFrom(): array { |
|
| 136 | - return $this->from; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Set the Reply-To address of this message |
|
| 141 | - * |
|
| 142 | - * @return $this |
|
| 143 | - */ |
|
| 144 | - public function setReplyTo(array $addresses): IMessage { |
|
| 145 | - $this->replyTo = $addresses; |
|
| 146 | - return $this; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Returns the Reply-To address of this message |
|
| 151 | - */ |
|
| 152 | - public function getReplyTo(): array { |
|
| 153 | - return $this->replyTo; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Set the to addresses of this message. |
|
| 158 | - * |
|
| 159 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 160 | - * @return $this |
|
| 161 | - */ |
|
| 162 | - public function setTo(array $recipients): IMessage { |
|
| 163 | - $this->to = $recipients; |
|
| 164 | - return $this; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Get the to address of this message. |
|
| 169 | - */ |
|
| 170 | - public function getTo(): array { |
|
| 171 | - return $this->to; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Set the CC recipients of this message. |
|
| 176 | - * |
|
| 177 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 178 | - * @return $this |
|
| 179 | - */ |
|
| 180 | - public function setCc(array $recipients): IMessage { |
|
| 181 | - $this->cc = $recipients; |
|
| 182 | - return $this; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Get the cc address of this message. |
|
| 187 | - */ |
|
| 188 | - public function getCc(): array { |
|
| 189 | - return $this->cc; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Set the BCC recipients of this message. |
|
| 194 | - * |
|
| 195 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 196 | - * @return $this |
|
| 197 | - */ |
|
| 198 | - public function setBcc(array $recipients): IMessage { |
|
| 199 | - $this->bcc = $recipients; |
|
| 200 | - return $this; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Get the Bcc address of this message. |
|
| 205 | - */ |
|
| 206 | - public function getBcc(): array { |
|
| 207 | - return $this->bcc; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - public function setSubject(string $subject): IMessage { |
|
| 211 | - $this->symfonyEmail->subject($subject); |
|
| 212 | - return $this; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Get the from subject of this message. |
|
| 217 | - */ |
|
| 218 | - public function getSubject(): string { |
|
| 219 | - return $this->symfonyEmail->getSubject() ?? ''; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - public function setPlainBody(string $body): IMessage { |
|
| 223 | - $this->symfonyEmail->text($body); |
|
| 224 | - return $this; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Get the plain body of this message. |
|
| 229 | - */ |
|
| 230 | - public function getPlainBody(): string { |
|
| 231 | - /** @var string $body */ |
|
| 232 | - $body = $this->symfonyEmail->getTextBody() ?? ''; |
|
| 233 | - return $body; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - public function setHtmlBody(string $body): IMessage { |
|
| 237 | - if (!$this->plainTextOnly) { |
|
| 238 | - $this->symfonyEmail->html($body); |
|
| 239 | - } |
|
| 240 | - return $this; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Set the underlying Email intance |
|
| 245 | - */ |
|
| 246 | - public function setSymfonyEmail(Email $symfonyEmail): void { |
|
| 247 | - $this->symfonyEmail = $symfonyEmail; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * Get the underlying Email instance |
|
| 252 | - */ |
|
| 253 | - public function getSymfonyEmail(): Email { |
|
| 254 | - return $this->symfonyEmail; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @return $this |
|
| 259 | - */ |
|
| 260 | - public function setBody(string $body, string $contentType): IMessage { |
|
| 261 | - if (!$this->plainTextOnly || $contentType !== 'text/html') { |
|
| 262 | - if ($contentType === 'text/html') { |
|
| 263 | - $this->symfonyEmail->html($body); |
|
| 264 | - } else { |
|
| 265 | - $this->symfonyEmail->text($body); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - return $this; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Set the recipients on the symphony email |
|
| 273 | - * |
|
| 274 | - * Since |
|
| 275 | - * |
|
| 276 | - * setTo |
|
| 277 | - * setFrom |
|
| 278 | - * setReplyTo |
|
| 279 | - * setCc |
|
| 280 | - * setBcc |
|
| 281 | - * |
|
| 282 | - * could throw a \Symfony\Component\Mime\Exception\RfcComplianceException |
|
| 283 | - * or a \Symfony\Component\Mime\Exception\InvalidArgumentException |
|
| 284 | - * we wrap the calls here. We then have the validation errors all in one place and can |
|
| 285 | - * throw shortly before \OC\Mail\Mailer::send |
|
| 286 | - * |
|
| 287 | - * @return void |
|
| 288 | - * @throws InvalidArgumentException|RfcComplianceException |
|
| 289 | - */ |
|
| 290 | - public function setRecipients() { |
|
| 291 | - $this->symfonyEmail->to(...$this->convertAddresses($this->getTo())); |
|
| 292 | - $this->symfonyEmail->from(...$this->convertAddresses($this->getFrom())); |
|
| 293 | - $this->symfonyEmail->replyTo(...$this->convertAddresses($this->getReplyTo())); |
|
| 294 | - $this->symfonyEmail->cc(...$this->convertAddresses($this->getCc())); |
|
| 295 | - $this->symfonyEmail->bcc(...$this->convertAddresses($this->getBcc())); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @return $this |
|
| 300 | - */ |
|
| 301 | - public function useTemplate(IEMailTemplate $emailTemplate): IMessage { |
|
| 302 | - $this->setSubject($emailTemplate->renderSubject()); |
|
| 303 | - $this->setPlainBody($emailTemplate->renderText()); |
|
| 304 | - if (!$this->plainTextOnly) { |
|
| 305 | - $this->setHtmlBody($emailTemplate->renderHtml()); |
|
| 306 | - } |
|
| 307 | - return $this; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Add the Auto-Submitted header to the email, preventing most automated |
|
| 312 | - * responses to automated messages. |
|
| 313 | - * |
|
| 314 | - * @param AutoSubmitted::VALUE_* $value (one of AutoSubmitted::VALUE_NO, AutoSubmitted::VALUE_AUTO_GENERATED, AutoSubmitted::VALUE_AUTO_REPLIED) |
|
| 315 | - * @return $this |
|
| 316 | - */ |
|
| 317 | - public function setAutoSubmitted(string $value): IMessage { |
|
| 318 | - $headers = $this->symfonyEmail->getHeaders(); |
|
| 319 | - |
|
| 320 | - if ($headers->has(AutoSubmitted::HEADER)) { |
|
| 321 | - // if the header already exsists, remove it. |
|
| 322 | - // the value can be modified with some implementations |
|
| 323 | - // of the interface \Swift_Mime_Header, however the |
|
| 324 | - // interface doesn't, and this makes the static-code |
|
| 325 | - // analysis unhappy. |
|
| 326 | - // @todo check if symfony mailer can modify the autosubmitted header |
|
| 327 | - $headers->remove(AutoSubmitted::HEADER); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - $headers->addTextHeader(AutoSubmitted::HEADER, $value); |
|
| 331 | - |
|
| 332 | - return $this; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Get the current value of the Auto-Submitted header. Defaults to "no" |
|
| 337 | - * which is equivalent to the header not existing at all |
|
| 338 | - * |
|
| 339 | - * @return string |
|
| 340 | - */ |
|
| 341 | - public function getAutoSubmitted(): string { |
|
| 342 | - $headers = $this->symfonyEmail->getHeaders(); |
|
| 343 | - |
|
| 344 | - return $headers->has(AutoSubmitted::HEADER) ? |
|
| 345 | - $headers->get(AutoSubmitted::HEADER)->getBodyAsString() : AutoSubmitted::VALUE_NO; |
|
| 346 | - } |
|
| 49 | + private Email $symfonyEmail; |
|
| 50 | + private bool $plainTextOnly; |
|
| 51 | + |
|
| 52 | + private array $to; |
|
| 53 | + private array $from; |
|
| 54 | + private array $replyTo; |
|
| 55 | + private array $cc; |
|
| 56 | + private array $bcc; |
|
| 57 | + |
|
| 58 | + public function __construct(Email $symfonyEmail, bool $plainTextOnly) { |
|
| 59 | + $this->symfonyEmail = $symfonyEmail; |
|
| 60 | + $this->plainTextOnly = $plainTextOnly; |
|
| 61 | + $this->to = []; |
|
| 62 | + $this->from = []; |
|
| 63 | + $this->replyTo = []; |
|
| 64 | + $this->cc = []; |
|
| 65 | + $this->bcc = []; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return $this |
|
| 70 | + * @since 13.0.0 |
|
| 71 | + */ |
|
| 72 | + public function attach(IAttachment $attachment): IMessage { |
|
| 73 | + /** @var Attachment $attachment */ |
|
| 74 | + $attachment->attach($this->symfonyEmail); |
|
| 75 | + return $this; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Can be used to "attach content inline" as message parts with specific MIME type and encoding. |
|
| 80 | + * {@inheritDoc} |
|
| 81 | + * @since 26.0.0 |
|
| 82 | + */ |
|
| 83 | + public function attachInline(string $body, string $name, string $contentType = null): IMessage { |
|
| 84 | + # To be sure this works with iCalendar messages, we encode with 8bit instead of |
|
| 85 | + # quoted-printable encoding. We save the current encoder, replace the current |
|
| 86 | + # encoder with an 8bit encoder and after we've finished, we reset the encoder |
|
| 87 | + # to the previous one. Originally intended to be added after the message body, |
|
| 88 | + # as it is curently unknown if all mail clients handle this properly if added |
|
| 89 | + # before. |
|
| 90 | + $this->symfonyEmail->embed($body, $name, $contentType); |
|
| 91 | + return $this; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Converts the [['displayName' => 'email'], ['displayName2' => 'email2']] arrays to valid Adresses |
|
| 96 | + * |
|
| 97 | + * @param array $addresses Array of mail addresses |
|
| 98 | + * @return Address[] |
|
| 99 | + * @throws RfcComplianceException|InvalidArgumentException |
|
| 100 | + */ |
|
| 101 | + protected function convertAddresses(array $addresses): array { |
|
| 102 | + $convertedAddresses = []; |
|
| 103 | + |
|
| 104 | + if (empty($addresses)) { |
|
| 105 | + return []; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + array_walk($addresses, function ($readableName, $email) use (&$convertedAddresses) { |
|
| 109 | + if (is_numeric($email)) { |
|
| 110 | + $convertedAddresses[] = new Address($readableName); |
|
| 111 | + } else { |
|
| 112 | + $convertedAddresses[] = new Address($email, $readableName); |
|
| 113 | + } |
|
| 114 | + }); |
|
| 115 | + |
|
| 116 | + return $convertedAddresses; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Set the from address of this message. |
|
| 121 | + * |
|
| 122 | + * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 123 | + * |
|
| 124 | + * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 125 | + * @return $this |
|
| 126 | + */ |
|
| 127 | + public function setFrom(array $addresses): IMessage { |
|
| 128 | + $this->from = $addresses; |
|
| 129 | + return $this; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Get the from address of this message. |
|
| 134 | + */ |
|
| 135 | + public function getFrom(): array { |
|
| 136 | + return $this->from; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Set the Reply-To address of this message |
|
| 141 | + * |
|
| 142 | + * @return $this |
|
| 143 | + */ |
|
| 144 | + public function setReplyTo(array $addresses): IMessage { |
|
| 145 | + $this->replyTo = $addresses; |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Returns the Reply-To address of this message |
|
| 151 | + */ |
|
| 152 | + public function getReplyTo(): array { |
|
| 153 | + return $this->replyTo; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Set the to addresses of this message. |
|
| 158 | + * |
|
| 159 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 160 | + * @return $this |
|
| 161 | + */ |
|
| 162 | + public function setTo(array $recipients): IMessage { |
|
| 163 | + $this->to = $recipients; |
|
| 164 | + return $this; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Get the to address of this message. |
|
| 169 | + */ |
|
| 170 | + public function getTo(): array { |
|
| 171 | + return $this->to; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Set the CC recipients of this message. |
|
| 176 | + * |
|
| 177 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 178 | + * @return $this |
|
| 179 | + */ |
|
| 180 | + public function setCc(array $recipients): IMessage { |
|
| 181 | + $this->cc = $recipients; |
|
| 182 | + return $this; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Get the cc address of this message. |
|
| 187 | + */ |
|
| 188 | + public function getCc(): array { |
|
| 189 | + return $this->cc; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Set the BCC recipients of this message. |
|
| 194 | + * |
|
| 195 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 196 | + * @return $this |
|
| 197 | + */ |
|
| 198 | + public function setBcc(array $recipients): IMessage { |
|
| 199 | + $this->bcc = $recipients; |
|
| 200 | + return $this; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Get the Bcc address of this message. |
|
| 205 | + */ |
|
| 206 | + public function getBcc(): array { |
|
| 207 | + return $this->bcc; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + public function setSubject(string $subject): IMessage { |
|
| 211 | + $this->symfonyEmail->subject($subject); |
|
| 212 | + return $this; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Get the from subject of this message. |
|
| 217 | + */ |
|
| 218 | + public function getSubject(): string { |
|
| 219 | + return $this->symfonyEmail->getSubject() ?? ''; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + public function setPlainBody(string $body): IMessage { |
|
| 223 | + $this->symfonyEmail->text($body); |
|
| 224 | + return $this; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Get the plain body of this message. |
|
| 229 | + */ |
|
| 230 | + public function getPlainBody(): string { |
|
| 231 | + /** @var string $body */ |
|
| 232 | + $body = $this->symfonyEmail->getTextBody() ?? ''; |
|
| 233 | + return $body; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + public function setHtmlBody(string $body): IMessage { |
|
| 237 | + if (!$this->plainTextOnly) { |
|
| 238 | + $this->symfonyEmail->html($body); |
|
| 239 | + } |
|
| 240 | + return $this; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Set the underlying Email intance |
|
| 245 | + */ |
|
| 246 | + public function setSymfonyEmail(Email $symfonyEmail): void { |
|
| 247 | + $this->symfonyEmail = $symfonyEmail; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * Get the underlying Email instance |
|
| 252 | + */ |
|
| 253 | + public function getSymfonyEmail(): Email { |
|
| 254 | + return $this->symfonyEmail; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @return $this |
|
| 259 | + */ |
|
| 260 | + public function setBody(string $body, string $contentType): IMessage { |
|
| 261 | + if (!$this->plainTextOnly || $contentType !== 'text/html') { |
|
| 262 | + if ($contentType === 'text/html') { |
|
| 263 | + $this->symfonyEmail->html($body); |
|
| 264 | + } else { |
|
| 265 | + $this->symfonyEmail->text($body); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + return $this; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Set the recipients on the symphony email |
|
| 273 | + * |
|
| 274 | + * Since |
|
| 275 | + * |
|
| 276 | + * setTo |
|
| 277 | + * setFrom |
|
| 278 | + * setReplyTo |
|
| 279 | + * setCc |
|
| 280 | + * setBcc |
|
| 281 | + * |
|
| 282 | + * could throw a \Symfony\Component\Mime\Exception\RfcComplianceException |
|
| 283 | + * or a \Symfony\Component\Mime\Exception\InvalidArgumentException |
|
| 284 | + * we wrap the calls here. We then have the validation errors all in one place and can |
|
| 285 | + * throw shortly before \OC\Mail\Mailer::send |
|
| 286 | + * |
|
| 287 | + * @return void |
|
| 288 | + * @throws InvalidArgumentException|RfcComplianceException |
|
| 289 | + */ |
|
| 290 | + public function setRecipients() { |
|
| 291 | + $this->symfonyEmail->to(...$this->convertAddresses($this->getTo())); |
|
| 292 | + $this->symfonyEmail->from(...$this->convertAddresses($this->getFrom())); |
|
| 293 | + $this->symfonyEmail->replyTo(...$this->convertAddresses($this->getReplyTo())); |
|
| 294 | + $this->symfonyEmail->cc(...$this->convertAddresses($this->getCc())); |
|
| 295 | + $this->symfonyEmail->bcc(...$this->convertAddresses($this->getBcc())); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @return $this |
|
| 300 | + */ |
|
| 301 | + public function useTemplate(IEMailTemplate $emailTemplate): IMessage { |
|
| 302 | + $this->setSubject($emailTemplate->renderSubject()); |
|
| 303 | + $this->setPlainBody($emailTemplate->renderText()); |
|
| 304 | + if (!$this->plainTextOnly) { |
|
| 305 | + $this->setHtmlBody($emailTemplate->renderHtml()); |
|
| 306 | + } |
|
| 307 | + return $this; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Add the Auto-Submitted header to the email, preventing most automated |
|
| 312 | + * responses to automated messages. |
|
| 313 | + * |
|
| 314 | + * @param AutoSubmitted::VALUE_* $value (one of AutoSubmitted::VALUE_NO, AutoSubmitted::VALUE_AUTO_GENERATED, AutoSubmitted::VALUE_AUTO_REPLIED) |
|
| 315 | + * @return $this |
|
| 316 | + */ |
|
| 317 | + public function setAutoSubmitted(string $value): IMessage { |
|
| 318 | + $headers = $this->symfonyEmail->getHeaders(); |
|
| 319 | + |
|
| 320 | + if ($headers->has(AutoSubmitted::HEADER)) { |
|
| 321 | + // if the header already exsists, remove it. |
|
| 322 | + // the value can be modified with some implementations |
|
| 323 | + // of the interface \Swift_Mime_Header, however the |
|
| 324 | + // interface doesn't, and this makes the static-code |
|
| 325 | + // analysis unhappy. |
|
| 326 | + // @todo check if symfony mailer can modify the autosubmitted header |
|
| 327 | + $headers->remove(AutoSubmitted::HEADER); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + $headers->addTextHeader(AutoSubmitted::HEADER, $value); |
|
| 331 | + |
|
| 332 | + return $this; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Get the current value of the Auto-Submitted header. Defaults to "no" |
|
| 337 | + * which is equivalent to the header not existing at all |
|
| 338 | + * |
|
| 339 | + * @return string |
|
| 340 | + */ |
|
| 341 | + public function getAutoSubmitted(): string { |
|
| 342 | + $headers = $this->symfonyEmail->getHeaders(); |
|
| 343 | + |
|
| 344 | + return $headers->has(AutoSubmitted::HEADER) ? |
|
| 345 | + $headers->get(AutoSubmitted::HEADER)->getBodyAsString() : AutoSubmitted::VALUE_NO; |
|
| 346 | + } |
|
| 347 | 347 | } |
@@ -32,116 +32,116 @@ |
||
| 32 | 32 | * @since 13.0.0 |
| 33 | 33 | */ |
| 34 | 34 | interface IMessage { |
| 35 | - /** |
|
| 36 | - * Set the subject of this message |
|
| 37 | - * |
|
| 38 | - * @param string $subject |
|
| 39 | - * |
|
| 40 | - * @return self |
|
| 41 | - * @since 28.0.0 |
|
| 42 | - */ |
|
| 43 | - public function setSubject(string $subject): IMessage; |
|
| 35 | + /** |
|
| 36 | + * Set the subject of this message |
|
| 37 | + * |
|
| 38 | + * @param string $subject |
|
| 39 | + * |
|
| 40 | + * @return self |
|
| 41 | + * @since 28.0.0 |
|
| 42 | + */ |
|
| 43 | + public function setSubject(string $subject): IMessage; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Set the plain-text body of this message |
|
| 47 | - * |
|
| 48 | - * @param string $body |
|
| 49 | - * |
|
| 50 | - * @return self |
|
| 51 | - * @since 28.0.0 |
|
| 52 | - */ |
|
| 53 | - public function setPlainBody(string $body): IMessage; |
|
| 45 | + /** |
|
| 46 | + * Set the plain-text body of this message |
|
| 47 | + * |
|
| 48 | + * @param string $body |
|
| 49 | + * |
|
| 50 | + * @return self |
|
| 51 | + * @since 28.0.0 |
|
| 52 | + */ |
|
| 53 | + public function setPlainBody(string $body): IMessage; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one. |
|
| 57 | - * |
|
| 58 | - * @param string $body |
|
| 59 | - * |
|
| 60 | - * @return self |
|
| 61 | - * @since 28.0.0 |
|
| 62 | - */ |
|
| 63 | - public function setHtmlBody(string $body): IMessage; |
|
| 55 | + /** |
|
| 56 | + * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one. |
|
| 57 | + * |
|
| 58 | + * @param string $body |
|
| 59 | + * |
|
| 60 | + * @return self |
|
| 61 | + * @since 28.0.0 |
|
| 62 | + */ |
|
| 63 | + public function setHtmlBody(string $body): IMessage; |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param IAttachment $attachment |
|
| 67 | - * @return IMessage |
|
| 68 | - * @since 13.0.0 |
|
| 69 | - */ |
|
| 70 | - public function attach(IAttachment $attachment): IMessage; |
|
| 65 | + /** |
|
| 66 | + * @param IAttachment $attachment |
|
| 67 | + * @return IMessage |
|
| 68 | + * @since 13.0.0 |
|
| 69 | + */ |
|
| 70 | + public function attach(IAttachment $attachment): IMessage; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Can be used to "attach content inline" as message parts with specific MIME type and encoding. |
|
| 74 | - * |
|
| 75 | - * @param string $body body of the MIME part |
|
| 76 | - * @param string $name the file name |
|
| 77 | - * @param string|null $contentType MIME Content-Type (e.g. text/plain or text/calendar) |
|
| 78 | - * |
|
| 79 | - * @return IMessage |
|
| 80 | - * @since 27.0.0 |
|
| 81 | - */ |
|
| 82 | - public function attachInline(string $body, string $name, string $contentType = null): IMessage; |
|
| 72 | + /** |
|
| 73 | + * Can be used to "attach content inline" as message parts with specific MIME type and encoding. |
|
| 74 | + * |
|
| 75 | + * @param string $body body of the MIME part |
|
| 76 | + * @param string $name the file name |
|
| 77 | + * @param string|null $contentType MIME Content-Type (e.g. text/plain or text/calendar) |
|
| 78 | + * |
|
| 79 | + * @return IMessage |
|
| 80 | + * @since 27.0.0 |
|
| 81 | + */ |
|
| 82 | + public function attachInline(string $body, string $name, string $contentType = null): IMessage; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Set the from address of this message. |
|
| 86 | - * |
|
| 87 | - * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 88 | - * |
|
| 89 | - * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 90 | - * @return IMessage |
|
| 91 | - * @since 13.0.0 |
|
| 92 | - */ |
|
| 93 | - public function setFrom(array $addresses): IMessage; |
|
| 84 | + /** |
|
| 85 | + * Set the from address of this message. |
|
| 86 | + * |
|
| 87 | + * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 88 | + * |
|
| 89 | + * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 90 | + * @return IMessage |
|
| 91 | + * @since 13.0.0 |
|
| 92 | + */ |
|
| 93 | + public function setFrom(array $addresses): IMessage; |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Set the Reply-To address of this message |
|
| 97 | - * |
|
| 98 | - * @param array $addresses |
|
| 99 | - * @return IMessage |
|
| 100 | - * @since 13.0.0 |
|
| 101 | - */ |
|
| 102 | - public function setReplyTo(array $addresses): IMessage; |
|
| 95 | + /** |
|
| 96 | + * Set the Reply-To address of this message |
|
| 97 | + * |
|
| 98 | + * @param array $addresses |
|
| 99 | + * @return IMessage |
|
| 100 | + * @since 13.0.0 |
|
| 101 | + */ |
|
| 102 | + public function setReplyTo(array $addresses): IMessage; |
|
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * Set the to addresses of this message. |
|
| 106 | - * |
|
| 107 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 108 | - * @return IMessage |
|
| 109 | - * @since 13.0.0 |
|
| 110 | - */ |
|
| 111 | - public function setTo(array $recipients): IMessage; |
|
| 104 | + /** |
|
| 105 | + * Set the to addresses of this message. |
|
| 106 | + * |
|
| 107 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 108 | + * @return IMessage |
|
| 109 | + * @since 13.0.0 |
|
| 110 | + */ |
|
| 111 | + public function setTo(array $recipients): IMessage; |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Set the CC recipients of this message. |
|
| 115 | - * |
|
| 116 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 117 | - * @return IMessage |
|
| 118 | - * @since 13.0.0 |
|
| 119 | - */ |
|
| 120 | - public function setCc(array $recipients): IMessage; |
|
| 113 | + /** |
|
| 114 | + * Set the CC recipients of this message. |
|
| 115 | + * |
|
| 116 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 117 | + * @return IMessage |
|
| 118 | + * @since 13.0.0 |
|
| 119 | + */ |
|
| 120 | + public function setCc(array $recipients): IMessage; |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Set the BCC recipients of this message. |
|
| 124 | - * |
|
| 125 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 126 | - * @return IMessage |
|
| 127 | - * @since 13.0.0 |
|
| 128 | - */ |
|
| 129 | - public function setBcc(array $recipients): IMessage; |
|
| 122 | + /** |
|
| 123 | + * Set the BCC recipients of this message. |
|
| 124 | + * |
|
| 125 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 126 | + * @return IMessage |
|
| 127 | + * @since 13.0.0 |
|
| 128 | + */ |
|
| 129 | + public function setBcc(array $recipients): IMessage; |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * @param IEMailTemplate $emailTemplate |
|
| 133 | - * @return IMessage |
|
| 134 | - * @since 13.0.0 |
|
| 135 | - */ |
|
| 136 | - public function useTemplate(IEMailTemplate $emailTemplate): IMessage; |
|
| 131 | + /** |
|
| 132 | + * @param IEMailTemplate $emailTemplate |
|
| 133 | + * @return IMessage |
|
| 134 | + * @since 13.0.0 |
|
| 135 | + */ |
|
| 136 | + public function useTemplate(IEMailTemplate $emailTemplate): IMessage; |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * Add the Auto-Submitted header to the email, preventing most automated |
|
| 140 | - * responses to automated messages. |
|
| 141 | - * |
|
| 142 | - * @param Headers\AutoSubmitted::VALUE_* $value (one of AutoSubmitted::VALUE_NO, AutoSubmitted::VALUE_AUTO_GENERATED, AutoSubmitted::VALUE_AUTO_REPLIED) |
|
| 143 | - * @return IMessage |
|
| 144 | - * @since 26.0.0 |
|
| 145 | - */ |
|
| 146 | - public function setAutoSubmitted(string $value): IMessage; |
|
| 138 | + /** |
|
| 139 | + * Add the Auto-Submitted header to the email, preventing most automated |
|
| 140 | + * responses to automated messages. |
|
| 141 | + * |
|
| 142 | + * @param Headers\AutoSubmitted::VALUE_* $value (one of AutoSubmitted::VALUE_NO, AutoSubmitted::VALUE_AUTO_GENERATED, AutoSubmitted::VALUE_AUTO_REPLIED) |
|
| 143 | + * @return IMessage |
|
| 144 | + * @since 26.0.0 |
|
| 145 | + */ |
|
| 146 | + public function setAutoSubmitted(string $value): IMessage; |
|
| 147 | 147 | } |