@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright 2017, Morris Jobke <[email protected]> |
| 5 | 5 | * |
@@ -62,6 +62,7 @@ discard block |
||
| 62 | 62 | * @param string $subject |
| 63 | 63 | * |
| 64 | 64 | * @since 13.0.0 |
| 65 | + * @return void |
|
| 65 | 66 | */ |
| 66 | 67 | public function setSubject(string $subject); |
| 67 | 68 | |
@@ -69,6 +70,7 @@ discard block |
||
| 69 | 70 | * Adds a header to the email |
| 70 | 71 | * |
| 71 | 72 | * @since 12.0.0 |
| 73 | + * @return void |
|
| 72 | 74 | */ |
| 73 | 75 | public function addHeader(); |
| 74 | 76 | |
@@ -80,6 +82,7 @@ discard block |
||
| 80 | 82 | * if empty the $title is used, if false none will be used |
| 81 | 83 | * |
| 82 | 84 | * @since 12.0.0 |
| 85 | + * @return void |
|
| 83 | 86 | */ |
| 84 | 87 | public function addHeading(string $title, $plainTitle = ''); |
| 85 | 88 | |
@@ -91,6 +94,7 @@ discard block |
||
| 91 | 94 | * if empty the $text is used, if false none will be used |
| 92 | 95 | * |
| 93 | 96 | * @since 12.0.0 |
| 97 | + * @return void |
|
| 94 | 98 | */ |
| 95 | 99 | public function addBodyText(string $text, $plainText = ''); |
| 96 | 100 | |
@@ -105,6 +109,7 @@ discard block |
||
| 105 | 109 | * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
| 106 | 110 | * if empty the $metaInfo is used, if false none will be used |
| 107 | 111 | * @since 12.0.0 |
| 112 | + * @return void |
|
| 108 | 113 | */ |
| 109 | 114 | public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = ''); |
| 110 | 115 | |
@@ -119,6 +124,7 @@ discard block |
||
| 119 | 124 | * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
| 120 | 125 | * |
| 121 | 126 | * @since 12.0.0 |
| 127 | + * @return void |
|
| 122 | 128 | */ |
| 123 | 129 | public function addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight, string $plainTextLeft = '', string $plainTextRight = ''); |
| 124 | 130 | |
@@ -131,6 +137,7 @@ discard block |
||
| 131 | 137 | * if empty the $text is used, if false none will be used |
| 132 | 138 | * |
| 133 | 139 | * @since 12.0.0 |
| 140 | + * @return void |
|
| 134 | 141 | */ |
| 135 | 142 | public function addBodyButton(string $text, string $url, $plainText = ''); |
| 136 | 143 | |
@@ -140,6 +147,7 @@ discard block |
||
| 140 | 147 | * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
| 141 | 148 | * |
| 142 | 149 | * @since 12.0.0 |
| 150 | + * @return void |
|
| 143 | 151 | */ |
| 144 | 152 | public function addFooter(string $text = ''); |
| 145 | 153 | |
@@ -56,117 +56,117 @@ |
||
| 56 | 56 | */ |
| 57 | 57 | interface IEMailTemplate { |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Sets the subject of the email |
|
| 61 | - * |
|
| 62 | - * @param string $subject |
|
| 63 | - * |
|
| 64 | - * @since 13.0.0 |
|
| 65 | - */ |
|
| 66 | - public function setSubject(string $subject); |
|
| 59 | + /** |
|
| 60 | + * Sets the subject of the email |
|
| 61 | + * |
|
| 62 | + * @param string $subject |
|
| 63 | + * |
|
| 64 | + * @since 13.0.0 |
|
| 65 | + */ |
|
| 66 | + public function setSubject(string $subject); |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Adds a header to the email |
|
| 70 | - * |
|
| 71 | - * @since 12.0.0 |
|
| 72 | - */ |
|
| 73 | - public function addHeader(); |
|
| 68 | + /** |
|
| 69 | + * Adds a header to the email |
|
| 70 | + * |
|
| 71 | + * @since 12.0.0 |
|
| 72 | + */ |
|
| 73 | + public function addHeader(); |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Adds a heading to the email |
|
| 77 | - * |
|
| 78 | - * @param string $title |
|
| 79 | - * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 80 | - * if empty the $title is used, if false none will be used |
|
| 81 | - * |
|
| 82 | - * @since 12.0.0 |
|
| 83 | - */ |
|
| 84 | - public function addHeading(string $title, $plainTitle = ''); |
|
| 75 | + /** |
|
| 76 | + * Adds a heading to the email |
|
| 77 | + * |
|
| 78 | + * @param string $title |
|
| 79 | + * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 80 | + * if empty the $title is used, if false none will be used |
|
| 81 | + * |
|
| 82 | + * @since 12.0.0 |
|
| 83 | + */ |
|
| 84 | + public function addHeading(string $title, $plainTitle = ''); |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Adds a paragraph to the body of the email |
|
| 88 | - * |
|
| 89 | - * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 90 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 91 | - * if empty the $text is used, if false none will be used |
|
| 92 | - * |
|
| 93 | - * @since 12.0.0 |
|
| 94 | - */ |
|
| 95 | - public function addBodyText(string $text, $plainText = ''); |
|
| 86 | + /** |
|
| 87 | + * Adds a paragraph to the body of the email |
|
| 88 | + * |
|
| 89 | + * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 90 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 91 | + * if empty the $text is used, if false none will be used |
|
| 92 | + * |
|
| 93 | + * @since 12.0.0 |
|
| 94 | + */ |
|
| 95 | + public function addBodyText(string $text, $plainText = ''); |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Adds a list item to the body of the email |
|
| 99 | - * |
|
| 100 | - * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 101 | - * @param string $metaInfo; Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 102 | - * @param string $icon Absolute path, must be 16*16 pixels |
|
| 103 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 104 | - * if empty the $text is used, if false none will be used |
|
| 105 | - * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 106 | - * if empty the $metaInfo is used, if false none will be used |
|
| 107 | - * @since 12.0.0 |
|
| 108 | - */ |
|
| 109 | - public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = ''); |
|
| 97 | + /** |
|
| 98 | + * Adds a list item to the body of the email |
|
| 99 | + * |
|
| 100 | + * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 101 | + * @param string $metaInfo; Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 102 | + * @param string $icon Absolute path, must be 16*16 pixels |
|
| 103 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 104 | + * if empty the $text is used, if false none will be used |
|
| 105 | + * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 106 | + * if empty the $metaInfo is used, if false none will be used |
|
| 107 | + * @since 12.0.0 |
|
| 108 | + */ |
|
| 109 | + public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = ''); |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Adds a button group of two buttons to the body of the email |
|
| 113 | - * |
|
| 114 | - * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 115 | - * @param string $urlLeft URL of left button |
|
| 116 | - * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 117 | - * @param string $urlRight URL of right button |
|
| 118 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
| 119 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
| 120 | - * |
|
| 121 | - * @since 12.0.0 |
|
| 122 | - */ |
|
| 123 | - public function addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight, string $plainTextLeft = '', string $plainTextRight = ''); |
|
| 111 | + /** |
|
| 112 | + * Adds a button group of two buttons to the body of the email |
|
| 113 | + * |
|
| 114 | + * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 115 | + * @param string $urlLeft URL of left button |
|
| 116 | + * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 117 | + * @param string $urlRight URL of right button |
|
| 118 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used |
|
| 119 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used |
|
| 120 | + * |
|
| 121 | + * @since 12.0.0 |
|
| 122 | + */ |
|
| 123 | + public function addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight, string $plainTextLeft = '', string $plainTextRight = ''); |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Adds a button to the body of the email |
|
| 127 | - * |
|
| 128 | - * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 129 | - * @param string $url URL of button |
|
| 130 | - * @param string $plainText Text of button in plain text version |
|
| 131 | - * if empty the $text is used, if false none will be used |
|
| 132 | - * |
|
| 133 | - * @since 12.0.0 |
|
| 134 | - */ |
|
| 135 | - public function addBodyButton(string $text, string $url, $plainText = ''); |
|
| 125 | + /** |
|
| 126 | + * Adds a button to the body of the email |
|
| 127 | + * |
|
| 128 | + * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 129 | + * @param string $url URL of button |
|
| 130 | + * @param string $plainText Text of button in plain text version |
|
| 131 | + * if empty the $text is used, if false none will be used |
|
| 132 | + * |
|
| 133 | + * @since 12.0.0 |
|
| 134 | + */ |
|
| 135 | + public function addBodyButton(string $text, string $url, $plainText = ''); |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 139 | - * |
|
| 140 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 141 | - * |
|
| 142 | - * @since 12.0.0 |
|
| 143 | - */ |
|
| 144 | - public function addFooter(string $text = ''); |
|
| 137 | + /** |
|
| 138 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 139 | + * |
|
| 140 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 141 | + * |
|
| 142 | + * @since 12.0.0 |
|
| 143 | + */ |
|
| 144 | + public function addFooter(string $text = ''); |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Returns the rendered email subject as string |
|
| 148 | - * |
|
| 149 | - * @return string |
|
| 150 | - * |
|
| 151 | - * @since 13.0.0 |
|
| 152 | - */ |
|
| 153 | - public function renderSubject(): string; |
|
| 146 | + /** |
|
| 147 | + * Returns the rendered email subject as string |
|
| 148 | + * |
|
| 149 | + * @return string |
|
| 150 | + * |
|
| 151 | + * @since 13.0.0 |
|
| 152 | + */ |
|
| 153 | + public function renderSubject(): string; |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Returns the rendered HTML email as string |
|
| 157 | - * |
|
| 158 | - * @return string |
|
| 159 | - * |
|
| 160 | - * @since 12.0.0 |
|
| 161 | - */ |
|
| 162 | - public function renderHtml(): string; |
|
| 155 | + /** |
|
| 156 | + * Returns the rendered HTML email as string |
|
| 157 | + * |
|
| 158 | + * @return string |
|
| 159 | + * |
|
| 160 | + * @since 12.0.0 |
|
| 161 | + */ |
|
| 162 | + public function renderHtml(): string; |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Returns the rendered plain text email as string |
|
| 166 | - * |
|
| 167 | - * @return string |
|
| 168 | - * |
|
| 169 | - * @since 12.0.0 |
|
| 170 | - */ |
|
| 171 | - public function renderText(): string; |
|
| 164 | + /** |
|
| 165 | + * Returns the rendered plain text email as string |
|
| 166 | + * |
|
| 167 | + * @return string |
|
| 168 | + * |
|
| 169 | + * @since 12.0.0 |
|
| 170 | + */ |
|
| 171 | + public function renderText(): string; |
|
| 172 | 172 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2017 Joas Schilling <[email protected]> |
| 5 | 5 | * |
@@ -32,25 +32,25 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface IAttachment { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param string $filename |
|
| 37 | - * @return IAttachment |
|
| 38 | - * @since 13.0.0 |
|
| 39 | - */ |
|
| 40 | - public function setFilename(string $filename): IAttachment; |
|
| 35 | + /** |
|
| 36 | + * @param string $filename |
|
| 37 | + * @return IAttachment |
|
| 38 | + * @since 13.0.0 |
|
| 39 | + */ |
|
| 40 | + public function setFilename(string $filename): IAttachment; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @param string $contentType |
|
| 44 | - * @return IAttachment |
|
| 45 | - * @since 13.0.0 |
|
| 46 | - */ |
|
| 47 | - public function setContentType(string $contentType): IAttachment; |
|
| 42 | + /** |
|
| 43 | + * @param string $contentType |
|
| 44 | + * @return IAttachment |
|
| 45 | + * @since 13.0.0 |
|
| 46 | + */ |
|
| 47 | + public function setContentType(string $contentType): IAttachment; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param string $body |
|
| 51 | - * @return IAttachment |
|
| 52 | - * @since 13.0.0 |
|
| 53 | - */ |
|
| 54 | - public function setBody(string $body): IAttachment; |
|
| 49 | + /** |
|
| 50 | + * @param string $body |
|
| 51 | + * @return IAttachment |
|
| 52 | + * @since 13.0.0 |
|
| 53 | + */ |
|
| 54 | + public function setBody(string $body): IAttachment; |
|
| 55 | 55 | |
| 56 | 56 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $mailer = $this->getInstance(); |
| 170 | 170 | |
| 171 | 171 | // Enable logger if debug mode is enabled |
| 172 | - if($debugMode) { |
|
| 172 | + if ($debugMode) { |
|
| 173 | 173 | $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
| 174 | 174 | $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
| 175 | 175 | } |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | // Debugging logging |
| 180 | 180 | $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
| 181 | 181 | $this->logger->debug($logMessage, ['app' => 'core']); |
| 182 | - if($debugMode && isset($mailLogger)) { |
|
| 182 | + if ($debugMode && isset($mailLogger)) { |
|
| 183 | 183 | $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
| 184 | 184 | } |
| 185 | 185 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | list($name, $domain) = explode('@', $email, 2); |
| 213 | - $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
| 213 | + $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
|
| 214 | 214 | return $name.'@'.$domain; |
| 215 | 215 | } |
| 216 | 216 | |
@@ -280,7 +280,7 @@ discard block |
||
| 280 | 280 | break; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs'); |
|
| 283 | + return \Swift_SendmailTransport::newInstance($binaryPath.' -bs'); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -55,241 +55,241 @@ |
||
| 55 | 55 | * @package OC\Mail |
| 56 | 56 | */ |
| 57 | 57 | class Mailer implements IMailer { |
| 58 | - /** @var \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport Cached transport */ |
|
| 59 | - private $instance = null; |
|
| 60 | - /** @var IConfig */ |
|
| 61 | - private $config; |
|
| 62 | - /** @var ILogger */ |
|
| 63 | - private $logger; |
|
| 64 | - /** @var Defaults */ |
|
| 65 | - private $defaults; |
|
| 66 | - /** @var IURLGenerator */ |
|
| 67 | - private $urlGenerator; |
|
| 68 | - /** @var IL10N */ |
|
| 69 | - private $l10n; |
|
| 58 | + /** @var \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport Cached transport */ |
|
| 59 | + private $instance = null; |
|
| 60 | + /** @var IConfig */ |
|
| 61 | + private $config; |
|
| 62 | + /** @var ILogger */ |
|
| 63 | + private $logger; |
|
| 64 | + /** @var Defaults */ |
|
| 65 | + private $defaults; |
|
| 66 | + /** @var IURLGenerator */ |
|
| 67 | + private $urlGenerator; |
|
| 68 | + /** @var IL10N */ |
|
| 69 | + private $l10n; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param IConfig $config |
|
| 73 | - * @param ILogger $logger |
|
| 74 | - * @param Defaults $defaults |
|
| 75 | - * @param IURLGenerator $urlGenerator |
|
| 76 | - * @param IL10N $l10n |
|
| 77 | - */ |
|
| 78 | - public function __construct(IConfig $config, |
|
| 79 | - ILogger $logger, |
|
| 80 | - Defaults $defaults, |
|
| 81 | - IURLGenerator $urlGenerator, |
|
| 82 | - IL10N $l10n) { |
|
| 83 | - $this->config = $config; |
|
| 84 | - $this->logger = $logger; |
|
| 85 | - $this->defaults = $defaults; |
|
| 86 | - $this->urlGenerator = $urlGenerator; |
|
| 87 | - $this->l10n = $l10n; |
|
| 88 | - } |
|
| 71 | + /** |
|
| 72 | + * @param IConfig $config |
|
| 73 | + * @param ILogger $logger |
|
| 74 | + * @param Defaults $defaults |
|
| 75 | + * @param IURLGenerator $urlGenerator |
|
| 76 | + * @param IL10N $l10n |
|
| 77 | + */ |
|
| 78 | + public function __construct(IConfig $config, |
|
| 79 | + ILogger $logger, |
|
| 80 | + Defaults $defaults, |
|
| 81 | + IURLGenerator $urlGenerator, |
|
| 82 | + IL10N $l10n) { |
|
| 83 | + $this->config = $config; |
|
| 84 | + $this->logger = $logger; |
|
| 85 | + $this->defaults = $defaults; |
|
| 86 | + $this->urlGenerator = $urlGenerator; |
|
| 87 | + $this->l10n = $l10n; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Creates a new message object that can be passed to send() |
|
| 92 | - * |
|
| 93 | - * @return IMessage |
|
| 94 | - */ |
|
| 95 | - public function createMessage(): IMessage { |
|
| 96 | - return new Message(new \Swift_Message()); |
|
| 97 | - } |
|
| 90 | + /** |
|
| 91 | + * Creates a new message object that can be passed to send() |
|
| 92 | + * |
|
| 93 | + * @return IMessage |
|
| 94 | + */ |
|
| 95 | + public function createMessage(): IMessage { |
|
| 96 | + return new Message(new \Swift_Message()); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * @param string|null $data |
|
| 101 | - * @param string|null $filename |
|
| 102 | - * @param string|null $contentType |
|
| 103 | - * @return IAttachment |
|
| 104 | - * @since 13.0.0 |
|
| 105 | - */ |
|
| 106 | - public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment { |
|
| 107 | - return new Attachment(\Swift_Attachment::newInstance($data, $filename, $contentType)); |
|
| 108 | - } |
|
| 99 | + /** |
|
| 100 | + * @param string|null $data |
|
| 101 | + * @param string|null $filename |
|
| 102 | + * @param string|null $contentType |
|
| 103 | + * @return IAttachment |
|
| 104 | + * @since 13.0.0 |
|
| 105 | + */ |
|
| 106 | + public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment { |
|
| 107 | + return new Attachment(\Swift_Attachment::newInstance($data, $filename, $contentType)); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * @param string $path |
|
| 112 | - * @param string|null $contentType |
|
| 113 | - * @return IAttachment |
|
| 114 | - * @since 13.0.0 |
|
| 115 | - */ |
|
| 116 | - public function createAttachmentFromPath(string $path, $contentType = null): IAttachment { |
|
| 117 | - return new Attachment(\Swift_Attachment::fromPath($path, $contentType)); |
|
| 118 | - } |
|
| 110 | + /** |
|
| 111 | + * @param string $path |
|
| 112 | + * @param string|null $contentType |
|
| 113 | + * @return IAttachment |
|
| 114 | + * @since 13.0.0 |
|
| 115 | + */ |
|
| 116 | + public function createAttachmentFromPath(string $path, $contentType = null): IAttachment { |
|
| 117 | + return new Attachment(\Swift_Attachment::fromPath($path, $contentType)); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Creates a new email template object |
|
| 122 | - * |
|
| 123 | - * @param string $emailId |
|
| 124 | - * @param array $data |
|
| 125 | - * @return IEMailTemplate |
|
| 126 | - * @since 12.0.0 |
|
| 127 | - */ |
|
| 128 | - public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate { |
|
| 129 | - $class = $this->config->getSystemValue('mail_template_class', ''); |
|
| 120 | + /** |
|
| 121 | + * Creates a new email template object |
|
| 122 | + * |
|
| 123 | + * @param string $emailId |
|
| 124 | + * @param array $data |
|
| 125 | + * @return IEMailTemplate |
|
| 126 | + * @since 12.0.0 |
|
| 127 | + */ |
|
| 128 | + public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate { |
|
| 129 | + $class = $this->config->getSystemValue('mail_template_class', ''); |
|
| 130 | 130 | |
| 131 | - if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { |
|
| 132 | - return new $class( |
|
| 133 | - $this->defaults, |
|
| 134 | - $this->urlGenerator, |
|
| 135 | - $this->l10n, |
|
| 136 | - $emailId, |
|
| 137 | - $data |
|
| 138 | - ); |
|
| 139 | - } |
|
| 131 | + if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) { |
|
| 132 | + return new $class( |
|
| 133 | + $this->defaults, |
|
| 134 | + $this->urlGenerator, |
|
| 135 | + $this->l10n, |
|
| 136 | + $emailId, |
|
| 137 | + $data |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - return new EMailTemplate( |
|
| 142 | - $this->defaults, |
|
| 143 | - $this->urlGenerator, |
|
| 144 | - $this->l10n, |
|
| 145 | - $emailId, |
|
| 146 | - $data |
|
| 147 | - ); |
|
| 148 | - } |
|
| 141 | + return new EMailTemplate( |
|
| 142 | + $this->defaults, |
|
| 143 | + $this->urlGenerator, |
|
| 144 | + $this->l10n, |
|
| 145 | + $emailId, |
|
| 146 | + $data |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Send the specified message. Also sets the from address to the value defined in config.php |
|
| 152 | - * if no-one has been passed. |
|
| 153 | - * |
|
| 154 | - * @param IMessage|Message $message Message to send |
|
| 155 | - * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
| 156 | - * therefore should be considered |
|
| 157 | - * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
| 158 | - * has been supplied.) |
|
| 159 | - */ |
|
| 160 | - public function send(IMessage $message): array { |
|
| 161 | - $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); |
|
| 150 | + /** |
|
| 151 | + * Send the specified message. Also sets the from address to the value defined in config.php |
|
| 152 | + * if no-one has been passed. |
|
| 153 | + * |
|
| 154 | + * @param IMessage|Message $message Message to send |
|
| 155 | + * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
| 156 | + * therefore should be considered |
|
| 157 | + * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
| 158 | + * has been supplied.) |
|
| 159 | + */ |
|
| 160 | + public function send(IMessage $message): array { |
|
| 161 | + $debugMode = $this->config->getSystemValue('mail_smtpdebug', false); |
|
| 162 | 162 | |
| 163 | - if (empty($message->getFrom())) { |
|
| 164 | - $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName()) => $this->defaults->getName()]); |
|
| 165 | - } |
|
| 163 | + if (empty($message->getFrom())) { |
|
| 164 | + $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName()) => $this->defaults->getName()]); |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - $failedRecipients = []; |
|
| 167 | + $failedRecipients = []; |
|
| 168 | 168 | |
| 169 | - $mailer = $this->getInstance(); |
|
| 169 | + $mailer = $this->getInstance(); |
|
| 170 | 170 | |
| 171 | - // Enable logger if debug mode is enabled |
|
| 172 | - if($debugMode) { |
|
| 173 | - $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
|
| 174 | - $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
|
| 175 | - } |
|
| 171 | + // Enable logger if debug mode is enabled |
|
| 172 | + if($debugMode) { |
|
| 173 | + $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger(); |
|
| 174 | + $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger)); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - $mailer->send($message->getSwiftMessage(), $failedRecipients); |
|
| 177 | + $mailer->send($message->getSwiftMessage(), $failedRecipients); |
|
| 178 | 178 | |
| 179 | - // Debugging logging |
|
| 180 | - $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
|
| 181 | - $this->logger->debug($logMessage, ['app' => 'core']); |
|
| 182 | - if($debugMode && isset($mailLogger)) { |
|
| 183 | - $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
|
| 184 | - } |
|
| 179 | + // Debugging logging |
|
| 180 | + $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject()); |
|
| 181 | + $this->logger->debug($logMessage, ['app' => 'core']); |
|
| 182 | + if($debugMode && isset($mailLogger)) { |
|
| 183 | + $this->logger->debug($mailLogger->dump(), ['app' => 'core']); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - return $failedRecipients; |
|
| 187 | - } |
|
| 186 | + return $failedRecipients; |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * Checks if an e-mail address is valid |
|
| 191 | - * |
|
| 192 | - * @param string $email Email address to be validated |
|
| 193 | - * @return bool True if the mail address is valid, false otherwise |
|
| 194 | - */ |
|
| 195 | - public function validateMailAddress(string $email): bool { |
|
| 196 | - return \Swift_Validate::email($this->convertEmail($email)); |
|
| 197 | - } |
|
| 189 | + /** |
|
| 190 | + * Checks if an e-mail address is valid |
|
| 191 | + * |
|
| 192 | + * @param string $email Email address to be validated |
|
| 193 | + * @return bool True if the mail address is valid, false otherwise |
|
| 194 | + */ |
|
| 195 | + public function validateMailAddress(string $email): bool { |
|
| 196 | + return \Swift_Validate::email($this->convertEmail($email)); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - /** |
|
| 200 | - * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
| 201 | - * |
|
| 202 | - * FIXME: Remove this once SwiftMailer supports IDN |
|
| 203 | - * |
|
| 204 | - * @param string $email |
|
| 205 | - * @return string Converted mail address if `idn_to_ascii` exists |
|
| 206 | - */ |
|
| 207 | - protected function convertEmail(string $email): string { |
|
| 208 | - if (!function_exists('idn_to_ascii') || strpos($email, '@') === false) { |
|
| 209 | - return $email; |
|
| 210 | - } |
|
| 199 | + /** |
|
| 200 | + * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
| 201 | + * |
|
| 202 | + * FIXME: Remove this once SwiftMailer supports IDN |
|
| 203 | + * |
|
| 204 | + * @param string $email |
|
| 205 | + * @return string Converted mail address if `idn_to_ascii` exists |
|
| 206 | + */ |
|
| 207 | + protected function convertEmail(string $email): string { |
|
| 208 | + if (!function_exists('idn_to_ascii') || strpos($email, '@') === false) { |
|
| 209 | + return $email; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - list($name, $domain) = explode('@', $email, 2); |
|
| 213 | - $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
| 214 | - return $name.'@'.$domain; |
|
| 215 | - } |
|
| 212 | + list($name, $domain) = explode('@', $email, 2); |
|
| 213 | + $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46); |
|
| 214 | + return $name.'@'.$domain; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Returns whatever transport is configured within the config |
|
| 219 | - * |
|
| 220 | - * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport |
|
| 221 | - */ |
|
| 222 | - protected function getInstance() { |
|
| 223 | - if (!is_null($this->instance)) { |
|
| 224 | - return $this->instance; |
|
| 225 | - } |
|
| 217 | + /** |
|
| 218 | + * Returns whatever transport is configured within the config |
|
| 219 | + * |
|
| 220 | + * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport |
|
| 221 | + */ |
|
| 222 | + protected function getInstance() { |
|
| 223 | + if (!is_null($this->instance)) { |
|
| 224 | + return $this->instance; |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { |
|
| 228 | - case 'smtp': |
|
| 229 | - $this->instance = $this->getSmtpInstance(); |
|
| 230 | - break; |
|
| 231 | - case 'sendmail': |
|
| 232 | - // FIXME: Move into the return statement but requires proper testing |
|
| 233 | - // for SMTP and mail as well. Thus not really doable for a |
|
| 234 | - // minor release. |
|
| 235 | - $this->instance = \Swift_Mailer::newInstance($this->getSendMailInstance()); |
|
| 236 | - break; |
|
| 237 | - default: |
|
| 238 | - $this->instance = $this->getMailInstance(); |
|
| 239 | - break; |
|
| 240 | - } |
|
| 227 | + switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { |
|
| 228 | + case 'smtp': |
|
| 229 | + $this->instance = $this->getSmtpInstance(); |
|
| 230 | + break; |
|
| 231 | + case 'sendmail': |
|
| 232 | + // FIXME: Move into the return statement but requires proper testing |
|
| 233 | + // for SMTP and mail as well. Thus not really doable for a |
|
| 234 | + // minor release. |
|
| 235 | + $this->instance = \Swift_Mailer::newInstance($this->getSendMailInstance()); |
|
| 236 | + break; |
|
| 237 | + default: |
|
| 238 | + $this->instance = $this->getMailInstance(); |
|
| 239 | + break; |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $this->instance; |
|
| 243 | - } |
|
| 242 | + return $this->instance; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Returns the SMTP transport |
|
| 247 | - * |
|
| 248 | - * @return \Swift_SmtpTransport |
|
| 249 | - */ |
|
| 250 | - protected function getSmtpInstance(): \Swift_SmtpTransport { |
|
| 251 | - $transport = \Swift_SmtpTransport::newInstance(); |
|
| 252 | - $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); |
|
| 253 | - $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); |
|
| 254 | - $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); |
|
| 255 | - if ($this->config->getSystemValue('mail_smtpauth', false)) { |
|
| 256 | - $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); |
|
| 257 | - $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); |
|
| 258 | - $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN')); |
|
| 259 | - } |
|
| 260 | - $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', ''); |
|
| 261 | - if (!empty($smtpSecurity)) { |
|
| 262 | - $transport->setEncryption($smtpSecurity); |
|
| 263 | - } |
|
| 264 | - $transport->start(); |
|
| 265 | - return $transport; |
|
| 266 | - } |
|
| 245 | + /** |
|
| 246 | + * Returns the SMTP transport |
|
| 247 | + * |
|
| 248 | + * @return \Swift_SmtpTransport |
|
| 249 | + */ |
|
| 250 | + protected function getSmtpInstance(): \Swift_SmtpTransport { |
|
| 251 | + $transport = \Swift_SmtpTransport::newInstance(); |
|
| 252 | + $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10)); |
|
| 253 | + $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1')); |
|
| 254 | + $transport->setPort($this->config->getSystemValue('mail_smtpport', 25)); |
|
| 255 | + if ($this->config->getSystemValue('mail_smtpauth', false)) { |
|
| 256 | + $transport->setUsername($this->config->getSystemValue('mail_smtpname', '')); |
|
| 257 | + $transport->setPassword($this->config->getSystemValue('mail_smtppassword', '')); |
|
| 258 | + $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN')); |
|
| 259 | + } |
|
| 260 | + $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', ''); |
|
| 261 | + if (!empty($smtpSecurity)) { |
|
| 262 | + $transport->setEncryption($smtpSecurity); |
|
| 263 | + } |
|
| 264 | + $transport->start(); |
|
| 265 | + return $transport; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * Returns the sendmail transport |
|
| 270 | - * |
|
| 271 | - * @return \Swift_SendmailTransport |
|
| 272 | - */ |
|
| 273 | - protected function getSendMailInstance(): \Swift_SendmailTransport { |
|
| 274 | - switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { |
|
| 275 | - case 'qmail': |
|
| 276 | - $binaryPath = '/var/qmail/bin/sendmail'; |
|
| 277 | - break; |
|
| 278 | - default: |
|
| 279 | - $binaryPath = '/usr/sbin/sendmail'; |
|
| 280 | - break; |
|
| 281 | - } |
|
| 268 | + /** |
|
| 269 | + * Returns the sendmail transport |
|
| 270 | + * |
|
| 271 | + * @return \Swift_SendmailTransport |
|
| 272 | + */ |
|
| 273 | + protected function getSendMailInstance(): \Swift_SendmailTransport { |
|
| 274 | + switch ($this->config->getSystemValue('mail_smtpmode', 'php')) { |
|
| 275 | + case 'qmail': |
|
| 276 | + $binaryPath = '/var/qmail/bin/sendmail'; |
|
| 277 | + break; |
|
| 278 | + default: |
|
| 279 | + $binaryPath = '/usr/sbin/sendmail'; |
|
| 280 | + break; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs'); |
|
| 284 | - } |
|
| 283 | + return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs'); |
|
| 284 | + } |
|
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * Returns the mail transport |
|
| 288 | - * |
|
| 289 | - * @return \Swift_MailTransport |
|
| 290 | - */ |
|
| 291 | - protected function getMailInstance(): \Swift_MailTransport { |
|
| 292 | - return \Swift_MailTransport::newInstance(); |
|
| 293 | - } |
|
| 286 | + /** |
|
| 287 | + * Returns the mail transport |
|
| 288 | + * |
|
| 289 | + * @return \Swift_MailTransport |
|
| 290 | + */ |
|
| 291 | + protected function getMailInstance(): \Swift_MailTransport { |
|
| 292 | + return \Swift_MailTransport::newInstance(); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | 295 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2017 Joas Schilling <[email protected]> |
| 5 | 5 | * |
@@ -32,64 +32,64 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface IMessage { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param IAttachment $attachment |
|
| 37 | - * @return IMessage |
|
| 38 | - * @since 13.0.0 |
|
| 39 | - */ |
|
| 40 | - public function attach(IAttachment $attachment): IMessage; |
|
| 35 | + /** |
|
| 36 | + * @param IAttachment $attachment |
|
| 37 | + * @return IMessage |
|
| 38 | + * @since 13.0.0 |
|
| 39 | + */ |
|
| 40 | + public function attach(IAttachment $attachment): IMessage; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Set the from address of this message. |
|
| 44 | - * |
|
| 45 | - * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 46 | - * |
|
| 47 | - * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 48 | - * @return IMessage |
|
| 49 | - * @since 13.0.0 |
|
| 50 | - */ |
|
| 51 | - public function setFrom(array $addresses): IMessage; |
|
| 42 | + /** |
|
| 43 | + * Set the from address of this message. |
|
| 44 | + * |
|
| 45 | + * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 46 | + * |
|
| 47 | + * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 48 | + * @return IMessage |
|
| 49 | + * @since 13.0.0 |
|
| 50 | + */ |
|
| 51 | + public function setFrom(array $addresses): IMessage; |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Set the Reply-To address of this message |
|
| 55 | - * |
|
| 56 | - * @param array $addresses |
|
| 57 | - * @return IMessage |
|
| 58 | - * @since 13.0.0 |
|
| 59 | - */ |
|
| 60 | - public function setReplyTo(array $addresses): IMessage; |
|
| 53 | + /** |
|
| 54 | + * Set the Reply-To address of this message |
|
| 55 | + * |
|
| 56 | + * @param array $addresses |
|
| 57 | + * @return IMessage |
|
| 58 | + * @since 13.0.0 |
|
| 59 | + */ |
|
| 60 | + public function setReplyTo(array $addresses): IMessage; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Set the to addresses of this message. |
|
| 64 | - * |
|
| 65 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 66 | - * @return IMessage |
|
| 67 | - * @since 13.0.0 |
|
| 68 | - */ |
|
| 69 | - public function setTo(array $recipients): IMessage; |
|
| 62 | + /** |
|
| 63 | + * Set the to addresses of this message. |
|
| 64 | + * |
|
| 65 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 66 | + * @return IMessage |
|
| 67 | + * @since 13.0.0 |
|
| 68 | + */ |
|
| 69 | + public function setTo(array $recipients): IMessage; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Set the CC recipients of this message. |
|
| 73 | - * |
|
| 74 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 75 | - * @return IMessage |
|
| 76 | - * @since 13.0.0 |
|
| 77 | - */ |
|
| 78 | - public function setCc(array $recipients): IMessage; |
|
| 71 | + /** |
|
| 72 | + * Set the CC recipients of this message. |
|
| 73 | + * |
|
| 74 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 75 | + * @return IMessage |
|
| 76 | + * @since 13.0.0 |
|
| 77 | + */ |
|
| 78 | + public function setCc(array $recipients): IMessage; |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Set the BCC recipients of this message. |
|
| 82 | - * |
|
| 83 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 84 | - * @return IMessage |
|
| 85 | - * @since 13.0.0 |
|
| 86 | - */ |
|
| 87 | - public function setBcc(array $recipients): IMessage; |
|
| 80 | + /** |
|
| 81 | + * Set the BCC recipients of this message. |
|
| 82 | + * |
|
| 83 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 84 | + * @return IMessage |
|
| 85 | + * @since 13.0.0 |
|
| 86 | + */ |
|
| 87 | + public function setBcc(array $recipients): IMessage; |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @param IEMailTemplate $emailTemplate |
|
| 91 | - * @return IMessage |
|
| 92 | - * @since 13.0.0 |
|
| 93 | - */ |
|
| 94 | - public function useTemplate(IEMailTemplate $emailTemplate): IMessage; |
|
| 89 | + /** |
|
| 90 | + * @param IEMailTemplate $emailTemplate |
|
| 91 | + * @return IMessage |
|
| 92 | + * @since 13.0.0 |
|
| 93 | + */ |
|
| 94 | + public function useTemplate(IEMailTemplate $emailTemplate): IMessage; |
|
| 95 | 95 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -46,60 +46,60 @@ |
||
| 46 | 46 | * @since 8.1.0 |
| 47 | 47 | */ |
| 48 | 48 | interface IMailer { |
| 49 | - /** |
|
| 50 | - * Creates a new message object that can be passed to send() |
|
| 51 | - * |
|
| 52 | - * @return IMessage |
|
| 53 | - * @since 8.1.0 |
|
| 54 | - */ |
|
| 55 | - public function createMessage(): IMessage; |
|
| 49 | + /** |
|
| 50 | + * Creates a new message object that can be passed to send() |
|
| 51 | + * |
|
| 52 | + * @return IMessage |
|
| 53 | + * @since 8.1.0 |
|
| 54 | + */ |
|
| 55 | + public function createMessage(): IMessage; |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param string|null $data |
|
| 59 | - * @param string|null $filename |
|
| 60 | - * @param string|null $contentType |
|
| 61 | - * @return IAttachment |
|
| 62 | - * @since 13.0.0 |
|
| 63 | - */ |
|
| 64 | - public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment; |
|
| 57 | + /** |
|
| 58 | + * @param string|null $data |
|
| 59 | + * @param string|null $filename |
|
| 60 | + * @param string|null $contentType |
|
| 61 | + * @return IAttachment |
|
| 62 | + * @since 13.0.0 |
|
| 63 | + */ |
|
| 64 | + public function createAttachment($data = null, $filename = null, $contentType = null): IAttachment; |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @param string $path |
|
| 68 | - * @param string|null $contentType |
|
| 69 | - * @return IAttachment |
|
| 70 | - * @since 13.0.0 |
|
| 71 | - */ |
|
| 72 | - public function createAttachmentFromPath(string $path, $contentType = null): IAttachment; |
|
| 66 | + /** |
|
| 67 | + * @param string $path |
|
| 68 | + * @param string|null $contentType |
|
| 69 | + * @return IAttachment |
|
| 70 | + * @since 13.0.0 |
|
| 71 | + */ |
|
| 72 | + public function createAttachmentFromPath(string $path, $contentType = null): IAttachment; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Creates a new email template object |
|
| 76 | - * |
|
| 77 | - * @param string $emailId |
|
| 78 | - * @param array $data |
|
| 79 | - * @return IEMailTemplate |
|
| 80 | - * @since 12.0.0 Parameters added in 12.0.3 |
|
| 81 | - */ |
|
| 82 | - public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate; |
|
| 74 | + /** |
|
| 75 | + * Creates a new email template object |
|
| 76 | + * |
|
| 77 | + * @param string $emailId |
|
| 78 | + * @param array $data |
|
| 79 | + * @return IEMailTemplate |
|
| 80 | + * @since 12.0.0 Parameters added in 12.0.3 |
|
| 81 | + */ |
|
| 82 | + public function createEMailTemplate(string $emailId, array $data = []): IEMailTemplate; |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Send the specified message. Also sets the from address to the value defined in config.php |
|
| 86 | - * if no-one has been passed. |
|
| 87 | - * |
|
| 88 | - * @param IMessage $message Message to send |
|
| 89 | - * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
| 90 | - * therefore should be considered |
|
| 91 | - * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
| 92 | - * has been supplied.) |
|
| 93 | - * @since 8.1.0 |
|
| 94 | - */ |
|
| 95 | - public function send(IMessage $message): array; |
|
| 84 | + /** |
|
| 85 | + * Send the specified message. Also sets the from address to the value defined in config.php |
|
| 86 | + * if no-one has been passed. |
|
| 87 | + * |
|
| 88 | + * @param IMessage $message Message to send |
|
| 89 | + * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and |
|
| 90 | + * therefore should be considered |
|
| 91 | + * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address |
|
| 92 | + * has been supplied.) |
|
| 93 | + * @since 8.1.0 |
|
| 94 | + */ |
|
| 95 | + public function send(IMessage $message): array; |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Checks if an e-mail address is valid |
|
| 99 | - * |
|
| 100 | - * @param string $email Email address to be validated |
|
| 101 | - * @return bool True if the mail address is valid, false otherwise |
|
| 102 | - * @since 8.1.0 |
|
| 103 | - */ |
|
| 104 | - public function validateMailAddress(string $email): bool; |
|
| 97 | + /** |
|
| 98 | + * Checks if an e-mail address is valid |
|
| 99 | + * |
|
| 100 | + * @param string $email Email address to be validated |
|
| 101 | + * @return bool True if the mail address is valid, false otherwise |
|
| 102 | + * @since 8.1.0 |
|
| 103 | + */ |
|
| 104 | + public function validateMailAddress(string $email): bool; |
|
| 105 | 105 | } |
@@ -1,5 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2017 Joas Schilling <[email protected]> |
| 5 | 5 | * |
@@ -34,48 +34,48 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class Attachment implements IAttachment { |
| 36 | 36 | |
| 37 | - /** @var \Swift_Mime_Attachment */ |
|
| 38 | - protected $swiftAttachment; |
|
| 37 | + /** @var \Swift_Mime_Attachment */ |
|
| 38 | + protected $swiftAttachment; |
|
| 39 | 39 | |
| 40 | - public function __construct(\Swift_Mime_Attachment $attachment) { |
|
| 41 | - $this->swiftAttachment = $attachment; |
|
| 42 | - } |
|
| 40 | + public function __construct(\Swift_Mime_Attachment $attachment) { |
|
| 41 | + $this->swiftAttachment = $attachment; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param string $filename |
|
| 46 | - * @return $this |
|
| 47 | - * @since 13.0.0 |
|
| 48 | - */ |
|
| 49 | - public function setFilename(string $filename): IAttachment { |
|
| 50 | - $this->swiftAttachment->setFilename($filename); |
|
| 51 | - return $this; |
|
| 52 | - } |
|
| 44 | + /** |
|
| 45 | + * @param string $filename |
|
| 46 | + * @return $this |
|
| 47 | + * @since 13.0.0 |
|
| 48 | + */ |
|
| 49 | + public function setFilename(string $filename): IAttachment { |
|
| 50 | + $this->swiftAttachment->setFilename($filename); |
|
| 51 | + return $this; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param string $contentType |
|
| 56 | - * @return $this |
|
| 57 | - * @since 13.0.0 |
|
| 58 | - */ |
|
| 59 | - public function setContentType(string $contentType): IAttachment { |
|
| 60 | - $this->swiftAttachment->setContentType($contentType); |
|
| 61 | - return $this; |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * @param string $contentType |
|
| 56 | + * @return $this |
|
| 57 | + * @since 13.0.0 |
|
| 58 | + */ |
|
| 59 | + public function setContentType(string $contentType): IAttachment { |
|
| 60 | + $this->swiftAttachment->setContentType($contentType); |
|
| 61 | + return $this; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param string $body |
|
| 66 | - * @return $this |
|
| 67 | - * @since 13.0.0 |
|
| 68 | - */ |
|
| 69 | - public function setBody(string $body): IAttachment { |
|
| 70 | - $this->swiftAttachment->setBody($body); |
|
| 71 | - return $this; |
|
| 72 | - } |
|
| 64 | + /** |
|
| 65 | + * @param string $body |
|
| 66 | + * @return $this |
|
| 67 | + * @since 13.0.0 |
|
| 68 | + */ |
|
| 69 | + public function setBody(string $body): IAttachment { |
|
| 70 | + $this->swiftAttachment->setBody($body); |
|
| 71 | + return $this; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return \Swift_Mime_Attachment |
|
| 76 | - */ |
|
| 77 | - public function getSwiftAttachment(): \Swift_Mime_Attachment { |
|
| 78 | - return $this->swiftAttachment; |
|
| 79 | - } |
|
| 74 | + /** |
|
| 75 | + * @return \Swift_Mime_Attachment |
|
| 76 | + */ |
|
| 77 | + public function getSwiftAttachment(): \Swift_Mime_Attachment { |
|
| 78 | + return $this->swiftAttachment; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright 2017, Morris Jobke <[email protected]> |
| 5 | 5 | * @copyright 2017, Lukas Reschke <[email protected]> |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
| 404 | 404 | if ($plainTitle !== false) { |
| 405 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 405 | + $this->plainBody .= $plainTitle.PHP_EOL.PHP_EOL; |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
| 440 | 440 | if ($plainText !== false) { |
| 441 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 441 | + $this->plainBody .= $plainText.PHP_EOL.PHP_EOL; |
|
| 442 | 442 | } |
| 443 | 443 | } |
| 444 | 444 | |
@@ -468,18 +468,18 @@ discard block |
||
| 468 | 468 | |
| 469 | 469 | $htmlText = $text; |
| 470 | 470 | if ($metaInfo) { |
| 471 | - $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
| 471 | + $htmlText = '<em style="color:#777;">'.$metaInfo.'</em><br>'.$htmlText; |
|
| 472 | 472 | } |
| 473 | 473 | if ($icon !== '') { |
| 474 | - $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
| 474 | + $icon = '<img src="'.htmlspecialchars($icon).'" alt="•">'; |
|
| 475 | 475 | } else { |
| 476 | 476 | $icon = '•'; |
| 477 | 477 | } |
| 478 | 478 | $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
| 479 | 479 | if ($plainText !== false) { |
| 480 | - $this->plainBody .= ' * ' . $plainText; |
|
| 480 | + $this->plainBody .= ' * '.$plainText; |
|
| 481 | 481 | if ($plainMetaInfo !== false) { |
| 482 | - $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
| 482 | + $this->plainBody .= ' ('.$plainMetaInfo.')'; |
|
| 483 | 483 | } |
| 484 | 484 | $this->plainBody .= PHP_EOL; |
| 485 | 485 | } |
@@ -540,8 +540,8 @@ discard block |
||
| 540 | 540 | $textColor = $this->themingDefaults->getTextColorPrimary(); |
| 541 | 541 | |
| 542 | 542 | $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
| 543 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 544 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 543 | + $this->plainBody .= $plainTextLeft.': '.$urlLeft.PHP_EOL; |
|
| 544 | + $this->plainBody .= $plainTextRight.': '.$urlRight.PHP_EOL.PHP_EOL; |
|
| 545 | 545 | |
| 546 | 546 | } |
| 547 | 547 | |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
| 574 | 574 | |
| 575 | 575 | if ($plainText !== false) { |
| 576 | - $this->plainBody .= $plainText . ': '; |
|
| 576 | + $this->plainBody .= $plainText.': '; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - $this->plainBody .= $url . PHP_EOL; |
|
| 579 | + $this->plainBody .= $url.PHP_EOL; |
|
| 580 | 580 | |
| 581 | 581 | } |
| 582 | 582 | |
@@ -600,8 +600,8 @@ discard block |
||
| 600 | 600 | * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
| 601 | 601 | */ |
| 602 | 602 | public function addFooter(string $text = '') { |
| 603 | - if($text === '') { |
|
| 604 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 603 | + if ($text === '') { |
|
| 604 | + $text = $this->themingDefaults->getName().' - '.$this->themingDefaults->getSlogan().'<br>'.$this->l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | if ($this->footerAdded) { |
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | |
| 614 | 614 | $this->htmlBody .= vsprintf($this->footer, [$text]); |
| 615 | 615 | $this->htmlBody .= $this->tail; |
| 616 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 616 | + $this->plainBody .= PHP_EOL.'-- '.PHP_EOL; |
|
| 617 | 617 | $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
| 618 | 618 | } |
| 619 | 619 | |
@@ -42,33 +42,33 @@ discard block |
||
| 42 | 42 | * @package OC\Mail |
| 43 | 43 | */ |
| 44 | 44 | class EMailTemplate implements IEMailTemplate { |
| 45 | - /** @var Defaults */ |
|
| 46 | - protected $themingDefaults; |
|
| 47 | - /** @var IURLGenerator */ |
|
| 48 | - protected $urlGenerator; |
|
| 49 | - /** @var IL10N */ |
|
| 50 | - protected $l10n; |
|
| 51 | - /** @var string */ |
|
| 52 | - protected $emailId; |
|
| 53 | - /** @var array */ |
|
| 54 | - protected $data; |
|
| 55 | - |
|
| 56 | - /** @var string */ |
|
| 57 | - protected $subject = ''; |
|
| 58 | - /** @var string */ |
|
| 59 | - protected $htmlBody = ''; |
|
| 60 | - /** @var string */ |
|
| 61 | - protected $plainBody = ''; |
|
| 62 | - /** @var bool indicated if the footer is added */ |
|
| 63 | - protected $headerAdded = false; |
|
| 64 | - /** @var bool indicated if the body is already opened */ |
|
| 65 | - protected $bodyOpened = false; |
|
| 66 | - /** @var bool indicated if there is a list open in the body */ |
|
| 67 | - protected $bodyListOpened = false; |
|
| 68 | - /** @var bool indicated if the footer is added */ |
|
| 69 | - protected $footerAdded = false; |
|
| 70 | - |
|
| 71 | - protected $head = <<<EOF |
|
| 45 | + /** @var Defaults */ |
|
| 46 | + protected $themingDefaults; |
|
| 47 | + /** @var IURLGenerator */ |
|
| 48 | + protected $urlGenerator; |
|
| 49 | + /** @var IL10N */ |
|
| 50 | + protected $l10n; |
|
| 51 | + /** @var string */ |
|
| 52 | + protected $emailId; |
|
| 53 | + /** @var array */ |
|
| 54 | + protected $data; |
|
| 55 | + |
|
| 56 | + /** @var string */ |
|
| 57 | + protected $subject = ''; |
|
| 58 | + /** @var string */ |
|
| 59 | + protected $htmlBody = ''; |
|
| 60 | + /** @var string */ |
|
| 61 | + protected $plainBody = ''; |
|
| 62 | + /** @var bool indicated if the footer is added */ |
|
| 63 | + protected $headerAdded = false; |
|
| 64 | + /** @var bool indicated if the body is already opened */ |
|
| 65 | + protected $bodyOpened = false; |
|
| 66 | + /** @var bool indicated if there is a list open in the body */ |
|
| 67 | + protected $bodyListOpened = false; |
|
| 68 | + /** @var bool indicated if the footer is added */ |
|
| 69 | + protected $footerAdded = false; |
|
| 70 | + |
|
| 71 | + protected $head = <<<EOF |
|
| 72 | 72 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 73 | 73 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#f3f3f3!important"> |
| 74 | 74 | <head> |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | <center data-parsed="" style="min-width:580px;width:100%"> |
| 87 | 87 | EOF; |
| 88 | 88 | |
| 89 | - protected $tail = <<<EOF |
|
| 89 | + protected $tail = <<<EOF |
|
| 90 | 90 | </center> |
| 91 | 91 | </td> |
| 92 | 92 | </tr> |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | </html> |
| 98 | 98 | EOF; |
| 99 | 99 | |
| 100 | - protected $header = <<<EOF |
|
| 100 | + protected $header = <<<EOF |
|
| 101 | 101 | <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#8a8a8a;background-color:%s;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
| 102 | 102 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 103 | 103 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:20px;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | </table> |
| 131 | 131 | EOF; |
| 132 | 132 | |
| 133 | - protected $heading = <<<EOF |
|
| 133 | + protected $heading = <<<EOF |
|
| 134 | 134 | <table align="center" class="container main-heading float-center" style="Margin:0 auto;background:0 0!important;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:580px"> |
| 135 | 135 | <tbody> |
| 136 | 136 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | </table> |
| 150 | 150 | EOF; |
| 151 | 151 | |
| 152 | - protected $bodyBegin = <<<EOF |
|
| 152 | + protected $bodyBegin = <<<EOF |
|
| 153 | 153 | <table align="center" class="wrapper content float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%"> |
| 154 | 154 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 155 | 155 | <td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;hyphens:auto;line-height:1.3;margin:0;padding:0;text-align:left;vertical-align:top;word-wrap:break-word"> |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | </table> |
| 167 | 167 | EOF; |
| 168 | 168 | |
| 169 | - protected $bodyText = <<<EOF |
|
| 169 | + protected $bodyText = <<<EOF |
|
| 170 | 170 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
| 171 | 171 | <tbody> |
| 172 | 172 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | </table> |
| 186 | 186 | EOF; |
| 187 | 187 | |
| 188 | - protected $listBegin = <<<EOF |
|
| 188 | + protected $listBegin = <<<EOF |
|
| 189 | 189 | <table class="row description" style="border-collapse:collapse;border-spacing:0;display:table;padding:0;position:relative;text-align:left;vertical-align:top;width:100%%"> |
| 190 | 190 | <tbody> |
| 191 | 191 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | <table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
| 194 | 194 | EOF; |
| 195 | 195 | |
| 196 | - protected $listItem = <<<EOF |
|
| 196 | + protected $listItem = <<<EOF |
|
| 197 | 197 | <tr style="padding:0;text-align:left;vertical-align:top"> |
| 198 | 198 | <td style="Margin:0;color:#0a0a0a;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;width:15px;"> |
| 199 | 199 | <p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:Lucida Grande,Geneva,Verdana,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0;padding-left:10px;text-align:left">%s</p> |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | </tr> |
| 206 | 206 | EOF; |
| 207 | 207 | |
| 208 | - protected $listEnd = <<<EOF |
|
| 208 | + protected $listEnd = <<<EOF |
|
| 209 | 209 | </table> |
| 210 | 210 | </th> |
| 211 | 211 | </tr> |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | </table> |
| 214 | 214 | EOF; |
| 215 | 215 | |
| 216 | - protected $buttonGroup = <<<EOF |
|
| 216 | + protected $buttonGroup = <<<EOF |
|
| 217 | 217 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
| 218 | 218 | <tbody> |
| 219 | 219 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | </table> |
| 267 | 267 | EOF; |
| 268 | 268 | |
| 269 | - protected $button = <<<EOF |
|
| 269 | + protected $button = <<<EOF |
|
| 270 | 270 | <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%"> |
| 271 | 271 | <tbody> |
| 272 | 272 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | </table> |
| 307 | 307 | EOF; |
| 308 | 308 | |
| 309 | - protected $bodyEnd = <<<EOF |
|
| 309 | + protected $bodyEnd = <<<EOF |
|
| 310 | 310 | |
| 311 | 311 | </td> |
| 312 | 312 | </tr> |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | </table> |
| 318 | 318 | EOF; |
| 319 | 319 | |
| 320 | - protected $footer = <<<EOF |
|
| 320 | + protected $footer = <<<EOF |
|
| 321 | 321 | <table class="spacer float-center" style="Margin:0 auto;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%"> |
| 322 | 322 | <tbody> |
| 323 | 323 | <tr style="padding:0;text-align:left;vertical-align:top"> |
@@ -343,314 +343,314 @@ discard block |
||
| 343 | 343 | </table> |
| 344 | 344 | EOF; |
| 345 | 345 | |
| 346 | - /** |
|
| 347 | - * @param Defaults $themingDefaults |
|
| 348 | - * @param IURLGenerator $urlGenerator |
|
| 349 | - * @param IL10N $l10n |
|
| 350 | - * @param string $emailId |
|
| 351 | - * @param array $data |
|
| 352 | - */ |
|
| 353 | - public function __construct(Defaults $themingDefaults, |
|
| 354 | - IURLGenerator $urlGenerator, |
|
| 355 | - IL10N $l10n, |
|
| 356 | - $emailId, |
|
| 357 | - array $data) { |
|
| 358 | - $this->themingDefaults = $themingDefaults; |
|
| 359 | - $this->urlGenerator = $urlGenerator; |
|
| 360 | - $this->l10n = $l10n; |
|
| 361 | - $this->htmlBody .= $this->head; |
|
| 362 | - $this->emailId = $emailId; |
|
| 363 | - $this->data = $data; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Sets the subject of the email |
|
| 368 | - * |
|
| 369 | - * @param string $subject |
|
| 370 | - */ |
|
| 371 | - public function setSubject(string $subject) { |
|
| 372 | - $this->subject = $subject; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Adds a header to the email |
|
| 377 | - */ |
|
| 378 | - public function addHeader() { |
|
| 379 | - if ($this->headerAdded) { |
|
| 380 | - return; |
|
| 381 | - } |
|
| 382 | - $this->headerAdded = true; |
|
| 383 | - |
|
| 384 | - $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
| 385 | - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * Adds a heading to the email |
|
| 390 | - * |
|
| 391 | - * @param string $title |
|
| 392 | - * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 393 | - * if empty the $title is used, if false none will be used |
|
| 394 | - */ |
|
| 395 | - public function addHeading(string $title, $plainTitle = '') { |
|
| 396 | - if ($this->footerAdded) { |
|
| 397 | - return; |
|
| 398 | - } |
|
| 399 | - if ($plainTitle === '') { |
|
| 400 | - $plainTitle = $title; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
| 404 | - if ($plainTitle !== false) { |
|
| 405 | - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Open the HTML body when it is not already |
|
| 411 | - */ |
|
| 412 | - protected function ensureBodyIsOpened() { |
|
| 413 | - if ($this->bodyOpened) { |
|
| 414 | - return; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $this->htmlBody .= $this->bodyBegin; |
|
| 418 | - $this->bodyOpened = true; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * Adds a paragraph to the body of the email |
|
| 423 | - * |
|
| 424 | - * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 425 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 426 | - * if empty the $text is used, if false none will be used |
|
| 427 | - */ |
|
| 428 | - public function addBodyText(string $text, $plainText = '') { |
|
| 429 | - if ($this->footerAdded) { |
|
| 430 | - return; |
|
| 431 | - } |
|
| 432 | - if ($plainText === '') { |
|
| 433 | - $plainText = $text; |
|
| 434 | - $text = htmlspecialchars($text); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $this->ensureBodyIsOpened(); |
|
| 438 | - |
|
| 439 | - $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
| 440 | - if ($plainText !== false) { |
|
| 441 | - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 442 | - } |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * Adds a list item to the body of the email |
|
| 447 | - * |
|
| 448 | - * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 449 | - * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 450 | - * @param string $icon Absolute path, must be 16*16 pixels |
|
| 451 | - * @param string|bool $plainText Text that is used in the plain text email |
|
| 452 | - * if empty the $text is used, if false none will be used |
|
| 453 | - * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 454 | - * if empty the $metaInfo is used, if false none will be used |
|
| 455 | - * @since 12.0.0 |
|
| 456 | - */ |
|
| 457 | - public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '') { |
|
| 458 | - $this->ensureBodyListOpened(); |
|
| 459 | - |
|
| 460 | - if ($plainText === '') { |
|
| 461 | - $plainText = $text; |
|
| 462 | - $text = htmlspecialchars($text); |
|
| 463 | - } |
|
| 464 | - if ($plainMetaInfo === '') { |
|
| 465 | - $plainMetaInfo = $metaInfo; |
|
| 466 | - $metaInfo = htmlspecialchars($metaInfo); |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - $htmlText = $text; |
|
| 470 | - if ($metaInfo) { |
|
| 471 | - $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
| 472 | - } |
|
| 473 | - if ($icon !== '') { |
|
| 474 | - $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
| 475 | - } else { |
|
| 476 | - $icon = '•'; |
|
| 477 | - } |
|
| 478 | - $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
| 479 | - if ($plainText !== false) { |
|
| 480 | - $this->plainBody .= ' * ' . $plainText; |
|
| 481 | - if ($plainMetaInfo !== false) { |
|
| 482 | - $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
| 483 | - } |
|
| 484 | - $this->plainBody .= PHP_EOL; |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - protected function ensureBodyListOpened() { |
|
| 489 | - if ($this->bodyListOpened) { |
|
| 490 | - return; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - $this->ensureBodyIsOpened(); |
|
| 494 | - $this->bodyListOpened = true; |
|
| 495 | - $this->htmlBody .= $this->listBegin; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - protected function ensureBodyListClosed() { |
|
| 499 | - if (!$this->bodyListOpened) { |
|
| 500 | - return; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - $this->bodyListOpened = false; |
|
| 504 | - $this->htmlBody .= $this->listEnd; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Adds a button group of two buttons to the body of the email |
|
| 509 | - * |
|
| 510 | - * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 511 | - * @param string $urlLeft URL of left button |
|
| 512 | - * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 513 | - * @param string $urlRight URL of right button |
|
| 514 | - * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
| 515 | - * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
| 516 | - */ |
|
| 517 | - public function addBodyButtonGroup(string $textLeft, |
|
| 518 | - string $urlLeft, |
|
| 519 | - string $textRight, |
|
| 520 | - string $urlRight, |
|
| 521 | - string $plainTextLeft = '', |
|
| 522 | - string $plainTextRight = '') { |
|
| 523 | - if ($this->footerAdded) { |
|
| 524 | - return; |
|
| 525 | - } |
|
| 526 | - if ($plainTextLeft === '') { |
|
| 527 | - $plainTextLeft = $textLeft; |
|
| 528 | - $textLeft = htmlspecialchars($textLeft); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - if ($plainTextRight === '') { |
|
| 532 | - $plainTextRight = $textRight; |
|
| 533 | - $textRight = htmlspecialchars($textRight); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - $this->ensureBodyIsOpened(); |
|
| 537 | - $this->ensureBodyListClosed(); |
|
| 538 | - |
|
| 539 | - $color = $this->themingDefaults->getColorPrimary(); |
|
| 540 | - $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 541 | - |
|
| 542 | - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
|
| 543 | - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 544 | - $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 545 | - |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Adds a button to the body of the email |
|
| 550 | - * |
|
| 551 | - * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 552 | - * @param string $url URL of button |
|
| 553 | - * @param string $plainText Text of button in plain text version |
|
| 554 | - * if empty the $text is used, if false none will be used |
|
| 555 | - * |
|
| 556 | - * @since 12.0.0 |
|
| 557 | - */ |
|
| 558 | - public function addBodyButton(string $text, string $url, $plainText = '') { |
|
| 559 | - if ($this->footerAdded) { |
|
| 560 | - return; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - $this->ensureBodyIsOpened(); |
|
| 564 | - $this->ensureBodyListClosed(); |
|
| 565 | - |
|
| 566 | - if ($plainText === '') { |
|
| 567 | - $plainText = $text; |
|
| 568 | - $text = htmlspecialchars($text); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - $color = $this->themingDefaults->getColorPrimary(); |
|
| 572 | - $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 573 | - $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
|
| 574 | - |
|
| 575 | - if ($plainText !== false) { |
|
| 576 | - $this->plainBody .= $plainText . ': '; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - $this->plainBody .= $url . PHP_EOL; |
|
| 580 | - |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - /** |
|
| 584 | - * Close the HTML body when it is open |
|
| 585 | - */ |
|
| 586 | - protected function ensureBodyIsClosed() { |
|
| 587 | - if (!$this->bodyOpened) { |
|
| 588 | - return; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - $this->ensureBodyListClosed(); |
|
| 592 | - |
|
| 593 | - $this->htmlBody .= $this->bodyEnd; |
|
| 594 | - $this->bodyOpened = false; |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 599 | - * |
|
| 600 | - * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 601 | - */ |
|
| 602 | - public function addFooter(string $text = '') { |
|
| 603 | - if($text === '') { |
|
| 604 | - $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - if ($this->footerAdded) { |
|
| 608 | - return; |
|
| 609 | - } |
|
| 610 | - $this->footerAdded = true; |
|
| 611 | - |
|
| 612 | - $this->ensureBodyIsClosed(); |
|
| 613 | - |
|
| 614 | - $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
| 615 | - $this->htmlBody .= $this->tail; |
|
| 616 | - $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 617 | - $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Returns the rendered email subject as string |
|
| 622 | - * |
|
| 623 | - * @return string |
|
| 624 | - */ |
|
| 625 | - public function renderSubject(): string { |
|
| 626 | - return $this->subject; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Returns the rendered HTML email as string |
|
| 631 | - * |
|
| 632 | - * @return string |
|
| 633 | - */ |
|
| 634 | - public function renderHtml(): string { |
|
| 635 | - if (!$this->footerAdded) { |
|
| 636 | - $this->footerAdded = true; |
|
| 637 | - $this->ensureBodyIsClosed(); |
|
| 638 | - $this->htmlBody .= $this->tail; |
|
| 639 | - } |
|
| 640 | - return $this->htmlBody; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - /** |
|
| 644 | - * Returns the rendered plain text email as string |
|
| 645 | - * |
|
| 646 | - * @return string |
|
| 647 | - */ |
|
| 648 | - public function renderText(): string { |
|
| 649 | - if (!$this->footerAdded) { |
|
| 650 | - $this->footerAdded = true; |
|
| 651 | - $this->ensureBodyIsClosed(); |
|
| 652 | - $this->htmlBody .= $this->tail; |
|
| 653 | - } |
|
| 654 | - return $this->plainBody; |
|
| 655 | - } |
|
| 346 | + /** |
|
| 347 | + * @param Defaults $themingDefaults |
|
| 348 | + * @param IURLGenerator $urlGenerator |
|
| 349 | + * @param IL10N $l10n |
|
| 350 | + * @param string $emailId |
|
| 351 | + * @param array $data |
|
| 352 | + */ |
|
| 353 | + public function __construct(Defaults $themingDefaults, |
|
| 354 | + IURLGenerator $urlGenerator, |
|
| 355 | + IL10N $l10n, |
|
| 356 | + $emailId, |
|
| 357 | + array $data) { |
|
| 358 | + $this->themingDefaults = $themingDefaults; |
|
| 359 | + $this->urlGenerator = $urlGenerator; |
|
| 360 | + $this->l10n = $l10n; |
|
| 361 | + $this->htmlBody .= $this->head; |
|
| 362 | + $this->emailId = $emailId; |
|
| 363 | + $this->data = $data; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Sets the subject of the email |
|
| 368 | + * |
|
| 369 | + * @param string $subject |
|
| 370 | + */ |
|
| 371 | + public function setSubject(string $subject) { |
|
| 372 | + $this->subject = $subject; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Adds a header to the email |
|
| 377 | + */ |
|
| 378 | + public function addHeader() { |
|
| 379 | + if ($this->headerAdded) { |
|
| 380 | + return; |
|
| 381 | + } |
|
| 382 | + $this->headerAdded = true; |
|
| 383 | + |
|
| 384 | + $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false)); |
|
| 385 | + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * Adds a heading to the email |
|
| 390 | + * |
|
| 391 | + * @param string $title |
|
| 392 | + * @param string|bool $plainTitle Title that is used in the plain text email |
|
| 393 | + * if empty the $title is used, if false none will be used |
|
| 394 | + */ |
|
| 395 | + public function addHeading(string $title, $plainTitle = '') { |
|
| 396 | + if ($this->footerAdded) { |
|
| 397 | + return; |
|
| 398 | + } |
|
| 399 | + if ($plainTitle === '') { |
|
| 400 | + $plainTitle = $title; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); |
|
| 404 | + if ($plainTitle !== false) { |
|
| 405 | + $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Open the HTML body when it is not already |
|
| 411 | + */ |
|
| 412 | + protected function ensureBodyIsOpened() { |
|
| 413 | + if ($this->bodyOpened) { |
|
| 414 | + return; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $this->htmlBody .= $this->bodyBegin; |
|
| 418 | + $this->bodyOpened = true; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * Adds a paragraph to the body of the email |
|
| 423 | + * |
|
| 424 | + * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 425 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 426 | + * if empty the $text is used, if false none will be used |
|
| 427 | + */ |
|
| 428 | + public function addBodyText(string $text, $plainText = '') { |
|
| 429 | + if ($this->footerAdded) { |
|
| 430 | + return; |
|
| 431 | + } |
|
| 432 | + if ($plainText === '') { |
|
| 433 | + $plainText = $text; |
|
| 434 | + $text = htmlspecialchars($text); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $this->ensureBodyIsOpened(); |
|
| 438 | + |
|
| 439 | + $this->htmlBody .= vsprintf($this->bodyText, [$text]); |
|
| 440 | + if ($plainText !== false) { |
|
| 441 | + $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; |
|
| 442 | + } |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * Adds a list item to the body of the email |
|
| 447 | + * |
|
| 448 | + * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 449 | + * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email |
|
| 450 | + * @param string $icon Absolute path, must be 16*16 pixels |
|
| 451 | + * @param string|bool $plainText Text that is used in the plain text email |
|
| 452 | + * if empty the $text is used, if false none will be used |
|
| 453 | + * @param string|bool $plainMetaInfo Meta info that is used in the plain text email |
|
| 454 | + * if empty the $metaInfo is used, if false none will be used |
|
| 455 | + * @since 12.0.0 |
|
| 456 | + */ |
|
| 457 | + public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '') { |
|
| 458 | + $this->ensureBodyListOpened(); |
|
| 459 | + |
|
| 460 | + if ($plainText === '') { |
|
| 461 | + $plainText = $text; |
|
| 462 | + $text = htmlspecialchars($text); |
|
| 463 | + } |
|
| 464 | + if ($plainMetaInfo === '') { |
|
| 465 | + $plainMetaInfo = $metaInfo; |
|
| 466 | + $metaInfo = htmlspecialchars($metaInfo); |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + $htmlText = $text; |
|
| 470 | + if ($metaInfo) { |
|
| 471 | + $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText; |
|
| 472 | + } |
|
| 473 | + if ($icon !== '') { |
|
| 474 | + $icon = '<img src="' . htmlspecialchars($icon) . '" alt="•">'; |
|
| 475 | + } else { |
|
| 476 | + $icon = '•'; |
|
| 477 | + } |
|
| 478 | + $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); |
|
| 479 | + if ($plainText !== false) { |
|
| 480 | + $this->plainBody .= ' * ' . $plainText; |
|
| 481 | + if ($plainMetaInfo !== false) { |
|
| 482 | + $this->plainBody .= ' (' . $plainMetaInfo . ')'; |
|
| 483 | + } |
|
| 484 | + $this->plainBody .= PHP_EOL; |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + protected function ensureBodyListOpened() { |
|
| 489 | + if ($this->bodyListOpened) { |
|
| 490 | + return; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + $this->ensureBodyIsOpened(); |
|
| 494 | + $this->bodyListOpened = true; |
|
| 495 | + $this->htmlBody .= $this->listBegin; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + protected function ensureBodyListClosed() { |
|
| 499 | + if (!$this->bodyListOpened) { |
|
| 500 | + return; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + $this->bodyListOpened = false; |
|
| 504 | + $this->htmlBody .= $this->listEnd; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Adds a button group of two buttons to the body of the email |
|
| 509 | + * |
|
| 510 | + * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email |
|
| 511 | + * @param string $urlLeft URL of left button |
|
| 512 | + * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email |
|
| 513 | + * @param string $urlRight URL of right button |
|
| 514 | + * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used |
|
| 515 | + * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used |
|
| 516 | + */ |
|
| 517 | + public function addBodyButtonGroup(string $textLeft, |
|
| 518 | + string $urlLeft, |
|
| 519 | + string $textRight, |
|
| 520 | + string $urlRight, |
|
| 521 | + string $plainTextLeft = '', |
|
| 522 | + string $plainTextRight = '') { |
|
| 523 | + if ($this->footerAdded) { |
|
| 524 | + return; |
|
| 525 | + } |
|
| 526 | + if ($plainTextLeft === '') { |
|
| 527 | + $plainTextLeft = $textLeft; |
|
| 528 | + $textLeft = htmlspecialchars($textLeft); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + if ($plainTextRight === '') { |
|
| 532 | + $plainTextRight = $textRight; |
|
| 533 | + $textRight = htmlspecialchars($textRight); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + $this->ensureBodyIsOpened(); |
|
| 537 | + $this->ensureBodyListClosed(); |
|
| 538 | + |
|
| 539 | + $color = $this->themingDefaults->getColorPrimary(); |
|
| 540 | + $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 541 | + |
|
| 542 | + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); |
|
| 543 | + $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; |
|
| 544 | + $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; |
|
| 545 | + |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Adds a button to the body of the email |
|
| 550 | + * |
|
| 551 | + * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email |
|
| 552 | + * @param string $url URL of button |
|
| 553 | + * @param string $plainText Text of button in plain text version |
|
| 554 | + * if empty the $text is used, if false none will be used |
|
| 555 | + * |
|
| 556 | + * @since 12.0.0 |
|
| 557 | + */ |
|
| 558 | + public function addBodyButton(string $text, string $url, $plainText = '') { |
|
| 559 | + if ($this->footerAdded) { |
|
| 560 | + return; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + $this->ensureBodyIsOpened(); |
|
| 564 | + $this->ensureBodyListClosed(); |
|
| 565 | + |
|
| 566 | + if ($plainText === '') { |
|
| 567 | + $plainText = $text; |
|
| 568 | + $text = htmlspecialchars($text); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + $color = $this->themingDefaults->getColorPrimary(); |
|
| 572 | + $textColor = $this->themingDefaults->getTextColorPrimary(); |
|
| 573 | + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]); |
|
| 574 | + |
|
| 575 | + if ($plainText !== false) { |
|
| 576 | + $this->plainBody .= $plainText . ': '; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + $this->plainBody .= $url . PHP_EOL; |
|
| 580 | + |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + /** |
|
| 584 | + * Close the HTML body when it is open |
|
| 585 | + */ |
|
| 586 | + protected function ensureBodyIsClosed() { |
|
| 587 | + if (!$this->bodyOpened) { |
|
| 588 | + return; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + $this->ensureBodyListClosed(); |
|
| 592 | + |
|
| 593 | + $this->htmlBody .= $this->bodyEnd; |
|
| 594 | + $this->bodyOpened = false; |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email |
|
| 599 | + * |
|
| 600 | + * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used |
|
| 601 | + */ |
|
| 602 | + public function addFooter(string $text = '') { |
|
| 603 | + if($text === '') { |
|
| 604 | + $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan() . '<br>' . $this->l10n->t('This is an automatically sent email, please do not reply.'); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + if ($this->footerAdded) { |
|
| 608 | + return; |
|
| 609 | + } |
|
| 610 | + $this->footerAdded = true; |
|
| 611 | + |
|
| 612 | + $this->ensureBodyIsClosed(); |
|
| 613 | + |
|
| 614 | + $this->htmlBody .= vsprintf($this->footer, [$text]); |
|
| 615 | + $this->htmlBody .= $this->tail; |
|
| 616 | + $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; |
|
| 617 | + $this->plainBody .= str_replace('<br>', PHP_EOL, $text); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Returns the rendered email subject as string |
|
| 622 | + * |
|
| 623 | + * @return string |
|
| 624 | + */ |
|
| 625 | + public function renderSubject(): string { |
|
| 626 | + return $this->subject; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Returns the rendered HTML email as string |
|
| 631 | + * |
|
| 632 | + * @return string |
|
| 633 | + */ |
|
| 634 | + public function renderHtml(): string { |
|
| 635 | + if (!$this->footerAdded) { |
|
| 636 | + $this->footerAdded = true; |
|
| 637 | + $this->ensureBodyIsClosed(); |
|
| 638 | + $this->htmlBody .= $this->tail; |
|
| 639 | + } |
|
| 640 | + return $this->htmlBody; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + /** |
|
| 644 | + * Returns the rendered plain text email as string |
|
| 645 | + * |
|
| 646 | + * @return string |
|
| 647 | + */ |
|
| 648 | + public function renderText(): string { |
|
| 649 | + if (!$this->footerAdded) { |
|
| 650 | + $this->footerAdded = true; |
|
| 651 | + $this->ensureBodyIsClosed(); |
|
| 652 | + $this->htmlBody .= $this->tail; |
|
| 653 | + } |
|
| 654 | + return $this->plainBody; |
|
| 655 | + } |
|
| 656 | 656 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | $convertedAddresses = []; |
| 74 | 74 | |
| 75 | - foreach($addresses as $email => $readableName) { |
|
| 76 | - if(!is_numeric($email)) { |
|
| 75 | + foreach ($addresses as $email => $readableName) { |
|
| 76 | + if (!is_numeric($email)) { |
|
| 77 | 77 | list($name, $domain) = explode('@', $email, 2); |
| 78 | 78 | $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
| 79 | 79 | $convertedAddresses[$name.'@'.$domain] = $readableName; |
@@ -37,245 +37,245 @@ |
||
| 37 | 37 | * @package OC\Mail |
| 38 | 38 | */ |
| 39 | 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) { |
|
| 47 | - $this->swiftMessage = $swiftMessage; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param IAttachment $attachment |
|
| 52 | - * @return $this |
|
| 53 | - * @since 13.0.0 |
|
| 54 | - */ |
|
| 55 | - public function attach(IAttachment $attachment): IMessage { |
|
| 56 | - /** @var Attachment $attachment */ |
|
| 57 | - $this->swiftMessage->attach($attachment->getSwiftAttachment()); |
|
| 58 | - return $this; |
|
| 59 | - } |
|
| 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')) { |
|
| 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 { |
|
| 99 | - $addresses = $this->convertAddresses($addresses); |
|
| 100 | - |
|
| 101 | - $this->swiftMessage->setFrom($addresses); |
|
| 102 | - return $this; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Get the from address of this message. |
|
| 107 | - * |
|
| 108 | - * @return array |
|
| 109 | - */ |
|
| 110 | - public function getFrom(): array { |
|
| 111 | - return $this->swiftMessage->getFrom(); |
|
| 112 | - } |
|
| 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 { |
|
| 121 | - $addresses = $this->convertAddresses($addresses); |
|
| 122 | - |
|
| 123 | - $this->swiftMessage->setReplyTo($addresses); |
|
| 124 | - return $this; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Returns the Reply-To address of this message |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function getReplyTo(): string { |
|
| 133 | - return $this->swiftMessage->getReplyTo(); |
|
| 134 | - } |
|
| 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 { |
|
| 143 | - $recipients = $this->convertAddresses($recipients); |
|
| 144 | - |
|
| 145 | - $this->swiftMessage->setTo($recipients); |
|
| 146 | - return $this; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Get the to address of this message. |
|
| 151 | - * |
|
| 152 | - * @return array |
|
| 153 | - */ |
|
| 154 | - public function getTo(): array { |
|
| 155 | - return $this->swiftMessage->getTo(); |
|
| 156 | - } |
|
| 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 { |
|
| 165 | - $recipients = $this->convertAddresses($recipients); |
|
| 166 | - |
|
| 167 | - $this->swiftMessage->setCc($recipients); |
|
| 168 | - return $this; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Get the cc address of this message. |
|
| 173 | - * |
|
| 174 | - * @return array |
|
| 175 | - */ |
|
| 176 | - public function getCc(): array { |
|
| 177 | - return $this->swiftMessage->getCc(); |
|
| 178 | - } |
|
| 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 { |
|
| 187 | - $recipients = $this->convertAddresses($recipients); |
|
| 188 | - |
|
| 189 | - $this->swiftMessage->setBcc($recipients); |
|
| 190 | - return $this; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Get the Bcc address of this message. |
|
| 195 | - * |
|
| 196 | - * @return array |
|
| 197 | - */ |
|
| 198 | - public function getBcc(): array { |
|
| 199 | - return $this->swiftMessage->getBcc(); |
|
| 200 | - } |
|
| 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 { |
|
| 209 | - $this->swiftMessage->setSubject($subject); |
|
| 210 | - return $this; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Get the from subject of this message. |
|
| 215 | - * |
|
| 216 | - * @return string |
|
| 217 | - */ |
|
| 218 | - public function getSubject(): string { |
|
| 219 | - return $this->swiftMessage->getSubject(); |
|
| 220 | - } |
|
| 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 { |
|
| 229 | - $this->swiftMessage->setBody($body); |
|
| 230 | - return $this; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Get the plain body of this message. |
|
| 235 | - * |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function getPlainBody(): string { |
|
| 239 | - return $this->swiftMessage->getBody(); |
|
| 240 | - } |
|
| 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) { |
|
| 249 | - $this->swiftMessage->addPart($body, 'text/html'); |
|
| 250 | - return $this; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Get's the underlying SwiftMessage |
|
| 255 | - * @return Swift_Message |
|
| 256 | - */ |
|
| 257 | - public function getSwiftMessage(): Swift_Message { |
|
| 258 | - return $this->swiftMessage; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @param string $body |
|
| 263 | - * @param string $contentType |
|
| 264 | - * @return $this |
|
| 265 | - */ |
|
| 266 | - public function setBody($body, $contentType) { |
|
| 267 | - $this->swiftMessage->setBody($body, $contentType); |
|
| 268 | - return $this; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @param IEMailTemplate $emailTemplate |
|
| 273 | - * @return $this |
|
| 274 | - */ |
|
| 275 | - public function useTemplate(IEMailTemplate $emailTemplate): IMessage { |
|
| 276 | - $this->setSubject($emailTemplate->renderSubject()); |
|
| 277 | - $this->setPlainBody($emailTemplate->renderText()); |
|
| 278 | - $this->setHtmlBody($emailTemplate->renderHtml()); |
|
| 279 | - return $this; |
|
| 280 | - } |
|
| 40 | + /** @var Swift_Message */ |
|
| 41 | + private $swiftMessage; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @param Swift_Message $swiftMessage |
|
| 45 | + */ |
|
| 46 | + public function __construct(Swift_Message $swiftMessage) { |
|
| 47 | + $this->swiftMessage = $swiftMessage; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param IAttachment $attachment |
|
| 52 | + * @return $this |
|
| 53 | + * @since 13.0.0 |
|
| 54 | + */ |
|
| 55 | + public function attach(IAttachment $attachment): IMessage { |
|
| 56 | + /** @var Attachment $attachment */ |
|
| 57 | + $this->swiftMessage->attach($attachment->getSwiftAttachment()); |
|
| 58 | + return $this; |
|
| 59 | + } |
|
| 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')) { |
|
| 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 { |
|
| 99 | + $addresses = $this->convertAddresses($addresses); |
|
| 100 | + |
|
| 101 | + $this->swiftMessage->setFrom($addresses); |
|
| 102 | + return $this; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Get the from address of this message. |
|
| 107 | + * |
|
| 108 | + * @return array |
|
| 109 | + */ |
|
| 110 | + public function getFrom(): array { |
|
| 111 | + return $this->swiftMessage->getFrom(); |
|
| 112 | + } |
|
| 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 { |
|
| 121 | + $addresses = $this->convertAddresses($addresses); |
|
| 122 | + |
|
| 123 | + $this->swiftMessage->setReplyTo($addresses); |
|
| 124 | + return $this; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Returns the Reply-To address of this message |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function getReplyTo(): string { |
|
| 133 | + return $this->swiftMessage->getReplyTo(); |
|
| 134 | + } |
|
| 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 { |
|
| 143 | + $recipients = $this->convertAddresses($recipients); |
|
| 144 | + |
|
| 145 | + $this->swiftMessage->setTo($recipients); |
|
| 146 | + return $this; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Get the to address of this message. |
|
| 151 | + * |
|
| 152 | + * @return array |
|
| 153 | + */ |
|
| 154 | + public function getTo(): array { |
|
| 155 | + return $this->swiftMessage->getTo(); |
|
| 156 | + } |
|
| 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 { |
|
| 165 | + $recipients = $this->convertAddresses($recipients); |
|
| 166 | + |
|
| 167 | + $this->swiftMessage->setCc($recipients); |
|
| 168 | + return $this; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Get the cc address of this message. |
|
| 173 | + * |
|
| 174 | + * @return array |
|
| 175 | + */ |
|
| 176 | + public function getCc(): array { |
|
| 177 | + return $this->swiftMessage->getCc(); |
|
| 178 | + } |
|
| 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 { |
|
| 187 | + $recipients = $this->convertAddresses($recipients); |
|
| 188 | + |
|
| 189 | + $this->swiftMessage->setBcc($recipients); |
|
| 190 | + return $this; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Get the Bcc address of this message. |
|
| 195 | + * |
|
| 196 | + * @return array |
|
| 197 | + */ |
|
| 198 | + public function getBcc(): array { |
|
| 199 | + return $this->swiftMessage->getBcc(); |
|
| 200 | + } |
|
| 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 { |
|
| 209 | + $this->swiftMessage->setSubject($subject); |
|
| 210 | + return $this; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Get the from subject of this message. |
|
| 215 | + * |
|
| 216 | + * @return string |
|
| 217 | + */ |
|
| 218 | + public function getSubject(): string { |
|
| 219 | + return $this->swiftMessage->getSubject(); |
|
| 220 | + } |
|
| 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 { |
|
| 229 | + $this->swiftMessage->setBody($body); |
|
| 230 | + return $this; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Get the plain body of this message. |
|
| 235 | + * |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function getPlainBody(): string { |
|
| 239 | + return $this->swiftMessage->getBody(); |
|
| 240 | + } |
|
| 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) { |
|
| 249 | + $this->swiftMessage->addPart($body, 'text/html'); |
|
| 250 | + return $this; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Get's the underlying SwiftMessage |
|
| 255 | + * @return Swift_Message |
|
| 256 | + */ |
|
| 257 | + public function getSwiftMessage(): Swift_Message { |
|
| 258 | + return $this->swiftMessage; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @param string $body |
|
| 263 | + * @param string $contentType |
|
| 264 | + * @return $this |
|
| 265 | + */ |
|
| 266 | + public function setBody($body, $contentType) { |
|
| 267 | + $this->swiftMessage->setBody($body, $contentType); |
|
| 268 | + return $this; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @param IEMailTemplate $emailTemplate |
|
| 273 | + * @return $this |
|
| 274 | + */ |
|
| 275 | + public function useTemplate(IEMailTemplate $emailTemplate): IMessage { |
|
| 276 | + $this->setSubject($emailTemplate->renderSubject()); |
|
| 277 | + $this->setPlainBody($emailTemplate->renderText()); |
|
| 278 | + $this->setHtmlBody($emailTemplate->renderHtml()); |
|
| 279 | + return $this; |
|
| 280 | + } |
|
| 281 | 281 | } |