@@ -29,25 +29,25 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface IAttachment { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param string $filename |
|
| 34 | - * @return $this |
|
| 35 | - * @since 13.0.0 |
|
| 36 | - */ |
|
| 37 | - public function setFilename($filename); |
|
| 32 | + /** |
|
| 33 | + * @param string $filename |
|
| 34 | + * @return $this |
|
| 35 | + * @since 13.0.0 |
|
| 36 | + */ |
|
| 37 | + public function setFilename($filename); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param string $contentType |
|
| 41 | - * @return $this |
|
| 42 | - * @since 13.0.0 |
|
| 43 | - */ |
|
| 44 | - public function setContentType($contentType); |
|
| 39 | + /** |
|
| 40 | + * @param string $contentType |
|
| 41 | + * @return $this |
|
| 42 | + * @since 13.0.0 |
|
| 43 | + */ |
|
| 44 | + public function setContentType($contentType); |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @param string $body |
|
| 48 | - * @return $this |
|
| 49 | - * @since 13.0.0 |
|
| 50 | - */ |
|
| 51 | - public function setBody($body); |
|
| 46 | + /** |
|
| 47 | + * @param string $body |
|
| 48 | + * @return $this |
|
| 49 | + * @since 13.0.0 |
|
| 50 | + */ |
|
| 51 | + public function setBody($body); |
|
| 52 | 52 | |
| 53 | 53 | } |
@@ -31,48 +31,48 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class Attachment implements IAttachment { |
| 33 | 33 | |
| 34 | - /** @var \Swift_Mime_Attachment */ |
|
| 35 | - protected $swiftAttachment; |
|
| 34 | + /** @var \Swift_Mime_Attachment */ |
|
| 35 | + protected $swiftAttachment; |
|
| 36 | 36 | |
| 37 | - public function __construct(\Swift_Mime_Attachment $attachment) { |
|
| 38 | - $this->swiftAttachment = $attachment; |
|
| 39 | - } |
|
| 37 | + public function __construct(\Swift_Mime_Attachment $attachment) { |
|
| 38 | + $this->swiftAttachment = $attachment; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $filename |
|
| 43 | - * @return $this |
|
| 44 | - * @since 13.0.0 |
|
| 45 | - */ |
|
| 46 | - public function setFilename($filename) { |
|
| 47 | - $this->swiftAttachment->setFilename($filename); |
|
| 48 | - return $this; |
|
| 49 | - } |
|
| 41 | + /** |
|
| 42 | + * @param string $filename |
|
| 43 | + * @return $this |
|
| 44 | + * @since 13.0.0 |
|
| 45 | + */ |
|
| 46 | + public function setFilename($filename) { |
|
| 47 | + $this->swiftAttachment->setFilename($filename); |
|
| 48 | + return $this; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param string $contentType |
|
| 53 | - * @return $this |
|
| 54 | - * @since 13.0.0 |
|
| 55 | - */ |
|
| 56 | - public function setContentType($contentType) { |
|
| 57 | - $this->swiftAttachment->setContentType($contentType); |
|
| 58 | - return $this; |
|
| 59 | - } |
|
| 51 | + /** |
|
| 52 | + * @param string $contentType |
|
| 53 | + * @return $this |
|
| 54 | + * @since 13.0.0 |
|
| 55 | + */ |
|
| 56 | + public function setContentType($contentType) { |
|
| 57 | + $this->swiftAttachment->setContentType($contentType); |
|
| 58 | + return $this; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @param string $body |
|
| 63 | - * @return $this |
|
| 64 | - * @since 13.0.0 |
|
| 65 | - */ |
|
| 66 | - public function setBody($body) { |
|
| 67 | - $this->swiftAttachment->setBody($body); |
|
| 68 | - return $this; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * @param string $body |
|
| 63 | + * @return $this |
|
| 64 | + * @since 13.0.0 |
|
| 65 | + */ |
|
| 66 | + public function setBody($body) { |
|
| 67 | + $this->swiftAttachment->setBody($body); |
|
| 68 | + return $this; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return \Swift_Mime_Attachment |
|
| 73 | - */ |
|
| 74 | - public function getSwiftAttachment() { |
|
| 75 | - return $this->swiftAttachment; |
|
| 76 | - } |
|
| 71 | + /** |
|
| 72 | + * @return \Swift_Mime_Attachment |
|
| 73 | + */ |
|
| 74 | + public function getSwiftAttachment() { |
|
| 75 | + return $this->swiftAttachment; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |
@@ -29,81 +29,81 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | interface IMessage { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param string|null $data |
|
| 34 | - * @param string|null $filename |
|
| 35 | - * @param string|null $contentType |
|
| 36 | - * @return IAttachment |
|
| 37 | - * @since 13.0.0 |
|
| 38 | - */ |
|
| 39 | - public function createAttachment($data = null, $filename = null, $contentType = null); |
|
| 32 | + /** |
|
| 33 | + * @param string|null $data |
|
| 34 | + * @param string|null $filename |
|
| 35 | + * @param string|null $contentType |
|
| 36 | + * @return IAttachment |
|
| 37 | + * @since 13.0.0 |
|
| 38 | + */ |
|
| 39 | + public function createAttachment($data = null, $filename = null, $contentType = null); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $path |
|
| 43 | - * @param string|null $contentType |
|
| 44 | - * @return IAttachment |
|
| 45 | - * @since 13.0.0 |
|
| 46 | - */ |
|
| 47 | - public function createAttachmentFromPath($path, $contentType = null); |
|
| 41 | + /** |
|
| 42 | + * @param string $path |
|
| 43 | + * @param string|null $contentType |
|
| 44 | + * @return IAttachment |
|
| 45 | + * @since 13.0.0 |
|
| 46 | + */ |
|
| 47 | + public function createAttachmentFromPath($path, $contentType = null); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @param IAttachment $attachment |
|
| 51 | - * @return $this |
|
| 52 | - * @since 13.0.0 |
|
| 53 | - */ |
|
| 54 | - public function attach(IAttachment $attachment); |
|
| 49 | + /** |
|
| 50 | + * @param IAttachment $attachment |
|
| 51 | + * @return $this |
|
| 52 | + * @since 13.0.0 |
|
| 53 | + */ |
|
| 54 | + public function attach(IAttachment $attachment); |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Set the from address of this message. |
|
| 58 | - * |
|
| 59 | - * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 60 | - * |
|
| 61 | - * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 62 | - * @return $this |
|
| 63 | - * @since 13.0.0 |
|
| 64 | - */ |
|
| 65 | - public function setFrom(array $addresses); |
|
| 56 | + /** |
|
| 57 | + * Set the from address of this message. |
|
| 58 | + * |
|
| 59 | + * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 60 | + * |
|
| 61 | + * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 62 | + * @return $this |
|
| 63 | + * @since 13.0.0 |
|
| 64 | + */ |
|
| 65 | + public function setFrom(array $addresses); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Set the Reply-To address of this message |
|
| 69 | - * |
|
| 70 | - * @param array $addresses |
|
| 71 | - * @return $this |
|
| 72 | - * @since 13.0.0 |
|
| 73 | - */ |
|
| 74 | - public function setReplyTo(array $addresses); |
|
| 67 | + /** |
|
| 68 | + * Set the Reply-To address of this message |
|
| 69 | + * |
|
| 70 | + * @param array $addresses |
|
| 71 | + * @return $this |
|
| 72 | + * @since 13.0.0 |
|
| 73 | + */ |
|
| 74 | + public function setReplyTo(array $addresses); |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Set the to addresses of this message. |
|
| 78 | - * |
|
| 79 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 80 | - * @return $this |
|
| 81 | - * @since 13.0.0 |
|
| 82 | - */ |
|
| 83 | - public function setTo(array $recipients); |
|
| 76 | + /** |
|
| 77 | + * Set the to addresses of this message. |
|
| 78 | + * |
|
| 79 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 80 | + * @return $this |
|
| 81 | + * @since 13.0.0 |
|
| 82 | + */ |
|
| 83 | + public function setTo(array $recipients); |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Set the CC recipients of this message. |
|
| 87 | - * |
|
| 88 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 89 | - * @return $this |
|
| 90 | - * @since 13.0.0 |
|
| 91 | - */ |
|
| 92 | - public function setCc(array $recipients); |
|
| 85 | + /** |
|
| 86 | + * Set the CC recipients of this message. |
|
| 87 | + * |
|
| 88 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 89 | + * @return $this |
|
| 90 | + * @since 13.0.0 |
|
| 91 | + */ |
|
| 92 | + public function setCc(array $recipients); |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Set the BCC recipients of this message. |
|
| 96 | - * |
|
| 97 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 98 | - * @return $this |
|
| 99 | - * @since 13.0.0 |
|
| 100 | - */ |
|
| 101 | - public function setBcc(array $recipients); |
|
| 94 | + /** |
|
| 95 | + * Set the BCC recipients of this message. |
|
| 96 | + * |
|
| 97 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 98 | + * @return $this |
|
| 99 | + * @since 13.0.0 |
|
| 100 | + */ |
|
| 101 | + public function setBcc(array $recipients); |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @param IEMailTemplate $emailTemplate |
|
| 105 | - * @return $this |
|
| 106 | - * @since 13.0.0 |
|
| 107 | - */ |
|
| 108 | - public function useTemplate(IEMailTemplate $emailTemplate); |
|
| 103 | + /** |
|
| 104 | + * @param IEMailTemplate $emailTemplate |
|
| 105 | + * @return $this |
|
| 106 | + * @since 13.0.0 |
|
| 107 | + */ |
|
| 108 | + public function useTemplate(IEMailTemplate $emailTemplate); |
|
| 109 | 109 | } |
@@ -34,266 +34,266 @@ |
||
| 34 | 34 | * @package OC\Mail |
| 35 | 35 | */ |
| 36 | 36 | class Message implements IMessage { |
| 37 | - /** @var Swift_Message */ |
|
| 38 | - private $swiftMessage; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param Swift_Message $swiftMessage |
|
| 42 | - */ |
|
| 43 | - public function __construct(Swift_Message $swiftMessage) { |
|
| 44 | - $this->swiftMessage = $swiftMessage; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param string|null $data |
|
| 49 | - * @param string|null $filename |
|
| 50 | - * @param string|null $contentType |
|
| 51 | - * @return IAttachment |
|
| 52 | - * @since 13.0.0 |
|
| 53 | - */ |
|
| 54 | - public function createAttachment($data = null, $filename = null, $contentType = null) { |
|
| 55 | - return new Attachment(\Swift_Attachment::newInstance($data, $filename, $contentType)); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @param string $path |
|
| 60 | - * @param string|null $contentType |
|
| 61 | - * @return IAttachment |
|
| 62 | - * @since 13.0.0 |
|
| 63 | - */ |
|
| 64 | - public function createAttachmentFromPath($path, $contentType = null) { |
|
| 65 | - return new Attachment(\Swift_Attachment::fromPath($path, $contentType)); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param IAttachment $attachment |
|
| 70 | - * @return $this |
|
| 71 | - * @since 13.0.0 |
|
| 72 | - */ |
|
| 73 | - public function attach(IAttachment $attachment) { |
|
| 74 | - /** @var Attachment $attachment */ |
|
| 75 | - $this->swiftMessage->attach($attachment->getSwiftAttachment()); |
|
| 76 | - return $this; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
| 81 | - * FIXME: Remove this once SwiftMailer supports IDN |
|
| 82 | - * |
|
| 83 | - * @param array $addresses Array of mail addresses, key will get converted |
|
| 84 | - * @return array Converted addresses if `idn_to_ascii` exists |
|
| 85 | - */ |
|
| 86 | - protected function convertAddresses($addresses) { |
|
| 87 | - if (!function_exists('idn_to_ascii')) { |
|
| 88 | - return $addresses; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $convertedAddresses = array(); |
|
| 92 | - |
|
| 93 | - foreach($addresses as $email => $readableName) { |
|
| 94 | - if(!is_numeric($email)) { |
|
| 95 | - list($name, $domain) = explode('@', $email, 2); |
|
| 96 | - $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
|
| 97 | - $convertedAddresses[$name.'@'.$domain] = $readableName; |
|
| 98 | - } else { |
|
| 99 | - list($name, $domain) = explode('@', $readableName, 2); |
|
| 100 | - $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
|
| 101 | - $convertedAddresses[$email] = $name.'@'.$domain; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return $convertedAddresses; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Set the from address of this message. |
|
| 110 | - * |
|
| 111 | - * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 112 | - * |
|
| 113 | - * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 114 | - * @return $this |
|
| 115 | - */ |
|
| 116 | - public function setFrom(array $addresses) { |
|
| 117 | - $addresses = $this->convertAddresses($addresses); |
|
| 118 | - |
|
| 119 | - $this->swiftMessage->setFrom($addresses); |
|
| 120 | - return $this; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get the from address of this message. |
|
| 125 | - * |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - public function getFrom() { |
|
| 129 | - return $this->swiftMessage->getFrom(); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Set the Reply-To address of this message |
|
| 134 | - * |
|
| 135 | - * @param array $addresses |
|
| 136 | - * @return $this |
|
| 137 | - */ |
|
| 138 | - public function setReplyTo(array $addresses) { |
|
| 139 | - $addresses = $this->convertAddresses($addresses); |
|
| 140 | - |
|
| 141 | - $this->swiftMessage->setReplyTo($addresses); |
|
| 142 | - return $this; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Returns the Reply-To address of this message |
|
| 147 | - * |
|
| 148 | - * @return array |
|
| 149 | - */ |
|
| 150 | - public function getReplyTo() { |
|
| 151 | - return $this->swiftMessage->getReplyTo(); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Set the to addresses of this message. |
|
| 156 | - * |
|
| 157 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 158 | - * @return $this |
|
| 159 | - */ |
|
| 160 | - public function setTo(array $recipients) { |
|
| 161 | - $recipients = $this->convertAddresses($recipients); |
|
| 162 | - |
|
| 163 | - $this->swiftMessage->setTo($recipients); |
|
| 164 | - return $this; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Get the to address of this message. |
|
| 169 | - * |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function getTo() { |
|
| 173 | - return $this->swiftMessage->getTo(); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Set the CC recipients of this message. |
|
| 178 | - * |
|
| 179 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 180 | - * @return $this |
|
| 181 | - */ |
|
| 182 | - public function setCc(array $recipients) { |
|
| 183 | - $recipients = $this->convertAddresses($recipients); |
|
| 184 | - |
|
| 185 | - $this->swiftMessage->setCc($recipients); |
|
| 186 | - return $this; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the cc address of this message. |
|
| 191 | - * |
|
| 192 | - * @return array |
|
| 193 | - */ |
|
| 194 | - public function getCc() { |
|
| 195 | - return $this->swiftMessage->getCc(); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Set the BCC recipients of this message. |
|
| 200 | - * |
|
| 201 | - * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 202 | - * @return $this |
|
| 203 | - */ |
|
| 204 | - public function setBcc(array $recipients) { |
|
| 205 | - $recipients = $this->convertAddresses($recipients); |
|
| 206 | - |
|
| 207 | - $this->swiftMessage->setBcc($recipients); |
|
| 208 | - return $this; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Get the Bcc address of this message. |
|
| 213 | - * |
|
| 214 | - * @return array |
|
| 215 | - */ |
|
| 216 | - public function getBcc() { |
|
| 217 | - return $this->swiftMessage->getBcc(); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Set the subject of this message. |
|
| 222 | - * |
|
| 223 | - * @param $subject |
|
| 224 | - * @return $this |
|
| 225 | - */ |
|
| 226 | - public function setSubject($subject) { |
|
| 227 | - $this->swiftMessage->setSubject($subject); |
|
| 228 | - return $this; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Get the from subject of this message. |
|
| 233 | - * |
|
| 234 | - * @return string |
|
| 235 | - */ |
|
| 236 | - public function getSubject() { |
|
| 237 | - return $this->swiftMessage->getSubject(); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Set the plain-text body of this message. |
|
| 242 | - * |
|
| 243 | - * @param string $body |
|
| 244 | - * @return $this |
|
| 245 | - */ |
|
| 246 | - public function setPlainBody($body) { |
|
| 247 | - $this->swiftMessage->setBody($body); |
|
| 248 | - return $this; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Get the plain body of this message. |
|
| 253 | - * |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 256 | - public function getPlainBody() { |
|
| 257 | - return $this->swiftMessage->getBody(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one. |
|
| 262 | - * |
|
| 263 | - * @param string $body |
|
| 264 | - * @return $this |
|
| 265 | - */ |
|
| 266 | - public function setHtmlBody($body) { |
|
| 267 | - $this->swiftMessage->addPart($body, 'text/html'); |
|
| 268 | - return $this; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Get's the underlying SwiftMessage |
|
| 273 | - * @return Swift_Message |
|
| 274 | - */ |
|
| 275 | - public function getSwiftMessage() { |
|
| 276 | - return $this->swiftMessage; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @param string $body |
|
| 281 | - * @param string $contentType |
|
| 282 | - * @return $this |
|
| 283 | - */ |
|
| 284 | - public function setBody($body, $contentType) { |
|
| 285 | - $this->swiftMessage->setBody($body, $contentType); |
|
| 286 | - return $this; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @param IEMailTemplate $emailTemplate |
|
| 291 | - * @return $this |
|
| 292 | - */ |
|
| 293 | - public function useTemplate(IEMailTemplate $emailTemplate) { |
|
| 294 | - $this->setSubject($emailTemplate->renderSubject()); |
|
| 295 | - $this->setPlainBody($emailTemplate->renderText()); |
|
| 296 | - $this->setHtmlBody($emailTemplate->renderHtml()); |
|
| 297 | - return $this; |
|
| 298 | - } |
|
| 37 | + /** @var Swift_Message */ |
|
| 38 | + private $swiftMessage; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param Swift_Message $swiftMessage |
|
| 42 | + */ |
|
| 43 | + public function __construct(Swift_Message $swiftMessage) { |
|
| 44 | + $this->swiftMessage = $swiftMessage; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param string|null $data |
|
| 49 | + * @param string|null $filename |
|
| 50 | + * @param string|null $contentType |
|
| 51 | + * @return IAttachment |
|
| 52 | + * @since 13.0.0 |
|
| 53 | + */ |
|
| 54 | + public function createAttachment($data = null, $filename = null, $contentType = null) { |
|
| 55 | + return new Attachment(\Swift_Attachment::newInstance($data, $filename, $contentType)); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @param string $path |
|
| 60 | + * @param string|null $contentType |
|
| 61 | + * @return IAttachment |
|
| 62 | + * @since 13.0.0 |
|
| 63 | + */ |
|
| 64 | + public function createAttachmentFromPath($path, $contentType = null) { |
|
| 65 | + return new Attachment(\Swift_Attachment::fromPath($path, $contentType)); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param IAttachment $attachment |
|
| 70 | + * @return $this |
|
| 71 | + * @since 13.0.0 |
|
| 72 | + */ |
|
| 73 | + public function attach(IAttachment $attachment) { |
|
| 74 | + /** @var Attachment $attachment */ |
|
| 75 | + $this->swiftMessage->attach($attachment->getSwiftAttachment()); |
|
| 76 | + return $this; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains |
|
| 81 | + * FIXME: Remove this once SwiftMailer supports IDN |
|
| 82 | + * |
|
| 83 | + * @param array $addresses Array of mail addresses, key will get converted |
|
| 84 | + * @return array Converted addresses if `idn_to_ascii` exists |
|
| 85 | + */ |
|
| 86 | + protected function convertAddresses($addresses) { |
|
| 87 | + if (!function_exists('idn_to_ascii')) { |
|
| 88 | + return $addresses; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $convertedAddresses = array(); |
|
| 92 | + |
|
| 93 | + foreach($addresses as $email => $readableName) { |
|
| 94 | + if(!is_numeric($email)) { |
|
| 95 | + list($name, $domain) = explode('@', $email, 2); |
|
| 96 | + $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
|
| 97 | + $convertedAddresses[$name.'@'.$domain] = $readableName; |
|
| 98 | + } else { |
|
| 99 | + list($name, $domain) = explode('@', $readableName, 2); |
|
| 100 | + $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46); |
|
| 101 | + $convertedAddresses[$email] = $name.'@'.$domain; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return $convertedAddresses; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Set the from address of this message. |
|
| 110 | + * |
|
| 111 | + * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php |
|
| 112 | + * |
|
| 113 | + * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 114 | + * @return $this |
|
| 115 | + */ |
|
| 116 | + public function setFrom(array $addresses) { |
|
| 117 | + $addresses = $this->convertAddresses($addresses); |
|
| 118 | + |
|
| 119 | + $this->swiftMessage->setFrom($addresses); |
|
| 120 | + return $this; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get the from address of this message. |
|
| 125 | + * |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + public function getFrom() { |
|
| 129 | + return $this->swiftMessage->getFrom(); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Set the Reply-To address of this message |
|
| 134 | + * |
|
| 135 | + * @param array $addresses |
|
| 136 | + * @return $this |
|
| 137 | + */ |
|
| 138 | + public function setReplyTo(array $addresses) { |
|
| 139 | + $addresses = $this->convertAddresses($addresses); |
|
| 140 | + |
|
| 141 | + $this->swiftMessage->setReplyTo($addresses); |
|
| 142 | + return $this; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Returns the Reply-To address of this message |
|
| 147 | + * |
|
| 148 | + * @return array |
|
| 149 | + */ |
|
| 150 | + public function getReplyTo() { |
|
| 151 | + return $this->swiftMessage->getReplyTo(); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Set the to addresses of this message. |
|
| 156 | + * |
|
| 157 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 158 | + * @return $this |
|
| 159 | + */ |
|
| 160 | + public function setTo(array $recipients) { |
|
| 161 | + $recipients = $this->convertAddresses($recipients); |
|
| 162 | + |
|
| 163 | + $this->swiftMessage->setTo($recipients); |
|
| 164 | + return $this; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Get the to address of this message. |
|
| 169 | + * |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function getTo() { |
|
| 173 | + return $this->swiftMessage->getTo(); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Set the CC recipients of this message. |
|
| 178 | + * |
|
| 179 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 180 | + * @return $this |
|
| 181 | + */ |
|
| 182 | + public function setCc(array $recipients) { |
|
| 183 | + $recipients = $this->convertAddresses($recipients); |
|
| 184 | + |
|
| 185 | + $this->swiftMessage->setCc($recipients); |
|
| 186 | + return $this; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the cc address of this message. |
|
| 191 | + * |
|
| 192 | + * @return array |
|
| 193 | + */ |
|
| 194 | + public function getCc() { |
|
| 195 | + return $this->swiftMessage->getCc(); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Set the BCC recipients of this message. |
|
| 200 | + * |
|
| 201 | + * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name') |
|
| 202 | + * @return $this |
|
| 203 | + */ |
|
| 204 | + public function setBcc(array $recipients) { |
|
| 205 | + $recipients = $this->convertAddresses($recipients); |
|
| 206 | + |
|
| 207 | + $this->swiftMessage->setBcc($recipients); |
|
| 208 | + return $this; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Get the Bcc address of this message. |
|
| 213 | + * |
|
| 214 | + * @return array |
|
| 215 | + */ |
|
| 216 | + public function getBcc() { |
|
| 217 | + return $this->swiftMessage->getBcc(); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Set the subject of this message. |
|
| 222 | + * |
|
| 223 | + * @param $subject |
|
| 224 | + * @return $this |
|
| 225 | + */ |
|
| 226 | + public function setSubject($subject) { |
|
| 227 | + $this->swiftMessage->setSubject($subject); |
|
| 228 | + return $this; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Get the from subject of this message. |
|
| 233 | + * |
|
| 234 | + * @return string |
|
| 235 | + */ |
|
| 236 | + public function getSubject() { |
|
| 237 | + return $this->swiftMessage->getSubject(); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Set the plain-text body of this message. |
|
| 242 | + * |
|
| 243 | + * @param string $body |
|
| 244 | + * @return $this |
|
| 245 | + */ |
|
| 246 | + public function setPlainBody($body) { |
|
| 247 | + $this->swiftMessage->setBody($body); |
|
| 248 | + return $this; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Get the plain body of this message. |
|
| 253 | + * |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | + public function getPlainBody() { |
|
| 257 | + return $this->swiftMessage->getBody(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one. |
|
| 262 | + * |
|
| 263 | + * @param string $body |
|
| 264 | + * @return $this |
|
| 265 | + */ |
|
| 266 | + public function setHtmlBody($body) { |
|
| 267 | + $this->swiftMessage->addPart($body, 'text/html'); |
|
| 268 | + return $this; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Get's the underlying SwiftMessage |
|
| 273 | + * @return Swift_Message |
|
| 274 | + */ |
|
| 275 | + public function getSwiftMessage() { |
|
| 276 | + return $this->swiftMessage; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @param string $body |
|
| 281 | + * @param string $contentType |
|
| 282 | + * @return $this |
|
| 283 | + */ |
|
| 284 | + public function setBody($body, $contentType) { |
|
| 285 | + $this->swiftMessage->setBody($body, $contentType); |
|
| 286 | + return $this; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @param IEMailTemplate $emailTemplate |
|
| 291 | + * @return $this |
|
| 292 | + */ |
|
| 293 | + public function useTemplate(IEMailTemplate $emailTemplate) { |
|
| 294 | + $this->setSubject($emailTemplate->renderSubject()); |
|
| 295 | + $this->setPlainBody($emailTemplate->renderText()); |
|
| 296 | + $this->setHtmlBody($emailTemplate->renderHtml()); |
|
| 297 | + return $this; |
|
| 298 | + } |
|
| 299 | 299 | } |