Completed
Push — master ( 73aef9...c8323f )
by Georg
60:20 queued 46:52
created
lib/public/Mail/IAttachment.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -29,25 +29,25 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/private/Mail/Attachment.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -31,48 +31,48 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
lib/private/Mail/Mailer.php 1 patch
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -51,241 +51,241 @@
 block discarded – undo
51 51
  * @package OC\Mail
52 52
  */
53 53
 class Mailer implements IMailer {
54
-	/** @var \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport Cached transport */
55
-	private $instance = null;
56
-	/** @var IConfig */
57
-	private $config;
58
-	/** @var ILogger */
59
-	private $logger;
60
-	/** @var Defaults */
61
-	private $defaults;
62
-	/** @var IURLGenerator */
63
-	private $urlGenerator;
64
-	/** @var IL10N */
65
-	private $l10n;
54
+    /** @var \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport Cached transport */
55
+    private $instance = null;
56
+    /** @var IConfig */
57
+    private $config;
58
+    /** @var ILogger */
59
+    private $logger;
60
+    /** @var Defaults */
61
+    private $defaults;
62
+    /** @var IURLGenerator */
63
+    private $urlGenerator;
64
+    /** @var IL10N */
65
+    private $l10n;
66 66
 
67
-	/**
68
-	 * @param IConfig $config
69
-	 * @param ILogger $logger
70
-	 * @param Defaults $defaults
71
-	 * @param IURLGenerator $urlGenerator
72
-	 * @param IL10N $l10n
73
-	 */
74
-	public function __construct(IConfig $config,
75
-						 ILogger $logger,
76
-						 Defaults $defaults,
77
-						 IURLGenerator $urlGenerator,
78
-						 IL10N $l10n) {
79
-		$this->config = $config;
80
-		$this->logger = $logger;
81
-		$this->defaults = $defaults;
82
-		$this->urlGenerator = $urlGenerator;
83
-		$this->l10n = $l10n;
84
-	}
67
+    /**
68
+     * @param IConfig $config
69
+     * @param ILogger $logger
70
+     * @param Defaults $defaults
71
+     * @param IURLGenerator $urlGenerator
72
+     * @param IL10N $l10n
73
+     */
74
+    public function __construct(IConfig $config,
75
+                            ILogger $logger,
76
+                            Defaults $defaults,
77
+                            IURLGenerator $urlGenerator,
78
+                            IL10N $l10n) {
79
+        $this->config = $config;
80
+        $this->logger = $logger;
81
+        $this->defaults = $defaults;
82
+        $this->urlGenerator = $urlGenerator;
83
+        $this->l10n = $l10n;
84
+    }
85 85
 
86
-	/**
87
-	 * Creates a new message object that can be passed to send()
88
-	 *
89
-	 * @return IMessage
90
-	 */
91
-	public function createMessage() {
92
-		return new Message(new \Swift_Message());
93
-	}
86
+    /**
87
+     * Creates a new message object that can be passed to send()
88
+     *
89
+     * @return IMessage
90
+     */
91
+    public function createMessage() {
92
+        return new Message(new \Swift_Message());
93
+    }
94 94
 
95
-	/**
96
-	 * @param string|null $data
97
-	 * @param string|null $filename
98
-	 * @param string|null $contentType
99
-	 * @return IAttachment
100
-	 * @since 13.0.0
101
-	 */
102
-	public function createAttachment($data = null, $filename = null, $contentType = null) {
103
-		return new Attachment(\Swift_Attachment::newInstance($data, $filename, $contentType));
104
-	}
95
+    /**
96
+     * @param string|null $data
97
+     * @param string|null $filename
98
+     * @param string|null $contentType
99
+     * @return IAttachment
100
+     * @since 13.0.0
101
+     */
102
+    public function createAttachment($data = null, $filename = null, $contentType = null) {
103
+        return new Attachment(\Swift_Attachment::newInstance($data, $filename, $contentType));
104
+    }
105 105
 
106
-	/**
107
-	 * @param string $path
108
-	 * @param string|null $contentType
109
-	 * @return IAttachment
110
-	 * @since 13.0.0
111
-	 */
112
-	public function createAttachmentFromPath($path, $contentType = null) {
113
-		return new Attachment(\Swift_Attachment::fromPath($path, $contentType));
114
-	}
106
+    /**
107
+     * @param string $path
108
+     * @param string|null $contentType
109
+     * @return IAttachment
110
+     * @since 13.0.0
111
+     */
112
+    public function createAttachmentFromPath($path, $contentType = null) {
113
+        return new Attachment(\Swift_Attachment::fromPath($path, $contentType));
114
+    }
115 115
 
116
-	/**
117
-	 * Creates a new email template object
118
-	 *
119
-	 * @param string $emailId
120
-	 * @param array $data
121
-	 * @return IEMailTemplate
122
-	 * @since 12.0.0
123
-	 */
124
-	public function createEMailTemplate($emailId, array $data = []) {
125
-		$class = $this->config->getSystemValue('mail_template_class', '');
116
+    /**
117
+     * Creates a new email template object
118
+     *
119
+     * @param string $emailId
120
+     * @param array $data
121
+     * @return IEMailTemplate
122
+     * @since 12.0.0
123
+     */
124
+    public function createEMailTemplate($emailId, array $data = []) {
125
+        $class = $this->config->getSystemValue('mail_template_class', '');
126 126
 
127
-		if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) {
128
-			return new $class(
129
-				$this->defaults,
130
-				$this->urlGenerator,
131
-				$this->l10n,
132
-				$emailId,
133
-				$data
134
-			);
135
-		}
127
+        if ($class !== '' && class_exists($class) && is_a($class, EMailTemplate::class, true)) {
128
+            return new $class(
129
+                $this->defaults,
130
+                $this->urlGenerator,
131
+                $this->l10n,
132
+                $emailId,
133
+                $data
134
+            );
135
+        }
136 136
 
137
-		return new EMailTemplate(
138
-			$this->defaults,
139
-			$this->urlGenerator,
140
-			$this->l10n,
141
-			$emailId,
142
-			$data
143
-		);
144
-	}
137
+        return new EMailTemplate(
138
+            $this->defaults,
139
+            $this->urlGenerator,
140
+            $this->l10n,
141
+            $emailId,
142
+            $data
143
+        );
144
+    }
145 145
 
146
-	/**
147
-	 * Send the specified message. Also sets the from address to the value defined in config.php
148
-	 * if no-one has been passed.
149
-	 *
150
-	 * @param IMessage|Message $message Message to send
151
-	 * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and
152
-	 * therefore should be considered
153
-	 * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address
154
-	 * has been supplied.)
155
-	 */
156
-	public function send(IMessage $message) {
157
-		$debugMode = $this->config->getSystemValue('mail_smtpdebug', false);
146
+    /**
147
+     * Send the specified message. Also sets the from address to the value defined in config.php
148
+     * if no-one has been passed.
149
+     *
150
+     * @param IMessage|Message $message Message to send
151
+     * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and
152
+     * therefore should be considered
153
+     * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address
154
+     * has been supplied.)
155
+     */
156
+    public function send(IMessage $message) {
157
+        $debugMode = $this->config->getSystemValue('mail_smtpdebug', false);
158 158
 
159
-		if (empty($message->getFrom())) {
160
-			$message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName()) => $this->defaults->getName()]);
161
-		}
159
+        if (empty($message->getFrom())) {
160
+            $message->setFrom([\OCP\Util::getDefaultEmailAddress($this->defaults->getName()) => $this->defaults->getName()]);
161
+        }
162 162
 
163
-		$failedRecipients = [];
163
+        $failedRecipients = [];
164 164
 
165
-		$mailer = $this->getInstance();
165
+        $mailer = $this->getInstance();
166 166
 
167
-		// Enable logger if debug mode is enabled
168
-		if($debugMode) {
169
-			$mailLogger = new \Swift_Plugins_Loggers_ArrayLogger();
170
-			$mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger));
171
-		}
167
+        // Enable logger if debug mode is enabled
168
+        if($debugMode) {
169
+            $mailLogger = new \Swift_Plugins_Loggers_ArrayLogger();
170
+            $mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger));
171
+        }
172 172
 
173
-		$mailer->send($message->getSwiftMessage(), $failedRecipients);
173
+        $mailer->send($message->getSwiftMessage(), $failedRecipients);
174 174
 
175
-		// Debugging logging
176
-		$logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject());
177
-		$this->logger->debug($logMessage, ['app' => 'core']);
178
-		if($debugMode && isset($mailLogger)) {
179
-			$this->logger->debug($mailLogger->dump(), ['app' => 'core']);
180
-		}
175
+        // Debugging logging
176
+        $logMessage = sprintf('Sent mail to "%s" with subject "%s"', print_r($message->getTo(), true), $message->getSubject());
177
+        $this->logger->debug($logMessage, ['app' => 'core']);
178
+        if($debugMode && isset($mailLogger)) {
179
+            $this->logger->debug($mailLogger->dump(), ['app' => 'core']);
180
+        }
181 181
 
182
-		return $failedRecipients;
183
-	}
182
+        return $failedRecipients;
183
+    }
184 184
 
185
-	/**
186
-	 * Checks if an e-mail address is valid
187
-	 *
188
-	 * @param string $email Email address to be validated
189
-	 * @return bool True if the mail address is valid, false otherwise
190
-	 */
191
-	public function validateMailAddress($email) {
192
-		return \Swift_Validate::email($this->convertEmail($email));
193
-	}
185
+    /**
186
+     * Checks if an e-mail address is valid
187
+     *
188
+     * @param string $email Email address to be validated
189
+     * @return bool True if the mail address is valid, false otherwise
190
+     */
191
+    public function validateMailAddress($email) {
192
+        return \Swift_Validate::email($this->convertEmail($email));
193
+    }
194 194
 
195
-	/**
196
-	 * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains
197
-	 *
198
-	 * FIXME: Remove this once SwiftMailer supports IDN
199
-	 *
200
-	 * @param string $email
201
-	 * @return string Converted mail address if `idn_to_ascii` exists
202
-	 */
203
-	protected function convertEmail($email) {
204
-		if (!function_exists('idn_to_ascii') || strpos($email, '@') === false) {
205
-			return $email;
206
-		}
195
+    /**
196
+     * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains
197
+     *
198
+     * FIXME: Remove this once SwiftMailer supports IDN
199
+     *
200
+     * @param string $email
201
+     * @return string Converted mail address if `idn_to_ascii` exists
202
+     */
203
+    protected function convertEmail($email) {
204
+        if (!function_exists('idn_to_ascii') || strpos($email, '@') === false) {
205
+            return $email;
206
+        }
207 207
 
208
-		list($name, $domain) = explode('@', $email, 2);
209
-		$domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46);
210
-		return $name.'@'.$domain;
211
-	}
208
+        list($name, $domain) = explode('@', $email, 2);
209
+        $domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46);
210
+        return $name.'@'.$domain;
211
+    }
212 212
 
213
-	/**
214
-	 * Returns whatever transport is configured within the config
215
-	 *
216
-	 * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport
217
-	 */
218
-	protected function getInstance() {
219
-		if (!is_null($this->instance)) {
220
-			return $this->instance;
221
-		}
213
+    /**
214
+     * Returns whatever transport is configured within the config
215
+     *
216
+     * @return \Swift_SmtpTransport|\Swift_SendmailTransport|\Swift_MailTransport
217
+     */
218
+    protected function getInstance() {
219
+        if (!is_null($this->instance)) {
220
+            return $this->instance;
221
+        }
222 222
 
223
-		switch ($this->config->getSystemValue('mail_smtpmode', 'php')) {
224
-			case 'smtp':
225
-				$this->instance = $this->getSmtpInstance();
226
-				break;
227
-			case 'sendmail':
228
-				// FIXME: Move into the return statement but requires proper testing
229
-				//       for SMTP and mail as well. Thus not really doable for a
230
-				//       minor release.
231
-				$this->instance = \Swift_Mailer::newInstance($this->getSendMailInstance());
232
-				break;
233
-			default:
234
-				$this->instance = $this->getMailInstance();
235
-				break;
236
-		}
223
+        switch ($this->config->getSystemValue('mail_smtpmode', 'php')) {
224
+            case 'smtp':
225
+                $this->instance = $this->getSmtpInstance();
226
+                break;
227
+            case 'sendmail':
228
+                // FIXME: Move into the return statement but requires proper testing
229
+                //       for SMTP and mail as well. Thus not really doable for a
230
+                //       minor release.
231
+                $this->instance = \Swift_Mailer::newInstance($this->getSendMailInstance());
232
+                break;
233
+            default:
234
+                $this->instance = $this->getMailInstance();
235
+                break;
236
+        }
237 237
 
238
-		return $this->instance;
239
-	}
238
+        return $this->instance;
239
+    }
240 240
 
241
-	/**
242
-	 * Returns the SMTP transport
243
-	 *
244
-	 * @return \Swift_SmtpTransport
245
-	 */
246
-	protected function getSmtpInstance() {
247
-		$transport = \Swift_SmtpTransport::newInstance();
248
-		$transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10));
249
-		$transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1'));
250
-		$transport->setPort($this->config->getSystemValue('mail_smtpport', 25));
251
-		if ($this->config->getSystemValue('mail_smtpauth', false)) {
252
-			$transport->setUsername($this->config->getSystemValue('mail_smtpname', ''));
253
-			$transport->setPassword($this->config->getSystemValue('mail_smtppassword', ''));
254
-			$transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN'));
255
-		}
256
-		$smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', '');
257
-		if (!empty($smtpSecurity)) {
258
-			$transport->setEncryption($smtpSecurity);
259
-		}
260
-		$transport->start();
261
-		return $transport;
262
-	}
241
+    /**
242
+     * Returns the SMTP transport
243
+     *
244
+     * @return \Swift_SmtpTransport
245
+     */
246
+    protected function getSmtpInstance() {
247
+        $transport = \Swift_SmtpTransport::newInstance();
248
+        $transport->setTimeout($this->config->getSystemValue('mail_smtptimeout', 10));
249
+        $transport->setHost($this->config->getSystemValue('mail_smtphost', '127.0.0.1'));
250
+        $transport->setPort($this->config->getSystemValue('mail_smtpport', 25));
251
+        if ($this->config->getSystemValue('mail_smtpauth', false)) {
252
+            $transport->setUsername($this->config->getSystemValue('mail_smtpname', ''));
253
+            $transport->setPassword($this->config->getSystemValue('mail_smtppassword', ''));
254
+            $transport->setAuthMode($this->config->getSystemValue('mail_smtpauthtype', 'LOGIN'));
255
+        }
256
+        $smtpSecurity = $this->config->getSystemValue('mail_smtpsecure', '');
257
+        if (!empty($smtpSecurity)) {
258
+            $transport->setEncryption($smtpSecurity);
259
+        }
260
+        $transport->start();
261
+        return $transport;
262
+    }
263 263
 
264
-	/**
265
-	 * Returns the sendmail transport
266
-	 *
267
-	 * @return \Swift_SendmailTransport
268
-	 */
269
-	protected function getSendMailInstance() {
270
-		switch ($this->config->getSystemValue('mail_smtpmode', 'php')) {
271
-			case 'qmail':
272
-				$binaryPath = '/var/qmail/bin/sendmail';
273
-				break;
274
-			default:
275
-				$binaryPath = '/usr/sbin/sendmail';
276
-				break;
277
-		}
264
+    /**
265
+     * Returns the sendmail transport
266
+     *
267
+     * @return \Swift_SendmailTransport
268
+     */
269
+    protected function getSendMailInstance() {
270
+        switch ($this->config->getSystemValue('mail_smtpmode', 'php')) {
271
+            case 'qmail':
272
+                $binaryPath = '/var/qmail/bin/sendmail';
273
+                break;
274
+            default:
275
+                $binaryPath = '/usr/sbin/sendmail';
276
+                break;
277
+        }
278 278
 
279
-		return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs');
280
-	}
279
+        return \Swift_SendmailTransport::newInstance($binaryPath . ' -bs');
280
+    }
281 281
 
282
-	/**
283
-	 * Returns the mail transport
284
-	 *
285
-	 * @return \Swift_MailTransport
286
-	 */
287
-	protected function getMailInstance() {
288
-		return \Swift_MailTransport::newInstance();
289
-	}
282
+    /**
283
+     * Returns the mail transport
284
+     *
285
+     * @return \Swift_MailTransport
286
+     */
287
+    protected function getMailInstance() {
288
+        return \Swift_MailTransport::newInstance();
289
+    }
290 290
 
291 291
 }
Please login to merge, or discard this patch.
lib/private/Mail/Message.php 1 patch
Indentation   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -34,245 +34,245 @@
 block discarded – undo
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 IAttachment $attachment
49
-	 * @return $this
50
-	 * @since 13.0.0
51
-	 */
52
-	public function attach(IAttachment $attachment) {
53
-		/** @var Attachment $attachment */
54
-		$this->swiftMessage->attach($attachment->getSwiftAttachment());
55
-		return $this;
56
-	}
57
-
58
-	/**
59
-	 * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains
60
-	 * FIXME: Remove this once SwiftMailer supports IDN
61
-	 *
62
-	 * @param array $addresses Array of mail addresses, key will get converted
63
-	 * @return array Converted addresses if `idn_to_ascii` exists
64
-	 */
65
-	protected function convertAddresses($addresses) {
66
-		if (!function_exists('idn_to_ascii')) {
67
-			return $addresses;
68
-		}
69
-
70
-		$convertedAddresses = array();
71
-
72
-		foreach($addresses as $email => $readableName) {
73
-			if(!is_numeric($email)) {
74
-				list($name, $domain) = explode('@', $email, 2);
75
-				$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
76
-				$convertedAddresses[$name.'@'.$domain] = $readableName;
77
-			} else {
78
-				list($name, $domain) = explode('@', $readableName, 2);
79
-				$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
80
-				$convertedAddresses[$email] = $name.'@'.$domain;
81
-			}
82
-		}
83
-
84
-		return $convertedAddresses;
85
-	}
86
-
87
-	/**
88
-	 * Set the from address of this message.
89
-	 *
90
-	 * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php
91
-	 *
92
-	 * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name')
93
-	 * @return $this
94
-	 */
95
-	public function setFrom(array $addresses) {
96
-		$addresses = $this->convertAddresses($addresses);
97
-
98
-		$this->swiftMessage->setFrom($addresses);
99
-		return $this;
100
-	}
101
-
102
-	/**
103
-	 * Get the from address of this message.
104
-	 *
105
-	 * @return array
106
-	 */
107
-	public function getFrom() {
108
-		return $this->swiftMessage->getFrom();
109
-	}
110
-
111
-	/**
112
-	 * Set the Reply-To address of this message
113
-	 *
114
-	 * @param array $addresses
115
-	 * @return $this
116
-	 */
117
-	public function setReplyTo(array $addresses) {
118
-		$addresses = $this->convertAddresses($addresses);
119
-
120
-		$this->swiftMessage->setReplyTo($addresses);
121
-		return $this;
122
-	}
123
-
124
-	/**
125
-	 * Returns the Reply-To address of this message
126
-	 *
127
-	 * @return array
128
-	 */
129
-	public function getReplyTo() {
130
-		return $this->swiftMessage->getReplyTo();
131
-	}
132
-
133
-	/**
134
-	 * Set the to addresses of this message.
135
-	 *
136
-	 * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
137
-	 * @return $this
138
-	 */
139
-	public function setTo(array $recipients) {
140
-		$recipients = $this->convertAddresses($recipients);
141
-
142
-		$this->swiftMessage->setTo($recipients);
143
-		return $this;
144
-	}
145
-
146
-	/**
147
-	 * Get the to address of this message.
148
-	 *
149
-	 * @return array
150
-	 */
151
-	public function getTo() {
152
-		return $this->swiftMessage->getTo();
153
-	}
154
-
155
-	/**
156
-	 * Set the CC recipients of this message.
157
-	 *
158
-	 * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
159
-	 * @return $this
160
-	 */
161
-	public function setCc(array $recipients) {
162
-		$recipients = $this->convertAddresses($recipients);
163
-
164
-		$this->swiftMessage->setCc($recipients);
165
-		return $this;
166
-	}
167
-
168
-	/**
169
-	 * Get the cc address of this message.
170
-	 *
171
-	 * @return array
172
-	 */
173
-	public function getCc() {
174
-		return $this->swiftMessage->getCc();
175
-	}
176
-
177
-	/**
178
-	 * Set the BCC recipients of this message.
179
-	 *
180
-	 * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
181
-	 * @return $this
182
-	 */
183
-	public function setBcc(array $recipients) {
184
-		$recipients = $this->convertAddresses($recipients);
185
-
186
-		$this->swiftMessage->setBcc($recipients);
187
-		return $this;
188
-	}
189
-
190
-	/**
191
-	 * Get the Bcc address of this message.
192
-	 *
193
-	 * @return array
194
-	 */
195
-	public function getBcc() {
196
-		return $this->swiftMessage->getBcc();
197
-	}
198
-
199
-	/**
200
-	 * Set the subject of this message.
201
-	 *
202
-	 * @param $subject
203
-	 * @return $this
204
-	 */
205
-	public function setSubject($subject) {
206
-		$this->swiftMessage->setSubject($subject);
207
-		return $this;
208
-	}
209
-
210
-	/**
211
-	 * Get the from subject of this message.
212
-	 *
213
-	 * @return string
214
-	 */
215
-	public function getSubject() {
216
-		return $this->swiftMessage->getSubject();
217
-	}
218
-
219
-	/**
220
-	 * Set the plain-text body of this message.
221
-	 *
222
-	 * @param string $body
223
-	 * @return $this
224
-	 */
225
-	public function setPlainBody($body) {
226
-		$this->swiftMessage->setBody($body);
227
-		return $this;
228
-	}
229
-
230
-	/**
231
-	 * Get the plain body of this message.
232
-	 *
233
-	 * @return string
234
-	 */
235
-	public function getPlainBody() {
236
-		return $this->swiftMessage->getBody();
237
-	}
238
-
239
-	/**
240
-	 * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one.
241
-	 *
242
-	 * @param string $body
243
-	 * @return $this
244
-	 */
245
-	public function setHtmlBody($body) {
246
-		$this->swiftMessage->addPart($body, 'text/html');
247
-		return $this;
248
-	}
249
-
250
-	/**
251
-	 * Get's the underlying SwiftMessage
252
-	 * @return Swift_Message
253
-	 */
254
-	public function getSwiftMessage() {
255
-		return $this->swiftMessage;
256
-	}
257
-
258
-	/**
259
-	 * @param string $body
260
-	 * @param string $contentType
261
-	 * @return $this
262
-	 */
263
-	public function setBody($body, $contentType) {
264
-		$this->swiftMessage->setBody($body, $contentType);
265
-		return $this;
266
-	}
267
-
268
-	/**
269
-	 * @param IEMailTemplate $emailTemplate
270
-	 * @return $this
271
-	 */
272
-	public function useTemplate(IEMailTemplate $emailTemplate) {
273
-		$this->setSubject($emailTemplate->renderSubject());
274
-		$this->setPlainBody($emailTemplate->renderText());
275
-		$this->setHtmlBody($emailTemplate->renderHtml());
276
-		return $this;
277
-	}
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 IAttachment $attachment
49
+     * @return $this
50
+     * @since 13.0.0
51
+     */
52
+    public function attach(IAttachment $attachment) {
53
+        /** @var Attachment $attachment */
54
+        $this->swiftMessage->attach($attachment->getSwiftAttachment());
55
+        return $this;
56
+    }
57
+
58
+    /**
59
+     * SwiftMailer does currently not work with IDN domains, this function therefore converts the domains
60
+     * FIXME: Remove this once SwiftMailer supports IDN
61
+     *
62
+     * @param array $addresses Array of mail addresses, key will get converted
63
+     * @return array Converted addresses if `idn_to_ascii` exists
64
+     */
65
+    protected function convertAddresses($addresses) {
66
+        if (!function_exists('idn_to_ascii')) {
67
+            return $addresses;
68
+        }
69
+
70
+        $convertedAddresses = array();
71
+
72
+        foreach($addresses as $email => $readableName) {
73
+            if(!is_numeric($email)) {
74
+                list($name, $domain) = explode('@', $email, 2);
75
+                $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
76
+                $convertedAddresses[$name.'@'.$domain] = $readableName;
77
+            } else {
78
+                list($name, $domain) = explode('@', $readableName, 2);
79
+                $domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
80
+                $convertedAddresses[$email] = $name.'@'.$domain;
81
+            }
82
+        }
83
+
84
+        return $convertedAddresses;
85
+    }
86
+
87
+    /**
88
+     * Set the from address of this message.
89
+     *
90
+     * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php
91
+     *
92
+     * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name')
93
+     * @return $this
94
+     */
95
+    public function setFrom(array $addresses) {
96
+        $addresses = $this->convertAddresses($addresses);
97
+
98
+        $this->swiftMessage->setFrom($addresses);
99
+        return $this;
100
+    }
101
+
102
+    /**
103
+     * Get the from address of this message.
104
+     *
105
+     * @return array
106
+     */
107
+    public function getFrom() {
108
+        return $this->swiftMessage->getFrom();
109
+    }
110
+
111
+    /**
112
+     * Set the Reply-To address of this message
113
+     *
114
+     * @param array $addresses
115
+     * @return $this
116
+     */
117
+    public function setReplyTo(array $addresses) {
118
+        $addresses = $this->convertAddresses($addresses);
119
+
120
+        $this->swiftMessage->setReplyTo($addresses);
121
+        return $this;
122
+    }
123
+
124
+    /**
125
+     * Returns the Reply-To address of this message
126
+     *
127
+     * @return array
128
+     */
129
+    public function getReplyTo() {
130
+        return $this->swiftMessage->getReplyTo();
131
+    }
132
+
133
+    /**
134
+     * Set the to addresses of this message.
135
+     *
136
+     * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
137
+     * @return $this
138
+     */
139
+    public function setTo(array $recipients) {
140
+        $recipients = $this->convertAddresses($recipients);
141
+
142
+        $this->swiftMessage->setTo($recipients);
143
+        return $this;
144
+    }
145
+
146
+    /**
147
+     * Get the to address of this message.
148
+     *
149
+     * @return array
150
+     */
151
+    public function getTo() {
152
+        return $this->swiftMessage->getTo();
153
+    }
154
+
155
+    /**
156
+     * Set the CC recipients of this message.
157
+     *
158
+     * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
159
+     * @return $this
160
+     */
161
+    public function setCc(array $recipients) {
162
+        $recipients = $this->convertAddresses($recipients);
163
+
164
+        $this->swiftMessage->setCc($recipients);
165
+        return $this;
166
+    }
167
+
168
+    /**
169
+     * Get the cc address of this message.
170
+     *
171
+     * @return array
172
+     */
173
+    public function getCc() {
174
+        return $this->swiftMessage->getCc();
175
+    }
176
+
177
+    /**
178
+     * Set the BCC recipients of this message.
179
+     *
180
+     * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
181
+     * @return $this
182
+     */
183
+    public function setBcc(array $recipients) {
184
+        $recipients = $this->convertAddresses($recipients);
185
+
186
+        $this->swiftMessage->setBcc($recipients);
187
+        return $this;
188
+    }
189
+
190
+    /**
191
+     * Get the Bcc address of this message.
192
+     *
193
+     * @return array
194
+     */
195
+    public function getBcc() {
196
+        return $this->swiftMessage->getBcc();
197
+    }
198
+
199
+    /**
200
+     * Set the subject of this message.
201
+     *
202
+     * @param $subject
203
+     * @return $this
204
+     */
205
+    public function setSubject($subject) {
206
+        $this->swiftMessage->setSubject($subject);
207
+        return $this;
208
+    }
209
+
210
+    /**
211
+     * Get the from subject of this message.
212
+     *
213
+     * @return string
214
+     */
215
+    public function getSubject() {
216
+        return $this->swiftMessage->getSubject();
217
+    }
218
+
219
+    /**
220
+     * Set the plain-text body of this message.
221
+     *
222
+     * @param string $body
223
+     * @return $this
224
+     */
225
+    public function setPlainBody($body) {
226
+        $this->swiftMessage->setBody($body);
227
+        return $this;
228
+    }
229
+
230
+    /**
231
+     * Get the plain body of this message.
232
+     *
233
+     * @return string
234
+     */
235
+    public function getPlainBody() {
236
+        return $this->swiftMessage->getBody();
237
+    }
238
+
239
+    /**
240
+     * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one.
241
+     *
242
+     * @param string $body
243
+     * @return $this
244
+     */
245
+    public function setHtmlBody($body) {
246
+        $this->swiftMessage->addPart($body, 'text/html');
247
+        return $this;
248
+    }
249
+
250
+    /**
251
+     * Get's the underlying SwiftMessage
252
+     * @return Swift_Message
253
+     */
254
+    public function getSwiftMessage() {
255
+        return $this->swiftMessage;
256
+    }
257
+
258
+    /**
259
+     * @param string $body
260
+     * @param string $contentType
261
+     * @return $this
262
+     */
263
+    public function setBody($body, $contentType) {
264
+        $this->swiftMessage->setBody($body, $contentType);
265
+        return $this;
266
+    }
267
+
268
+    /**
269
+     * @param IEMailTemplate $emailTemplate
270
+     * @return $this
271
+     */
272
+    public function useTemplate(IEMailTemplate $emailTemplate) {
273
+        $this->setSubject($emailTemplate->renderSubject());
274
+        $this->setPlainBody($emailTemplate->renderText());
275
+        $this->setHtmlBody($emailTemplate->renderHtml());
276
+        return $this;
277
+    }
278 278
 }
Please login to merge, or discard this patch.
lib/public/Mail/IMailer.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -45,60 +45,60 @@
 block discarded – undo
45 45
  * @since 8.1.0
46 46
  */
47 47
 interface IMailer {
48
-	/**
49
-	 * Creates a new message object that can be passed to send()
50
-	 *
51
-	 * @return IMessage
52
-	 * @since 8.1.0
53
-	 */
54
-	public function createMessage();
48
+    /**
49
+     * Creates a new message object that can be passed to send()
50
+     *
51
+     * @return IMessage
52
+     * @since 8.1.0
53
+     */
54
+    public function createMessage();
55 55
 
56
-	/**
57
-	 * @param string|null $data
58
-	 * @param string|null $filename
59
-	 * @param string|null $contentType
60
-	 * @return IAttachment
61
-	 * @since 13.0.0
62
-	 */
63
-	public function createAttachment($data = null, $filename = null, $contentType = null);
56
+    /**
57
+     * @param string|null $data
58
+     * @param string|null $filename
59
+     * @param string|null $contentType
60
+     * @return IAttachment
61
+     * @since 13.0.0
62
+     */
63
+    public function createAttachment($data = null, $filename = null, $contentType = null);
64 64
 
65
-	/**
66
-	 * @param string $path
67
-	 * @param string|null $contentType
68
-	 * @return IAttachment
69
-	 * @since 13.0.0
70
-	 */
71
-	public function createAttachmentFromPath($path, $contentType = null);
65
+    /**
66
+     * @param string $path
67
+     * @param string|null $contentType
68
+     * @return IAttachment
69
+     * @since 13.0.0
70
+     */
71
+    public function createAttachmentFromPath($path, $contentType = null);
72 72
 
73
-	/**
74
-	 * Creates a new email template object
75
-	 *
76
-	 * @param string $emailId
77
-	 * @param array $data
78
-	 * @return IEMailTemplate
79
-	 * @since 12.0.0 Parameters added in 12.0.3
80
-	 */
81
-	public function createEMailTemplate($emailId, array $data = []);
73
+    /**
74
+     * Creates a new email template object
75
+     *
76
+     * @param string $emailId
77
+     * @param array $data
78
+     * @return IEMailTemplate
79
+     * @since 12.0.0 Parameters added in 12.0.3
80
+     */
81
+    public function createEMailTemplate($emailId, array $data = []);
82 82
 
83
-	/**
84
-	 * Send the specified message. Also sets the from address to the value defined in config.php
85
-	 * if no-one has been passed.
86
-	 *
87
-	 * @param IMessage $message Message to send
88
-	 * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and
89
-	 * therefore should be considered
90
-	 * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address
91
-	 * has been supplied.)
92
-	 * @since 8.1.0
93
-	 */
94
-	public function send(IMessage $message);
83
+    /**
84
+     * Send the specified message. Also sets the from address to the value defined in config.php
85
+     * if no-one has been passed.
86
+     *
87
+     * @param IMessage $message Message to send
88
+     * @return string[] Array with failed recipients. Be aware that this depends on the used mail backend and
89
+     * therefore should be considered
90
+     * @throws \Exception In case it was not possible to send the message. (for example if an invalid mail address
91
+     * has been supplied.)
92
+     * @since 8.1.0
93
+     */
94
+    public function send(IMessage $message);
95 95
 
96
-	/**
97
-	 * Checks if an e-mail address is valid
98
-	 *
99
-	 * @param string $email Email address to be validated
100
-	 * @return bool True if the mail address is valid, false otherwise
101
-	 * @since 8.1.0
102
-	 */
103
-	public function validateMailAddress($email);
96
+    /**
97
+     * Checks if an e-mail address is valid
98
+     *
99
+     * @param string $email Email address to be validated
100
+     * @return bool True if the mail address is valid, false otherwise
101
+     * @since 8.1.0
102
+     */
103
+    public function validateMailAddress($email);
104 104
 }
Please login to merge, or discard this patch.
lib/public/Mail/IMessage.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -29,64 +29,64 @@
 block discarded – undo
29 29
  */
30 30
 interface IMessage {
31 31
 
32
-	/**
33
-	 * @param IAttachment $attachment
34
-	 * @return $this
35
-	 * @since 13.0.0
36
-	 */
37
-	public function attach(IAttachment $attachment);
32
+    /**
33
+     * @param IAttachment $attachment
34
+     * @return $this
35
+     * @since 13.0.0
36
+     */
37
+    public function attach(IAttachment $attachment);
38 38
 
39
-	/**
40
-	 * Set the from address of this message.
41
-	 *
42
-	 * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php
43
-	 *
44
-	 * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name')
45
-	 * @return $this
46
-	 * @since 13.0.0
47
-	 */
48
-	public function setFrom(array $addresses);
39
+    /**
40
+     * Set the from address of this message.
41
+     *
42
+     * If no "From" address is used \OC\Mail\Mailer will use mail_from_address and mail_domain from config.php
43
+     *
44
+     * @param array $addresses Example: array('[email protected]', '[email protected]' => 'A name')
45
+     * @return $this
46
+     * @since 13.0.0
47
+     */
48
+    public function setFrom(array $addresses);
49 49
 
50
-	/**
51
-	 * Set the Reply-To address of this message
52
-	 *
53
-	 * @param array $addresses
54
-	 * @return $this
55
-	 * @since 13.0.0
56
-	 */
57
-	public function setReplyTo(array $addresses);
50
+    /**
51
+     * Set the Reply-To address of this message
52
+     *
53
+     * @param array $addresses
54
+     * @return $this
55
+     * @since 13.0.0
56
+     */
57
+    public function setReplyTo(array $addresses);
58 58
 
59
-	/**
60
-	 * Set the to addresses of this message.
61
-	 *
62
-	 * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
63
-	 * @return $this
64
-	 * @since 13.0.0
65
-	 */
66
-	public function setTo(array $recipients);
59
+    /**
60
+     * Set the to addresses of this message.
61
+     *
62
+     * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
63
+     * @return $this
64
+     * @since 13.0.0
65
+     */
66
+    public function setTo(array $recipients);
67 67
 
68
-	/**
69
-	 * Set the CC recipients of this message.
70
-	 *
71
-	 * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
72
-	 * @return $this
73
-	 * @since 13.0.0
74
-	 */
75
-	public function setCc(array $recipients);
68
+    /**
69
+     * Set the CC recipients of this message.
70
+     *
71
+     * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
72
+     * @return $this
73
+     * @since 13.0.0
74
+     */
75
+    public function setCc(array $recipients);
76 76
 
77
-	/**
78
-	 * Set the BCC recipients of this message.
79
-	 *
80
-	 * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
81
-	 * @return $this
82
-	 * @since 13.0.0
83
-	 */
84
-	public function setBcc(array $recipients);
77
+    /**
78
+     * Set the BCC recipients of this message.
79
+     *
80
+     * @param array $recipients Example: array('[email protected]', '[email protected]' => 'A name')
81
+     * @return $this
82
+     * @since 13.0.0
83
+     */
84
+    public function setBcc(array $recipients);
85 85
 
86
-	/**
87
-	 * @param IEMailTemplate $emailTemplate
88
-	 * @return $this
89
-	 * @since 13.0.0
90
-	 */
91
-	public function useTemplate(IEMailTemplate $emailTemplate);
86
+    /**
87
+     * @param IEMailTemplate $emailTemplate
88
+     * @return $this
89
+     * @since 13.0.0
90
+     */
91
+    public function useTemplate(IEMailTemplate $emailTemplate);
92 92
 }
Please login to merge, or discard this patch.