Passed
Push — master ( 5483d0...593d64 )
by John
35:02 queued 22:39
created
lib/public/Mail/IEMailTemplate.php 1 patch
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -58,119 +58,119 @@
 block discarded – undo
58 58
  */
59 59
 interface IEMailTemplate {
60 60
 
61
-	/**
62
-	 * Sets the subject of the email
63
-	 *
64
-	 * @param string $subject
65
-	 *
66
-	 * @since 13.0.0
67
-	 */
68
-	public function setSubject(string $subject);
61
+    /**
62
+     * Sets the subject of the email
63
+     *
64
+     * @param string $subject
65
+     *
66
+     * @since 13.0.0
67
+     */
68
+    public function setSubject(string $subject);
69 69
 
70
-	/**
71
-	 * Adds a header to the email
72
-	 *
73
-	 * @since 12.0.0
74
-	 */
75
-	public function addHeader();
70
+    /**
71
+     * Adds a header to the email
72
+     *
73
+     * @since 12.0.0
74
+     */
75
+    public function addHeader();
76 76
 
77
-	/**
78
-	 * Adds a heading to the email
79
-	 *
80
-	 * @param string $title
81
-	 * @param string|bool $plainTitle Title that is used in the plain text email
82
-	 *   if empty the $title is used, if false none will be used
83
-	 *
84
-	 * @since 12.0.0
85
-	 */
86
-	public function addHeading(string $title, $plainTitle = '');
77
+    /**
78
+     * Adds a heading to the email
79
+     *
80
+     * @param string $title
81
+     * @param string|bool $plainTitle Title that is used in the plain text email
82
+     *   if empty the $title is used, if false none will be used
83
+     *
84
+     * @since 12.0.0
85
+     */
86
+    public function addHeading(string $title, $plainTitle = '');
87 87
 
88
-	/**
89
-	 * Adds a paragraph to the body of the email
90
-	 *
91
-	 * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
92
-	 * @param string|bool $plainText Text that is used in the plain text email
93
-	 *   if empty the $text is used, if false none will be used
94
-	 *
95
-	 * @since 12.0.0
96
-	 */
97
-	public function addBodyText(string $text, $plainText = '');
88
+    /**
89
+     * Adds a paragraph to the body of the email
90
+     *
91
+     * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
92
+     * @param string|bool $plainText Text that is used in the plain text email
93
+     *   if empty the $text is used, if false none will be used
94
+     *
95
+     * @since 12.0.0
96
+     */
97
+    public function addBodyText(string $text, $plainText = '');
98 98
 
99
-	/**
100
-	 * Adds a list item to the body of the email
101
-	 *
102
-	 * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
103
-	 * @param string $metaInfo; Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
104
-	 * @param string $icon Absolute path, must be 16*16 pixels
105
-	 * @param string|bool $plainText Text that is used in the plain text email
106
-	 *   if empty the $text is used, if false none will be used
107
-	 * @param string|bool $plainMetaInfo Meta info that is used in the plain text email
108
-	 *   if empty the $metaInfo is used, if false none will be used
109
-	 * @param integer plainIndent If > 0, Indent plainText by this amount.
110
-	 * @since 12.0.0
111
-	 */
112
-	public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0);
99
+    /**
100
+     * Adds a list item to the body of the email
101
+     *
102
+     * @param string $text; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
103
+     * @param string $metaInfo; Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
104
+     * @param string $icon Absolute path, must be 16*16 pixels
105
+     * @param string|bool $plainText Text that is used in the plain text email
106
+     *   if empty the $text is used, if false none will be used
107
+     * @param string|bool $plainMetaInfo Meta info that is used in the plain text email
108
+     *   if empty the $metaInfo is used, if false none will be used
109
+     * @param integer plainIndent If > 0, Indent plainText by this amount.
110
+     * @since 12.0.0
111
+     */
112
+    public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0);
113 113
 
114
-	/**
115
-	 * Adds a button group of two buttons to the body of the email
116
-	 *
117
-	 * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
118
-	 * @param string $urlLeft URL of left button
119
-	 * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
120
-	 * @param string $urlRight URL of right button
121
-	 * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used
122
-	 * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used
123
-	 *
124
-	 * @since 12.0.0
125
-	 */
126
-	public function addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight, string $plainTextLeft = '', string $plainTextRight = '');
114
+    /**
115
+     * Adds a button group of two buttons to the body of the email
116
+     *
117
+     * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
118
+     * @param string $urlLeft URL of left button
119
+     * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
120
+     * @param string $urlRight URL of right button
121
+     * @param string $plainTextLeft Text of left button that is used in the plain text version - if empty the $textLeft is used
122
+     * @param string $plainTextRight Text of right button that is used in the plain text version - if empty the $textRight is used
123
+     *
124
+     * @since 12.0.0
125
+     */
126
+    public function addBodyButtonGroup(string $textLeft, string $urlLeft, string $textRight, string $urlRight, string $plainTextLeft = '', string $plainTextRight = '');
127 127
 
128
-	/**
129
-	 * Adds a button to the body of the email
130
-	 *
131
-	 * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
132
-	 * @param string $url URL of button
133
-	 * @param string $plainText Text of button in plain text version
134
-	 * 		if empty the $text is used, if false none will be used
135
-	 *
136
-	 * @since 12.0.0
137
-	 */
138
-	public function addBodyButton(string $text, string $url, $plainText = '');
128
+    /**
129
+     * Adds a button to the body of the email
130
+     *
131
+     * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
132
+     * @param string $url URL of button
133
+     * @param string $plainText Text of button in plain text version
134
+     * 		if empty the $text is used, if false none will be used
135
+     *
136
+     * @since 12.0.0
137
+     */
138
+    public function addBodyButton(string $text, string $url, $plainText = '');
139 139
 
140
-	/**
141
-	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
142
-	 *
143
-	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
144
-	 * @param string $lang Optional language to set the default footer in
145
-	 *
146
-	 * @since 12.0.0
147
-	 */
148
-	public function addFooter(string $text = '', ?string $lang = null);
140
+    /**
141
+     * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
142
+     *
143
+     * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
144
+     * @param string $lang Optional language to set the default footer in
145
+     *
146
+     * @since 12.0.0
147
+     */
148
+    public function addFooter(string $text = '', ?string $lang = null);
149 149
 
150
-	/**
151
-	 * Returns the rendered email subject as string
152
-	 *
153
-	 * @return string
154
-	 *
155
-	 * @since 13.0.0
156
-	 */
157
-	public function renderSubject(): string;
150
+    /**
151
+     * Returns the rendered email subject as string
152
+     *
153
+     * @return string
154
+     *
155
+     * @since 13.0.0
156
+     */
157
+    public function renderSubject(): string;
158 158
 
159
-	/**
160
-	 * Returns the rendered HTML email as string
161
-	 *
162
-	 * @return string
163
-	 *
164
-	 * @since 12.0.0
165
-	 */
166
-	public function renderHtml(): string;
159
+    /**
160
+     * Returns the rendered HTML email as string
161
+     *
162
+     * @return string
163
+     *
164
+     * @since 12.0.0
165
+     */
166
+    public function renderHtml(): string;
167 167
 
168
-	/**
169
-	 * Returns the rendered plain text email as string
170
-	 *
171
-	 * @return string
172
-	 *
173
-	 * @since 12.0.0
174
-	 */
175
-	public function renderText(): string;
168
+    /**
169
+     * Returns the rendered plain text email as string
170
+     *
171
+     * @return string
172
+     *
173
+     * @since 12.0.0
174
+     */
175
+    public function renderText(): string;
176 176
 }
Please login to merge, or discard this patch.
lib/private/Mail/EMailTemplate.php 2 patches
Indentation   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -52,33 +52,33 @@  discard block
 block discarded – undo
52 52
  * @package OC\Mail
53 53
  */
54 54
 class EMailTemplate implements IEMailTemplate {
55
-	/** @var Defaults */
56
-	protected $themingDefaults;
57
-	/** @var IURLGenerator */
58
-	protected $urlGenerator;
59
-	/** @var IFactory */
60
-	protected $l10nFactory;
61
-	/** @var string */
62
-	protected $emailId;
63
-	/** @var array */
64
-	protected $data;
65
-
66
-	/** @var string */
67
-	protected $subject = '';
68
-	/** @var string */
69
-	protected $htmlBody = '';
70
-	/** @var string */
71
-	protected $plainBody = '';
72
-	/** @var bool indicated if the footer is added */
73
-	protected $headerAdded = false;
74
-	/** @var bool indicated if the body is already opened */
75
-	protected $bodyOpened = false;
76
-	/** @var bool indicated if there is a list open in the body */
77
-	protected $bodyListOpened = false;
78
-	/** @var bool indicated if the footer is added */
79
-	protected $footerAdded = false;
80
-
81
-	protected $head = <<<EOF
55
+    /** @var Defaults */
56
+    protected $themingDefaults;
57
+    /** @var IURLGenerator */
58
+    protected $urlGenerator;
59
+    /** @var IFactory */
60
+    protected $l10nFactory;
61
+    /** @var string */
62
+    protected $emailId;
63
+    /** @var array */
64
+    protected $data;
65
+
66
+    /** @var string */
67
+    protected $subject = '';
68
+    /** @var string */
69
+    protected $htmlBody = '';
70
+    /** @var string */
71
+    protected $plainBody = '';
72
+    /** @var bool indicated if the footer is added */
73
+    protected $headerAdded = false;
74
+    /** @var bool indicated if the body is already opened */
75
+    protected $bodyOpened = false;
76
+    /** @var bool indicated if there is a list open in the body */
77
+    protected $bodyListOpened = false;
78
+    /** @var bool indicated if the footer is added */
79
+    protected $footerAdded = false;
80
+
81
+    protected $head = <<<EOF
82 82
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
83 83
 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" style="-webkit-font-smoothing:antialiased;background:#fff!important">
84 84
 <head>
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 				<center data-parsed="" style="min-width:580px;width:100%">
97 97
 EOF;
98 98
 
99
-	protected $tail = <<<EOF
99
+    protected $tail = <<<EOF
100 100
 					</center>
101 101
 				</td>
102 102
 			</tr>
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 
109 109
 EOF;
110 110
 
111
-	protected $header = <<<EOF
111
+    protected $header = <<<EOF
112 112
 <table align="center" class="wrapper header float-center" style="Margin:0 auto;background:#fff;border-collapse:collapse;border-spacing:0;float:none;margin:0 auto;padding:0;text-align:center;vertical-align:top;width:100%%">
113 113
 	<tr style="padding:0;text-align:left;vertical-align:top">
114 114
 		<td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 </table>
142 142
 EOF;
143 143
 
144
-	protected $heading = <<<EOF
144
+    protected $heading = <<<EOF
145 145
 <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">
146 146
 	<tbody>
147 147
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 </table>
161 161
 EOF;
162 162
 
163
-	protected $bodyBegin = <<<EOF
163
+    protected $bodyBegin = <<<EOF
164 164
 <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%">
165 165
 	<tr style="padding:0;text-align:left;vertical-align:top">
166 166
 		<td class="wrapper-inner" style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 					<td style="-moz-hyphens:auto;-webkit-hyphens:auto;Margin:0;border-collapse:collapse!important;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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">
171 171
 EOF;
172 172
 
173
-	protected $bodyText = <<<EOF
173
+    protected $bodyText = <<<EOF
174 174
 <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%%">
175 175
 	<tbody>
176 176
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 </table>
190 190
 EOF;
191 191
 
192
-	// note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151)
193
-	protected $listBegin = <<<EOF
192
+    // note: listBegin (like bodyBegin) is not processed through sprintf, so "%" is not escaped as "%%". (bug #12151)
193
+    protected $listBegin = <<<EOF
194 194
 <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%">
195 195
 	<tbody>
196 196
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 			<table style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%">
199 199
 EOF;
200 200
 
201
-	protected $listItem = <<<EOF
201
+    protected $listItem = <<<EOF
202 202
 				<tr style="padding:0;text-align:left;vertical-align:top">
203 203
 					<td style="Margin:0;color:#0a0a0a;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left;width:15px;">
204 204
 						<p class="text-left" style="Margin:0;Margin-bottom:10px;color:#777;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen-Sans,Ubuntu,Cantarell,'Helvetica Neue',Arial,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>
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 				</tr>
211 211
 EOF;
212 212
 
213
-	protected $listEnd = <<<EOF
213
+    protected $listEnd = <<<EOF
214 214
 			</table>
215 215
 		</th>
216 216
 	</tr>
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 </table>
219 219
 EOF;
220 220
 
221
-	protected $buttonGroup = <<<EOF
221
+    protected $buttonGroup = <<<EOF
222 222
 <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
223 223
 	<tbody>
224 224
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 </table>
272 272
 EOF;
273 273
 
274
-	protected $button = <<<EOF
274
+    protected $button = <<<EOF
275 275
 <table class="spacer" style="border-collapse:collapse;border-spacing:0;padding:0;text-align:left;vertical-align:top;width:100%%">
276 276
 	<tbody>
277 277
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 </table>
312 312
 EOF;
313 313
 
314
-	protected $bodyEnd = <<<EOF
314
+    protected $bodyEnd = <<<EOF
315 315
 
316 316
 					</td>
317 317
 				</tr>
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 </table>
323 323
 EOF;
324 324
 
325
-	protected $footer = <<<EOF
325
+    protected $footer = <<<EOF
326 326
 <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%%">
327 327
 	<tbody>
328 328
 	<tr style="padding:0;text-align:left;vertical-align:top">
@@ -348,327 +348,327 @@  discard block
 block discarded – undo
348 348
 </table>
349 349
 EOF;
350 350
 
351
-	public function __construct(Defaults $themingDefaults,
352
-								IURLGenerator $urlGenerator,
353
-								IFactory $l10nFactory,
354
-								$emailId,
355
-								array $data) {
356
-		$this->themingDefaults = $themingDefaults;
357
-		$this->urlGenerator = $urlGenerator;
358
-		$this->l10nFactory = $l10nFactory;
359
-		$this->htmlBody .= $this->head;
360
-		$this->emailId = $emailId;
361
-		$this->data = $data;
362
-	}
363
-
364
-	/**
365
-	 * Sets the subject of the email
366
-	 *
367
-	 * @param string $subject
368
-	 */
369
-	public function setSubject(string $subject) {
370
-		$this->subject = $subject;
371
-	}
372
-
373
-	/**
374
-	 * Adds a header to the email
375
-	 */
376
-	public function addHeader() {
377
-		if ($this->headerAdded) {
378
-			return;
379
-		}
380
-		$this->headerAdded = true;
381
-
382
-		$logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
383
-		$this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
384
-	}
385
-
386
-	/**
387
-	 * Adds a heading to the email
388
-	 *
389
-	 * @param string $title
390
-	 * @param string|bool $plainTitle Title that is used in the plain text email
391
-	 *   if empty the $title is used, if false none will be used
392
-	 */
393
-	public function addHeading(string $title, $plainTitle = '') {
394
-		if ($this->footerAdded) {
395
-			return;
396
-		}
397
-		if ($plainTitle === '') {
398
-			$plainTitle = $title;
399
-		}
400
-
401
-		$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
402
-		if ($plainTitle !== false) {
403
-			$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
404
-		}
405
-	}
406
-
407
-	/**
408
-	 * Open the HTML body when it is not already
409
-	 */
410
-	protected function ensureBodyIsOpened() {
411
-		if ($this->bodyOpened) {
412
-			return;
413
-		}
414
-
415
-		$this->htmlBody .= $this->bodyBegin;
416
-		$this->bodyOpened = true;
417
-	}
418
-
419
-	/**
420
-	 * Adds a paragraph to the body of the email
421
-	 *
422
-	 * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
423
-	 * @param string|bool $plainText Text that is used in the plain text email
424
-	 *   if empty the $text is used, if false none will be used
425
-	 */
426
-	public function addBodyText(string $text, $plainText = '') {
427
-		if ($this->footerAdded) {
428
-			return;
429
-		}
430
-		if ($plainText === '') {
431
-			$plainText = $text;
432
-			$text = htmlspecialchars($text);
433
-		}
434
-
435
-		$this->ensureBodyListClosed();
436
-		$this->ensureBodyIsOpened();
437
-
438
-		$this->htmlBody .= vsprintf($this->bodyText, [$text]);
439
-		if ($plainText !== false) {
440
-			$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
441
-		}
442
-	}
443
-
444
-	/**
445
-	 * Adds a list item to the body of the email
446
-	 *
447
-	 * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
448
-	 * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
449
-	 * @param string $icon Absolute path, must be 16*16 pixels
450
-	 * @param string|bool $plainText Text that is used in the plain text email
451
-	 *   if empty or true the $text is used, if false none will be used
452
-	 * @param string|bool $plainMetaInfo Meta info that is used in the plain text email
453
-	 *   if empty or true the $metaInfo is used, if false none will be used
454
-	 * @param integer plainIndent If > 0, Indent plainText by this amount.
455
-	 * @since 12.0.0
456
-	 */
457
-	public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0) {
458
-		$this->ensureBodyListOpened();
459
-
460
-		if ($plainText === '' || $plainText === true) {
461
-			$plainText = $text;
462
-			$text = htmlspecialchars($text);
463
-			$text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks
464
-		}
465
-		if ($plainMetaInfo === '' || $plainMetaInfo === true) {
466
-			$plainMetaInfo = $metaInfo;
467
-			$metaInfo = htmlspecialchars($metaInfo);
468
-		}
469
-
470
-		$htmlText = $text;
471
-		if ($metaInfo) {
472
-			$htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText;
473
-		}
474
-		if ($icon !== '') {
475
-			$icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
476
-		} else {
477
-			$icon = '&bull;';
478
-		}
479
-		$this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
480
-		if ($plainText !== false) {
481
-			if ($plainIndent === 0) {
482
-				/*
351
+    public function __construct(Defaults $themingDefaults,
352
+                                IURLGenerator $urlGenerator,
353
+                                IFactory $l10nFactory,
354
+                                $emailId,
355
+                                array $data) {
356
+        $this->themingDefaults = $themingDefaults;
357
+        $this->urlGenerator = $urlGenerator;
358
+        $this->l10nFactory = $l10nFactory;
359
+        $this->htmlBody .= $this->head;
360
+        $this->emailId = $emailId;
361
+        $this->data = $data;
362
+    }
363
+
364
+    /**
365
+     * Sets the subject of the email
366
+     *
367
+     * @param string $subject
368
+     */
369
+    public function setSubject(string $subject) {
370
+        $this->subject = $subject;
371
+    }
372
+
373
+    /**
374
+     * Adds a header to the email
375
+     */
376
+    public function addHeader() {
377
+        if ($this->headerAdded) {
378
+            return;
379
+        }
380
+        $this->headerAdded = true;
381
+
382
+        $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo(false));
383
+        $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]);
384
+    }
385
+
386
+    /**
387
+     * Adds a heading to the email
388
+     *
389
+     * @param string $title
390
+     * @param string|bool $plainTitle Title that is used in the plain text email
391
+     *   if empty the $title is used, if false none will be used
392
+     */
393
+    public function addHeading(string $title, $plainTitle = '') {
394
+        if ($this->footerAdded) {
395
+            return;
396
+        }
397
+        if ($plainTitle === '') {
398
+            $plainTitle = $title;
399
+        }
400
+
401
+        $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
402
+        if ($plainTitle !== false) {
403
+            $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
404
+        }
405
+    }
406
+
407
+    /**
408
+     * Open the HTML body when it is not already
409
+     */
410
+    protected function ensureBodyIsOpened() {
411
+        if ($this->bodyOpened) {
412
+            return;
413
+        }
414
+
415
+        $this->htmlBody .= $this->bodyBegin;
416
+        $this->bodyOpened = true;
417
+    }
418
+
419
+    /**
420
+     * Adds a paragraph to the body of the email
421
+     *
422
+     * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
423
+     * @param string|bool $plainText Text that is used in the plain text email
424
+     *   if empty the $text is used, if false none will be used
425
+     */
426
+    public function addBodyText(string $text, $plainText = '') {
427
+        if ($this->footerAdded) {
428
+            return;
429
+        }
430
+        if ($plainText === '') {
431
+            $plainText = $text;
432
+            $text = htmlspecialchars($text);
433
+        }
434
+
435
+        $this->ensureBodyListClosed();
436
+        $this->ensureBodyIsOpened();
437
+
438
+        $this->htmlBody .= vsprintf($this->bodyText, [$text]);
439
+        if ($plainText !== false) {
440
+            $this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
441
+        }
442
+    }
443
+
444
+    /**
445
+     * Adds a list item to the body of the email
446
+     *
447
+     * @param string $text Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
448
+     * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
449
+     * @param string $icon Absolute path, must be 16*16 pixels
450
+     * @param string|bool $plainText Text that is used in the plain text email
451
+     *   if empty or true the $text is used, if false none will be used
452
+     * @param string|bool $plainMetaInfo Meta info that is used in the plain text email
453
+     *   if empty or true the $metaInfo is used, if false none will be used
454
+     * @param integer plainIndent If > 0, Indent plainText by this amount.
455
+     * @since 12.0.0
456
+     */
457
+    public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0) {
458
+        $this->ensureBodyListOpened();
459
+
460
+        if ($plainText === '' || $plainText === true) {
461
+            $plainText = $text;
462
+            $text = htmlspecialchars($text);
463
+            $text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks
464
+        }
465
+        if ($plainMetaInfo === '' || $plainMetaInfo === true) {
466
+            $plainMetaInfo = $metaInfo;
467
+            $metaInfo = htmlspecialchars($metaInfo);
468
+        }
469
+
470
+        $htmlText = $text;
471
+        if ($metaInfo) {
472
+            $htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText;
473
+        }
474
+        if ($icon !== '') {
475
+            $icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
476
+        } else {
477
+            $icon = '&bull;';
478
+        }
479
+        $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]);
480
+        if ($plainText !== false) {
481
+            if ($plainIndent === 0) {
482
+                /*
483 483
 				 * If plainIndent is not set by caller, this is the old NC17 layout code.
484 484
 				 */
485
-				$this->plainBody .= '  * ' . $plainText;
486
-				if ($plainMetaInfo !== false) {
487
-					$this->plainBody .= ' (' . $plainMetaInfo . ')';
488
-				}
489
-				$this->plainBody .= PHP_EOL;
490
-			} else {
491
-				/*
485
+                $this->plainBody .= '  * ' . $plainText;
486
+                if ($plainMetaInfo !== false) {
487
+                    $this->plainBody .= ' (' . $plainMetaInfo . ')';
488
+                }
489
+                $this->plainBody .= PHP_EOL;
490
+            } else {
491
+                /*
492 492
 				 * Caller can set plainIndent > 0 to format plainText in tabular fashion.
493 493
 				 * with plainMetaInfo in column 1, and plainText in column 2.
494 494
 				 * The plainMetaInfo label is right justified in a field of width
495 495
 				 * "plainIndent". Multilines after the first are indented plainIndent+1
496 496
 				 * (to account for space after label).  Fixes: #12391
497 497
 				 */
498
-				/** @var string $label */
499
-				$label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
500
-				$this->plainBody .= sprintf("%${plainIndent}s %s\n",
501
-					$label,
502
-					str_replace("\n", "\n" . str_repeat(' ', $plainIndent+1), $plainText));
503
-			}
504
-		}
505
-	}
506
-
507
-	protected function ensureBodyListOpened() {
508
-		if ($this->bodyListOpened) {
509
-			return;
510
-		}
511
-
512
-		$this->ensureBodyIsOpened();
513
-		$this->bodyListOpened = true;
514
-		$this->htmlBody .= $this->listBegin;
515
-	}
516
-
517
-	protected function ensureBodyListClosed() {
518
-		if (!$this->bodyListOpened) {
519
-			return;
520
-		}
521
-
522
-		$this->bodyListOpened = false;
523
-		$this->htmlBody .= $this->listEnd;
524
-	}
525
-
526
-	/**
527
-	 * Adds a button group of two buttons to the body of the email
528
-	 *
529
-	 * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
530
-	 * @param string $urlLeft URL of left button
531
-	 * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
532
-	 * @param string $urlRight URL of right button
533
-	 * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
534
-	 * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
535
-	 */
536
-	public function addBodyButtonGroup(string $textLeft,
537
-									   string $urlLeft,
538
-									   string $textRight,
539
-									   string $urlRight,
540
-									   string $plainTextLeft = '',
541
-									   string $plainTextRight = '') {
542
-		if ($this->footerAdded) {
543
-			return;
544
-		}
545
-		if ($plainTextLeft === '') {
546
-			$plainTextLeft = $textLeft;
547
-			$textLeft = htmlspecialchars($textLeft);
548
-		}
549
-
550
-		if ($plainTextRight === '') {
551
-			$plainTextRight = $textRight;
552
-			$textRight = htmlspecialchars($textRight);
553
-		}
554
-
555
-		$this->ensureBodyIsOpened();
556
-		$this->ensureBodyListClosed();
557
-
558
-		$color = $this->themingDefaults->getColorPrimary();
559
-		$textColor = $this->themingDefaults->getTextColorPrimary();
560
-
561
-		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
562
-		$this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
563
-		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
564
-	}
565
-
566
-	/**
567
-	 * Adds a button to the body of the email
568
-	 *
569
-	 * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
570
-	 * @param string $url URL of button
571
-	 * @param string $plainText Text of button in plain text version
572
-	 * 		if empty the $text is used, if false none will be used
573
-	 *
574
-	 * @since 12.0.0
575
-	 */
576
-	public function addBodyButton(string $text, string $url, $plainText = '') {
577
-		if ($this->footerAdded) {
578
-			return;
579
-		}
580
-
581
-		$this->ensureBodyIsOpened();
582
-		$this->ensureBodyListClosed();
583
-
584
-		if ($plainText === '') {
585
-			$plainText = $text;
586
-			$text = htmlspecialchars($text);
587
-		}
588
-
589
-		$color = $this->themingDefaults->getColorPrimary();
590
-		$textColor = $this->themingDefaults->getTextColorPrimary();
591
-		$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);
592
-
593
-		if ($plainText !== false) {
594
-			$this->plainBody .= $plainText . ': ';
595
-		}
596
-
597
-		$this->plainBody .=  $url . PHP_EOL;
598
-	}
599
-
600
-	/**
601
-	 * Close the HTML body when it is open
602
-	 */
603
-	protected function ensureBodyIsClosed() {
604
-		if (!$this->bodyOpened) {
605
-			return;
606
-		}
607
-
608
-		$this->ensureBodyListClosed();
609
-
610
-		$this->htmlBody .= $this->bodyEnd;
611
-		$this->bodyOpened = false;
612
-	}
613
-
614
-	/**
615
-	 * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
616
-	 *
617
-	 * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
618
-	 */
619
-	public function addFooter(string $text = '', ?string $lang = null) {
620
-		if ($text === '') {
621
-			$l10n = $this->l10nFactory->get('lib', $lang);
622
-			$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
623
-		}
624
-
625
-		if ($this->footerAdded) {
626
-			return;
627
-		}
628
-		$this->footerAdded = true;
629
-
630
-		$this->ensureBodyIsClosed();
631
-
632
-		$this->htmlBody .= vsprintf($this->footer, [$text]);
633
-		$this->htmlBody .= $this->tail;
634
-		$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
635
-		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
636
-	}
637
-
638
-	/**
639
-	 * Returns the rendered email subject as string
640
-	 *
641
-	 * @return string
642
-	 */
643
-	public function renderSubject(): string {
644
-		return $this->subject;
645
-	}
646
-
647
-	/**
648
-	 * Returns the rendered HTML email as string
649
-	 *
650
-	 * @return string
651
-	 */
652
-	public function renderHtml(): string {
653
-		if (!$this->footerAdded) {
654
-			$this->footerAdded = true;
655
-			$this->ensureBodyIsClosed();
656
-			$this->htmlBody .= $this->tail;
657
-		}
658
-		return $this->htmlBody;
659
-	}
660
-
661
-	/**
662
-	 * Returns the rendered plain text email as string
663
-	 *
664
-	 * @return string
665
-	 */
666
-	public function renderText(): string {
667
-		if (!$this->footerAdded) {
668
-			$this->footerAdded = true;
669
-			$this->ensureBodyIsClosed();
670
-			$this->htmlBody .= $this->tail;
671
-		}
672
-		return $this->plainBody;
673
-	}
498
+                /** @var string $label */
499
+                $label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
500
+                $this->plainBody .= sprintf("%${plainIndent}s %s\n",
501
+                    $label,
502
+                    str_replace("\n", "\n" . str_repeat(' ', $plainIndent+1), $plainText));
503
+            }
504
+        }
505
+    }
506
+
507
+    protected function ensureBodyListOpened() {
508
+        if ($this->bodyListOpened) {
509
+            return;
510
+        }
511
+
512
+        $this->ensureBodyIsOpened();
513
+        $this->bodyListOpened = true;
514
+        $this->htmlBody .= $this->listBegin;
515
+    }
516
+
517
+    protected function ensureBodyListClosed() {
518
+        if (!$this->bodyListOpened) {
519
+            return;
520
+        }
521
+
522
+        $this->bodyListOpened = false;
523
+        $this->htmlBody .= $this->listEnd;
524
+    }
525
+
526
+    /**
527
+     * Adds a button group of two buttons to the body of the email
528
+     *
529
+     * @param string $textLeft Text of left button; Note: When $plainTextLeft falls back to this, HTML is automatically escaped in the HTML email
530
+     * @param string $urlLeft URL of left button
531
+     * @param string $textRight Text of right button; Note: When $plainTextRight falls back to this, HTML is automatically escaped in the HTML email
532
+     * @param string $urlRight URL of right button
533
+     * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used
534
+     * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used
535
+     */
536
+    public function addBodyButtonGroup(string $textLeft,
537
+                                        string $urlLeft,
538
+                                        string $textRight,
539
+                                        string $urlRight,
540
+                                        string $plainTextLeft = '',
541
+                                        string $plainTextRight = '') {
542
+        if ($this->footerAdded) {
543
+            return;
544
+        }
545
+        if ($plainTextLeft === '') {
546
+            $plainTextLeft = $textLeft;
547
+            $textLeft = htmlspecialchars($textLeft);
548
+        }
549
+
550
+        if ($plainTextRight === '') {
551
+            $plainTextRight = $textRight;
552
+            $textRight = htmlspecialchars($textRight);
553
+        }
554
+
555
+        $this->ensureBodyIsOpened();
556
+        $this->ensureBodyListClosed();
557
+
558
+        $color = $this->themingDefaults->getColorPrimary();
559
+        $textColor = $this->themingDefaults->getTextColorPrimary();
560
+
561
+        $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
562
+        $this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
563
+        $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
564
+    }
565
+
566
+    /**
567
+     * Adds a button to the body of the email
568
+     *
569
+     * @param string $text Text of button; Note: When $plainText falls back to this, HTML is automatically escaped in the HTML email
570
+     * @param string $url URL of button
571
+     * @param string $plainText Text of button in plain text version
572
+     * 		if empty the $text is used, if false none will be used
573
+     *
574
+     * @since 12.0.0
575
+     */
576
+    public function addBodyButton(string $text, string $url, $plainText = '') {
577
+        if ($this->footerAdded) {
578
+            return;
579
+        }
580
+
581
+        $this->ensureBodyIsOpened();
582
+        $this->ensureBodyListClosed();
583
+
584
+        if ($plainText === '') {
585
+            $plainText = $text;
586
+            $text = htmlspecialchars($text);
587
+        }
588
+
589
+        $color = $this->themingDefaults->getColorPrimary();
590
+        $textColor = $this->themingDefaults->getTextColorPrimary();
591
+        $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);
592
+
593
+        if ($plainText !== false) {
594
+            $this->plainBody .= $plainText . ': ';
595
+        }
596
+
597
+        $this->plainBody .=  $url . PHP_EOL;
598
+    }
599
+
600
+    /**
601
+     * Close the HTML body when it is open
602
+     */
603
+    protected function ensureBodyIsClosed() {
604
+        if (!$this->bodyOpened) {
605
+            return;
606
+        }
607
+
608
+        $this->ensureBodyListClosed();
609
+
610
+        $this->htmlBody .= $this->bodyEnd;
611
+        $this->bodyOpened = false;
612
+    }
613
+
614
+    /**
615
+     * Adds a logo and a text to the footer. <br> in the text will be replaced by new lines in the plain text email
616
+     *
617
+     * @param string $text If the text is empty the default "Name - Slogan<br>This is an automatically sent email" will be used
618
+     */
619
+    public function addFooter(string $text = '', ?string $lang = null) {
620
+        if ($text === '') {
621
+            $l10n = $this->l10nFactory->get('lib', $lang);
622
+            $text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
623
+        }
624
+
625
+        if ($this->footerAdded) {
626
+            return;
627
+        }
628
+        $this->footerAdded = true;
629
+
630
+        $this->ensureBodyIsClosed();
631
+
632
+        $this->htmlBody .= vsprintf($this->footer, [$text]);
633
+        $this->htmlBody .= $this->tail;
634
+        $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
635
+        $this->plainBody .= str_replace('<br>', PHP_EOL, $text);
636
+    }
637
+
638
+    /**
639
+     * Returns the rendered email subject as string
640
+     *
641
+     * @return string
642
+     */
643
+    public function renderSubject(): string {
644
+        return $this->subject;
645
+    }
646
+
647
+    /**
648
+     * Returns the rendered HTML email as string
649
+     *
650
+     * @return string
651
+     */
652
+    public function renderHtml(): string {
653
+        if (!$this->footerAdded) {
654
+            $this->footerAdded = true;
655
+            $this->ensureBodyIsClosed();
656
+            $this->htmlBody .= $this->tail;
657
+        }
658
+        return $this->htmlBody;
659
+    }
660
+
661
+    /**
662
+     * Returns the rendered plain text email as string
663
+     *
664
+     * @return string
665
+     */
666
+    public function renderText(): string {
667
+        if (!$this->footerAdded) {
668
+            $this->footerAdded = true;
669
+            $this->ensureBodyIsClosed();
670
+            $this->htmlBody .= $this->tail;
671
+        }
672
+        return $this->plainBody;
673
+    }
674 674
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 
401 401
 		$this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]);
402 402
 		if ($plainTitle !== false) {
403
-			$this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL;
403
+			$this->plainBody .= $plainTitle.PHP_EOL.PHP_EOL;
404 404
 		}
405 405
 	}
406 406
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 
438 438
 		$this->htmlBody .= vsprintf($this->bodyText, [$text]);
439 439
 		if ($plainText !== false) {
440
-			$this->plainBody .= $plainText . PHP_EOL . PHP_EOL;
440
+			$this->plainBody .= $plainText.PHP_EOL.PHP_EOL;
441 441
 		}
442 442
 	}
443 443
 
@@ -469,10 +469,10 @@  discard block
 block discarded – undo
469 469
 
470 470
 		$htmlText = $text;
471 471
 		if ($metaInfo) {
472
-			$htmlText = '<em style="color:#777;">' . $metaInfo . '</em><br>' . $htmlText;
472
+			$htmlText = '<em style="color:#777;">'.$metaInfo.'</em><br>'.$htmlText;
473 473
 		}
474 474
 		if ($icon !== '') {
475
-			$icon = '<img src="' . htmlspecialchars($icon) . '" alt="&bull;">';
475
+			$icon = '<img src="'.htmlspecialchars($icon).'" alt="&bull;">';
476 476
 		} else {
477 477
 			$icon = '&bull;';
478 478
 		}
@@ -482,9 +482,9 @@  discard block
 block discarded – undo
482 482
 				/*
483 483
 				 * If plainIndent is not set by caller, this is the old NC17 layout code.
484 484
 				 */
485
-				$this->plainBody .= '  * ' . $plainText;
485
+				$this->plainBody .= '  * '.$plainText;
486 486
 				if ($plainMetaInfo !== false) {
487
-					$this->plainBody .= ' (' . $plainMetaInfo . ')';
487
+					$this->plainBody .= ' ('.$plainMetaInfo.')';
488 488
 				}
489 489
 				$this->plainBody .= PHP_EOL;
490 490
 			} else {
@@ -496,10 +496,10 @@  discard block
 block discarded – undo
496 496
 				 * (to account for space after label).  Fixes: #12391
497 497
 				 */
498 498
 				/** @var string $label */
499
-				$label = ($plainMetaInfo !== false)? $plainMetaInfo : '';
499
+				$label = ($plainMetaInfo !== false) ? $plainMetaInfo : '';
500 500
 				$this->plainBody .= sprintf("%${plainIndent}s %s\n",
501 501
 					$label,
502
-					str_replace("\n", "\n" . str_repeat(' ', $plainIndent+1), $plainText));
502
+					str_replace("\n", "\n".str_repeat(' ', $plainIndent + 1), $plainText));
503 503
 			}
504 504
 		}
505 505
 	}
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 		$textColor = $this->themingDefaults->getTextColorPrimary();
560 560
 
561 561
 		$this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]);
562
-		$this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL;
563
-		$this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL;
562
+		$this->plainBody .= PHP_EOL.$plainTextLeft.': '.$urlLeft.PHP_EOL;
563
+		$this->plainBody .= $plainTextRight.': '.$urlRight.PHP_EOL.PHP_EOL;
564 564
 	}
565 565
 
566 566
 	/**
@@ -591,10 +591,10 @@  discard block
 block discarded – undo
591 591
 		$this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, $textColor, $textColor, $text]);
592 592
 
593 593
 		if ($plainText !== false) {
594
-			$this->plainBody .= $plainText . ': ';
594
+			$this->plainBody .= $plainText.': ';
595 595
 		}
596 596
 
597
-		$this->plainBody .=  $url . PHP_EOL;
597
+		$this->plainBody .= $url.PHP_EOL;
598 598
 	}
599 599
 
600 600
 	/**
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 	public function addFooter(string $text = '', ?string $lang = null) {
620 620
 		if ($text === '') {
621 621
 			$l10n = $this->l10nFactory->get('lib', $lang);
622
-			$text = $this->themingDefaults->getName() . ' - ' . $this->themingDefaults->getSlogan($lang) . '<br>' . $l10n->t('This is an automatically sent email, please do not reply.');
622
+			$text = $this->themingDefaults->getName().' - '.$this->themingDefaults->getSlogan($lang).'<br>'.$l10n->t('This is an automatically sent email, please do not reply.');
623 623
 		}
624 624
 
625 625
 		if ($this->footerAdded) {
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
 
632 632
 		$this->htmlBody .= vsprintf($this->footer, [$text]);
633 633
 		$this->htmlBody .= $this->tail;
634
-		$this->plainBody .= PHP_EOL . '-- ' . PHP_EOL;
634
+		$this->plainBody .= PHP_EOL.'-- '.PHP_EOL;
635 635
 		$this->plainBody .= str_replace('<br>', PHP_EOL, $text);
636 636
 	}
637 637
 
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Schedule/IMipPlugin.php 2 patches
Indentation   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -69,186 +69,186 @@  discard block
 block discarded – undo
69 69
  */
70 70
 class IMipPlugin extends SabreIMipPlugin {
71 71
 
72
-	/** @var string */
73
-	private $userId;
74
-
75
-	/** @var IConfig */
76
-	private $config;
77
-
78
-	/** @var IMailer */
79
-	private $mailer;
80
-
81
-	/** @var ILogger */
82
-	private $logger;
83
-
84
-	/** @var ITimeFactory */
85
-	private $timeFactory;
86
-
87
-	/** @var L10NFactory */
88
-	private $l10nFactory;
89
-
90
-	/** @var IURLGenerator */
91
-	private $urlGenerator;
92
-
93
-	/** @var ISecureRandom */
94
-	private $random;
95
-
96
-	/** @var IDBConnection */
97
-	private $db;
98
-
99
-	/** @var Defaults */
100
-	private $defaults;
101
-
102
-	/** @var IUserManager */
103
-	private $userManager;
104
-
105
-	public const MAX_DATE = '2038-01-01';
106
-
107
-	public const METHOD_REQUEST = 'request';
108
-	public const METHOD_REPLY = 'reply';
109
-	public const METHOD_CANCEL = 'cancel';
110
-	public const IMIP_INDENT = 15; // Enough for the length of all body bullet items, in all languages
111
-
112
-	/**
113
-	 * @param IConfig $config
114
-	 * @param IMailer $mailer
115
-	 * @param ILogger $logger
116
-	 * @param ITimeFactory $timeFactory
117
-	 * @param L10NFactory $l10nFactory
118
-	 * @param IUrlGenerator $urlGenerator
119
-	 * @param Defaults $defaults
120
-	 * @param ISecureRandom $random
121
-	 * @param IDBConnection $db
122
-	 * @param string $userId
123
-	 */
124
-	public function __construct(IConfig $config, IMailer $mailer, ILogger $logger,
125
-								ITimeFactory $timeFactory, L10NFactory $l10nFactory,
126
-								IURLGenerator $urlGenerator, Defaults $defaults,
127
-								ISecureRandom $random, IDBConnection $db, IUserManager $userManager,
128
-								$userId) {
129
-		parent::__construct('');
130
-		$this->userId = $userId;
131
-		$this->config = $config;
132
-		$this->mailer = $mailer;
133
-		$this->logger = $logger;
134
-		$this->timeFactory = $timeFactory;
135
-		$this->l10nFactory = $l10nFactory;
136
-		$this->urlGenerator = $urlGenerator;
137
-		$this->random = $random;
138
-		$this->db = $db;
139
-		$this->defaults = $defaults;
140
-		$this->userManager = $userManager;
141
-	}
142
-
143
-	/**
144
-	 * Event handler for the 'schedule' event.
145
-	 *
146
-	 * @param Message $iTipMessage
147
-	 * @return void
148
-	 */
149
-	public function schedule(Message $iTipMessage) {
150
-
151
-		// Not sending any emails if the system considers the update
152
-		// insignificant.
153
-		if (!$iTipMessage->significantChange) {
154
-			if (!$iTipMessage->scheduleStatus) {
155
-				$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
156
-			}
157
-			return;
158
-		}
159
-
160
-		$summary = $iTipMessage->message->VEVENT->SUMMARY;
161
-
162
-		if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
163
-			return;
164
-		}
165
-
166
-		if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
167
-			return;
168
-		}
169
-
170
-		// don't send out mails for events that already took place
171
-		$lastOccurrence = $this->getLastOccurrence($iTipMessage->message);
172
-		$currentTime = $this->timeFactory->getTime();
173
-		if ($lastOccurrence < $currentTime) {
174
-			return;
175
-		}
176
-
177
-		// Strip off mailto:
178
-		$sender = substr($iTipMessage->sender, 7);
179
-		$recipient = substr($iTipMessage->recipient, 7);
180
-
181
-		$senderName = $iTipMessage->senderName ?: null;
182
-		$recipientName = $iTipMessage->recipientName ?: null;
183
-
184
-		if ($senderName === null || empty(trim($senderName))) {
185
-			$user = $this->userManager->get($this->userId);
186
-			if ($user) {
187
-				// getDisplayName automatically uses the uid
188
-				// if no display-name is set
189
-				$senderName = $user->getDisplayName();
190
-			}
191
-		}
192
-
193
-		/** @var VEvent $vevent */
194
-		$vevent = $iTipMessage->message->VEVENT;
195
-
196
-		$attendee = $this->getCurrentAttendee($iTipMessage);
197
-		$defaultLang = $this->l10nFactory->findLanguage();
198
-		$lang = $this->getAttendeeLangOrDefault($defaultLang, $attendee);
199
-		$l10n = $this->l10nFactory->get('dav', $lang);
200
-
201
-		$meetingAttendeeName = $recipientName ?: $recipient;
202
-		$meetingInviteeName = $senderName ?: $sender;
203
-
204
-		$meetingTitle = $vevent->SUMMARY;
205
-		$meetingDescription = $vevent->DESCRIPTION;
206
-
207
-
208
-		$meetingUrl = $vevent->URL;
209
-		$meetingLocation = $vevent->LOCATION;
210
-
211
-		$defaultVal = '--';
212
-
213
-		$method = self::METHOD_REQUEST;
214
-		switch (strtolower($iTipMessage->method)) {
215
-			case self::METHOD_REPLY:
216
-				$method = self::METHOD_REPLY;
217
-				break;
218
-			case self::METHOD_CANCEL:
219
-				$method = self::METHOD_CANCEL;
220
-				break;
221
-		}
222
-
223
-		$data = [
224
-			'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal,
225
-			'invitee_name' => (string)$meetingInviteeName ?: $defaultVal,
226
-			'meeting_title' => (string)$meetingTitle ?: $defaultVal,
227
-			'meeting_description' => (string)$meetingDescription ?: $defaultVal,
228
-			'meeting_url' => (string)$meetingUrl ?: $defaultVal,
229
-		];
230
-
231
-		$fromEMail = Util::getDefaultEmailAddress('invitations-noreply');
232
-		$fromName = $l10n->t('%1$s via %2$s', [$senderName, $this->defaults->getName()]);
233
-
234
-		$message = $this->mailer->createMessage()
235
-			->setFrom([$fromEMail => $fromName])
236
-			->setReplyTo([$sender => $senderName])
237
-			->setTo([$recipient => $recipientName]);
238
-
239
-		$template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
240
-		$template->addHeader();
241
-
242
-		$summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Untitled event');
243
-
244
-		$this->addSubjectAndHeading($template, $l10n, $method, $summary);
245
-		$this->addBulletList($template, $l10n, $vevent);
246
-
247
-
248
-		// Only add response buttons to invitation requests: Fix Issue #11230
249
-		if (($method == self::METHOD_REQUEST) && $this->getAttendeeRSVP($attendee)) {
72
+    /** @var string */
73
+    private $userId;
74
+
75
+    /** @var IConfig */
76
+    private $config;
77
+
78
+    /** @var IMailer */
79
+    private $mailer;
80
+
81
+    /** @var ILogger */
82
+    private $logger;
83
+
84
+    /** @var ITimeFactory */
85
+    private $timeFactory;
86
+
87
+    /** @var L10NFactory */
88
+    private $l10nFactory;
89
+
90
+    /** @var IURLGenerator */
91
+    private $urlGenerator;
92
+
93
+    /** @var ISecureRandom */
94
+    private $random;
95
+
96
+    /** @var IDBConnection */
97
+    private $db;
98
+
99
+    /** @var Defaults */
100
+    private $defaults;
101
+
102
+    /** @var IUserManager */
103
+    private $userManager;
104
+
105
+    public const MAX_DATE = '2038-01-01';
106
+
107
+    public const METHOD_REQUEST = 'request';
108
+    public const METHOD_REPLY = 'reply';
109
+    public const METHOD_CANCEL = 'cancel';
110
+    public const IMIP_INDENT = 15; // Enough for the length of all body bullet items, in all languages
111
+
112
+    /**
113
+     * @param IConfig $config
114
+     * @param IMailer $mailer
115
+     * @param ILogger $logger
116
+     * @param ITimeFactory $timeFactory
117
+     * @param L10NFactory $l10nFactory
118
+     * @param IUrlGenerator $urlGenerator
119
+     * @param Defaults $defaults
120
+     * @param ISecureRandom $random
121
+     * @param IDBConnection $db
122
+     * @param string $userId
123
+     */
124
+    public function __construct(IConfig $config, IMailer $mailer, ILogger $logger,
125
+                                ITimeFactory $timeFactory, L10NFactory $l10nFactory,
126
+                                IURLGenerator $urlGenerator, Defaults $defaults,
127
+                                ISecureRandom $random, IDBConnection $db, IUserManager $userManager,
128
+                                $userId) {
129
+        parent::__construct('');
130
+        $this->userId = $userId;
131
+        $this->config = $config;
132
+        $this->mailer = $mailer;
133
+        $this->logger = $logger;
134
+        $this->timeFactory = $timeFactory;
135
+        $this->l10nFactory = $l10nFactory;
136
+        $this->urlGenerator = $urlGenerator;
137
+        $this->random = $random;
138
+        $this->db = $db;
139
+        $this->defaults = $defaults;
140
+        $this->userManager = $userManager;
141
+    }
142
+
143
+    /**
144
+     * Event handler for the 'schedule' event.
145
+     *
146
+     * @param Message $iTipMessage
147
+     * @return void
148
+     */
149
+    public function schedule(Message $iTipMessage) {
150
+
151
+        // Not sending any emails if the system considers the update
152
+        // insignificant.
153
+        if (!$iTipMessage->significantChange) {
154
+            if (!$iTipMessage->scheduleStatus) {
155
+                $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
156
+            }
157
+            return;
158
+        }
159
+
160
+        $summary = $iTipMessage->message->VEVENT->SUMMARY;
161
+
162
+        if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
163
+            return;
164
+        }
165
+
166
+        if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
167
+            return;
168
+        }
169
+
170
+        // don't send out mails for events that already took place
171
+        $lastOccurrence = $this->getLastOccurrence($iTipMessage->message);
172
+        $currentTime = $this->timeFactory->getTime();
173
+        if ($lastOccurrence < $currentTime) {
174
+            return;
175
+        }
176
+
177
+        // Strip off mailto:
178
+        $sender = substr($iTipMessage->sender, 7);
179
+        $recipient = substr($iTipMessage->recipient, 7);
180
+
181
+        $senderName = $iTipMessage->senderName ?: null;
182
+        $recipientName = $iTipMessage->recipientName ?: null;
183
+
184
+        if ($senderName === null || empty(trim($senderName))) {
185
+            $user = $this->userManager->get($this->userId);
186
+            if ($user) {
187
+                // getDisplayName automatically uses the uid
188
+                // if no display-name is set
189
+                $senderName = $user->getDisplayName();
190
+            }
191
+        }
192
+
193
+        /** @var VEvent $vevent */
194
+        $vevent = $iTipMessage->message->VEVENT;
195
+
196
+        $attendee = $this->getCurrentAttendee($iTipMessage);
197
+        $defaultLang = $this->l10nFactory->findLanguage();
198
+        $lang = $this->getAttendeeLangOrDefault($defaultLang, $attendee);
199
+        $l10n = $this->l10nFactory->get('dav', $lang);
200
+
201
+        $meetingAttendeeName = $recipientName ?: $recipient;
202
+        $meetingInviteeName = $senderName ?: $sender;
203
+
204
+        $meetingTitle = $vevent->SUMMARY;
205
+        $meetingDescription = $vevent->DESCRIPTION;
206
+
207
+
208
+        $meetingUrl = $vevent->URL;
209
+        $meetingLocation = $vevent->LOCATION;
210
+
211
+        $defaultVal = '--';
212
+
213
+        $method = self::METHOD_REQUEST;
214
+        switch (strtolower($iTipMessage->method)) {
215
+            case self::METHOD_REPLY:
216
+                $method = self::METHOD_REPLY;
217
+                break;
218
+            case self::METHOD_CANCEL:
219
+                $method = self::METHOD_CANCEL;
220
+                break;
221
+        }
222
+
223
+        $data = [
224
+            'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal,
225
+            'invitee_name' => (string)$meetingInviteeName ?: $defaultVal,
226
+            'meeting_title' => (string)$meetingTitle ?: $defaultVal,
227
+            'meeting_description' => (string)$meetingDescription ?: $defaultVal,
228
+            'meeting_url' => (string)$meetingUrl ?: $defaultVal,
229
+        ];
230
+
231
+        $fromEMail = Util::getDefaultEmailAddress('invitations-noreply');
232
+        $fromName = $l10n->t('%1$s via %2$s', [$senderName, $this->defaults->getName()]);
233
+
234
+        $message = $this->mailer->createMessage()
235
+            ->setFrom([$fromEMail => $fromName])
236
+            ->setReplyTo([$sender => $senderName])
237
+            ->setTo([$recipient => $recipientName]);
238
+
239
+        $template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
240
+        $template->addHeader();
241
+
242
+        $summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Untitled event');
243
+
244
+        $this->addSubjectAndHeading($template, $l10n, $method, $summary);
245
+        $this->addBulletList($template, $l10n, $vevent);
246
+
247
+
248
+        // Only add response buttons to invitation requests: Fix Issue #11230
249
+        if (($method == self::METHOD_REQUEST) && $this->getAttendeeRSVP($attendee)) {
250 250
 
251
-			/*
251
+            /*
252 252
 			** Only offer invitation accept/reject buttons, which link back to the
253 253
 			** nextcloud server, to recipients who can access the nextcloud server via
254 254
 			** their internet/intranet.  Issue #12156
@@ -267,441 +267,441 @@  discard block
 block discarded – undo
267 267
 			** To suppress URLs entirely, set invitation_link_recipients to boolean "no".
268 268
 			*/
269 269
 
270
-			$recipientDomain = substr(strrchr($recipient, "@"), 1);
271
-			$invitationLinkRecipients = explode(',', preg_replace('/\s+/', '', strtolower($this->config->getAppValue('dav', 'invitation_link_recipients', 'yes'))));
272
-
273
-			if (strcmp('yes', $invitationLinkRecipients[0]) === 0
274
-				 || in_array(strtolower($recipient), $invitationLinkRecipients)
275
-				 || in_array(strtolower($recipientDomain), $invitationLinkRecipients)) {
276
-				$this->addResponseButtons($template, $l10n, $iTipMessage, $lastOccurrence);
277
-			}
278
-		}
279
-
280
-		$template->addFooter();
281
-
282
-		$message->useTemplate($template);
283
-
284
-		$attachment = $this->mailer->createAttachment(
285
-			$iTipMessage->message->serialize(),
286
-			'event.ics',// TODO(leon): Make file name unique, e.g. add event id
287
-			'text/calendar; method=' . $iTipMessage->method
288
-		);
289
-		$message->attach($attachment);
290
-
291
-		try {
292
-			$failed = $this->mailer->send($message);
293
-			$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
294
-			if ($failed) {
295
-				$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' =>  implode(', ', $failed)]);
296
-				$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
297
-			}
298
-		} catch (\Exception $ex) {
299
-			$this->logger->logException($ex, ['app' => 'dav']);
300
-			$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
301
-		}
302
-	}
303
-
304
-	/**
305
-	 * check if event took place in the past already
306
-	 * @param VCalendar $vObject
307
-	 * @return int
308
-	 */
309
-	private function getLastOccurrence(VCalendar $vObject) {
310
-		/** @var VEvent $component */
311
-		$component = $vObject->VEVENT;
312
-
313
-		$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
314
-		// Finding the last occurrence is a bit harder
315
-		if (!isset($component->RRULE)) {
316
-			if (isset($component->DTEND)) {
317
-				$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
318
-			} elseif (isset($component->DURATION)) {
319
-				/** @var \DateTime $endDate */
320
-				$endDate = clone $component->DTSTART->getDateTime();
321
-				// $component->DTEND->getDateTime() returns DateTimeImmutable
322
-				$endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
323
-				$lastOccurrence = $endDate->getTimestamp();
324
-			} elseif (!$component->DTSTART->hasTime()) {
325
-				/** @var \DateTime $endDate */
326
-				$endDate = clone $component->DTSTART->getDateTime();
327
-				// $component->DTSTART->getDateTime() returns DateTimeImmutable
328
-				$endDate = $endDate->modify('+1 day');
329
-				$lastOccurrence = $endDate->getTimestamp();
330
-			} else {
331
-				$lastOccurrence = $firstOccurrence;
332
-			}
333
-		} else {
334
-			$it = new EventIterator($vObject, (string)$component->UID);
335
-			$maxDate = new \DateTime(self::MAX_DATE);
336
-			if ($it->isInfinite()) {
337
-				$lastOccurrence = $maxDate->getTimestamp();
338
-			} else {
339
-				$end = $it->getDtEnd();
340
-				while ($it->valid() && $end < $maxDate) {
341
-					$end = $it->getDtEnd();
342
-					$it->next();
343
-				}
344
-				$lastOccurrence = $end->getTimestamp();
345
-			}
346
-		}
347
-
348
-		return $lastOccurrence;
349
-	}
350
-
351
-	/**
352
-	 * @param Message $iTipMessage
353
-	 * @return null|Property
354
-	 */
355
-	private function getCurrentAttendee(Message $iTipMessage) {
356
-		/** @var VEvent $vevent */
357
-		$vevent = $iTipMessage->message->VEVENT;
358
-		$attendees = $vevent->select('ATTENDEE');
359
-		foreach ($attendees as $attendee) {
360
-			/** @var Property $attendee */
361
-			if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
362
-				return $attendee;
363
-			}
364
-		}
365
-		return null;
366
-	}
367
-
368
-	/**
369
-	 * @param string $default
370
-	 * @param Property|null $attendee
371
-	 * @return string
372
-	 */
373
-	private function getAttendeeLangOrDefault($default, Property $attendee = null) {
374
-		if ($attendee !== null) {
375
-			$lang = $attendee->offsetGet('LANGUAGE');
376
-			if ($lang instanceof Parameter) {
377
-				return $lang->getValue();
378
-			}
379
-		}
380
-		return $default;
381
-	}
382
-
383
-	/**
384
-	 * @param Property|null $attendee
385
-	 * @return bool
386
-	 */
387
-	private function getAttendeeRSVP(Property $attendee = null) {
388
-		if ($attendee !== null) {
389
-			$rsvp = $attendee->offsetGet('RSVP');
390
-			if (($rsvp instanceof Parameter) && (strcasecmp($rsvp->getValue(), 'TRUE') === 0)) {
391
-				return true;
392
-			}
393
-		}
394
-		// RFC 5545 3.2.17: default RSVP is false
395
-		return false;
396
-	}
397
-
398
-	/**
399
-	 * @param IL10N $l10n
400
-	 * @param VEvent $vevent
401
-	 */
402
-	private function generateWhenString(IL10N $l10n, VEvent $vevent) {
403
-		$dtstart = $vevent->DTSTART;
404
-		if (isset($vevent->DTEND)) {
405
-			$dtend = $vevent->DTEND;
406
-		} elseif (isset($vevent->DURATION)) {
407
-			$isFloating = $vevent->DTSTART->isFloating();
408
-			$dtend = clone $vevent->DTSTART;
409
-			$endDateTime = $dtend->getDateTime();
410
-			$endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
411
-			$dtend->setDateTime($endDateTime, $isFloating);
412
-		} elseif (!$vevent->DTSTART->hasTime()) {
413
-			$isFloating = $vevent->DTSTART->isFloating();
414
-			$dtend = clone $vevent->DTSTART;
415
-			$endDateTime = $dtend->getDateTime();
416
-			$endDateTime = $endDateTime->modify('+1 day');
417
-			$dtend->setDateTime($endDateTime, $isFloating);
418
-		} else {
419
-			$dtend = clone $vevent->DTSTART;
420
-		}
421
-
422
-		$isAllDay = $dtstart instanceof Property\ICalendar\Date;
423
-
424
-		/** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */
425
-		/** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtend */
426
-		/** @var \DateTimeImmutable $dtstartDt */
427
-		$dtstartDt = $dtstart->getDateTime();
428
-		/** @var \DateTimeImmutable $dtendDt */
429
-		$dtendDt = $dtend->getDateTime();
430
-
431
-		$diff = $dtstartDt->diff($dtendDt);
432
-
433
-		$dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM));
434
-		$dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM));
435
-
436
-		if ($isAllDay) {
437
-			// One day event
438
-			if ($diff->days === 1) {
439
-				return $l10n->l('date', $dtstartDt, ['width' => 'medium']);
440
-			}
441
-
442
-			// DTEND is exclusive, so if the ics data says 2020-01-01 to 2020-01-05,
443
-			// the email should show 2020-01-01 to 2020-01-04.
444
-			$dtendDt->modify('-1 day');
445
-
446
-			//event that spans over multiple days
447
-			$localeStart = $l10n->l('date', $dtstartDt, ['width' => 'medium']);
448
-			$localeEnd = $l10n->l('date', $dtendDt, ['width' => 'medium']);
449
-
450
-			return $localeStart . ' - ' . $localeEnd;
451
-		}
452
-
453
-		/** @var Property\ICalendar\DateTime $dtstart */
454
-		/** @var Property\ICalendar\DateTime $dtend */
455
-		$isFloating = $dtstart->isFloating();
456
-		$startTimezone = $endTimezone = null;
457
-		if (!$isFloating) {
458
-			$prop = $dtstart->offsetGet('TZID');
459
-			if ($prop instanceof Parameter) {
460
-				$startTimezone = $prop->getValue();
461
-			}
462
-
463
-			$prop = $dtend->offsetGet('TZID');
464
-			if ($prop instanceof Parameter) {
465
-				$endTimezone = $prop->getValue();
466
-			}
467
-		}
468
-
469
-		$localeStart = $l10n->l('weekdayName', $dtstartDt, ['width' => 'abbreviated']) . ', ' .
470
-			$l10n->l('datetime', $dtstartDt, ['width' => 'medium|short']);
471
-
472
-		// always show full date with timezone if timezones are different
473
-		if ($startTimezone !== $endTimezone) {
474
-			$localeEnd = $l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
475
-
476
-			return $localeStart . ' (' . $startTimezone . ') - ' .
477
-				$localeEnd . ' (' . $endTimezone . ')';
478
-		}
479
-
480
-		// show only end time if date is the same
481
-		if ($this->isDayEqual($dtstartDt, $dtendDt)) {
482
-			$localeEnd = $l10n->l('time', $dtendDt, ['width' => 'short']);
483
-		} else {
484
-			$localeEnd = $l10n->l('weekdayName', $dtendDt, ['width' => 'abbreviated']) . ', ' .
485
-				$l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
486
-		}
487
-
488
-		return  $localeStart . ' - ' . $localeEnd . ' (' . $startTimezone . ')';
489
-	}
490
-
491
-	/**
492
-	 * @param \DateTime $dtStart
493
-	 * @param \DateTime $dtEnd
494
-	 * @return bool
495
-	 */
496
-	private function isDayEqual(\DateTime $dtStart, \DateTime $dtEnd) {
497
-		return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
498
-	}
499
-
500
-	/**
501
-	 * @param IEMailTemplate $template
502
-	 * @param IL10N $l10n
503
-	 * @param string $method
504
-	 * @param string $summary
505
-	 */
506
-	private function addSubjectAndHeading(IEMailTemplate $template, IL10N $l10n,
507
-										  $method, $summary) {
508
-		if ($method === self::METHOD_CANCEL) {
509
-			$template->setSubject('Canceled: ' . $summary);
510
-			$template->addHeading($l10n->t('Invitation canceled'));
511
-		} elseif ($method === self::METHOD_REPLY) {
512
-			$template->setSubject('Re: ' . $summary);
513
-			$template->addHeading($l10n->t('Invitation updated'));
514
-		} else {
515
-			$template->setSubject('Invitation: ' . $summary);
516
-			$template->addHeading($l10n->t('Invitation'));
517
-		}
518
-	}
519
-
520
-	/**
521
-	 * @param IEMailTemplate $template
522
-	 * @param IL10N $l10n
523
-	 * @param VEVENT $vevent
524
-	 */
525
-	private function addBulletList(IEMailTemplate $template, IL10N $l10n, $vevent) {
526
-		if ($vevent->SUMMARY) {
527
-			$template->addBodyListItem($vevent->SUMMARY, $l10n->t('Title:'),
528
-				$this->getAbsoluteImagePath('caldav/title.svg'),'','',self::IMIP_INDENT);
529
-		}
530
-		$meetingWhen = $this->generateWhenString($l10n, $vevent);
531
-		if ($meetingWhen) {
532
-			$template->addBodyListItem($meetingWhen, $l10n->t('Time:'),
533
-				$this->getAbsoluteImagePath('caldav/time.svg'),'','',self::IMIP_INDENT);
534
-		}
535
-		if ($vevent->LOCATION) {
536
-			$template->addBodyListItem($vevent->LOCATION, $l10n->t('Location:'),
537
-				$this->getAbsoluteImagePath('caldav/location.svg'),'','',self::IMIP_INDENT);
538
-		}
539
-		if ($vevent->URL) {
540
-			$url = $vevent->URL->getValue();
541
-			$template->addBodyListItem(sprintf('<a href="%s">%s</a>',
542
-					htmlspecialchars($url),
543
-					htmlspecialchars($url)),
544
-				$l10n->t('Link:'),
545
-				$this->getAbsoluteImagePath('caldav/link.svg'),
546
-				$url,'',self::IMIP_INDENT);
547
-		}
548
-
549
-		$this->addAttendees($template, $l10n, $vevent);
550
-
551
-		/* Put description last, like an email body, since it can be arbitrarily long */
552
-		if ($vevent->DESCRIPTION) {
553
-			$template->addBodyListItem($vevent->DESCRIPTION->getValue(), $l10n->t('Description:'),
554
-				$this->getAbsoluteImagePath('caldav/description.svg'),'','',self::IMIP_INDENT);
555
-		}
556
-	}
557
-
558
-	/**
559
-	 * addAttendees: add organizer and attendee names/emails to iMip mail.
560
-	 *
561
-	 * Enable with DAV setting: invitation_list_attendees (default: no)
562
-	 *
563
-	 * The default is 'no', which matches old behavior, and is privacy preserving.
564
-	 *
565
-	 * To enable including attendees in invitation emails:
566
-	 *   % php occ config:app:set dav invitation_list_attendees --value yes
567
-	 *
568
-	 * @param IEMailTemplate $template
569
-	 * @param IL10N $l10n
570
-	 * @param Message $iTipMessage
571
-	 * @param int $lastOccurrence
572
-	 * @author brad2014 on github.com
573
-	 */
574
-
575
-	private function addAttendees(IEMailTemplate $template, IL10N $l10n, VEvent $vevent) {
576
-		if ($this->config->getAppValue('dav', 'invitation_list_attendees', 'no') === 'no') {
577
-			return;
578
-		}
579
-
580
-		if (isset($vevent->ORGANIZER)) {
581
-			/** @var Property\ICalendar\CalAddress $organizer */
582
-			$organizer = $vevent->ORGANIZER;
583
-			$organizerURI = $organizer->getNormalizedValue();
584
-			list($scheme,$organizerEmail) = explode(':',$organizerURI,2); # strip off scheme mailto:
585
-			/** @var string|null $organizerName */
586
-			$organizerName = isset($organizer['CN']) ? $organizer['CN'] : null;
587
-			$organizerHTML = sprintf('<a href="%s">%s</a>',
588
-				htmlspecialchars($organizerURI),
589
-				htmlspecialchars($organizerName ?: $organizerEmail));
590
-			$organizerText = sprintf('%s <%s>', $organizerName, $organizerEmail);
591
-			if (isset($organizer['PARTSTAT'])) {
592
-				/** @var Parameter $partstat */
593
-				$partstat = $organizer['PARTSTAT'];
594
-				if (strcasecmp($partstat->getValue(), 'ACCEPTED') === 0) {
595
-					$organizerHTML .= ' ✔︎';
596
-					$organizerText .= ' ✔︎';
597
-				}
598
-			}
599
-			$template->addBodyListItem($organizerHTML, $l10n->t('Organizer:'),
600
-				$this->getAbsoluteImagePath('caldav/organizer.svg'),
601
-				$organizerText,'',self::IMIP_INDENT);
602
-		}
603
-
604
-		$attendees = $vevent->select('ATTENDEE');
605
-		if (count($attendees) === 0) {
606
-			return;
607
-		}
608
-
609
-		$attendeesHTML = [];
610
-		$attendeesText = [];
611
-		foreach ($attendees as $attendee) {
612
-			$attendeeURI = $attendee->getNormalizedValue();
613
-			list($scheme,$attendeeEmail) = explode(':',$attendeeURI,2); # strip off scheme mailto:
614
-			$attendeeName = isset($attendee['CN']) ? $attendee['CN'] : null;
615
-			$attendeeHTML = sprintf('<a href="%s">%s</a>',
616
-				htmlspecialchars($attendeeURI),
617
-				htmlspecialchars($attendeeName ?: $attendeeEmail));
618
-			$attendeeText = sprintf('%s <%s>', $attendeeName, $attendeeEmail);
619
-			if (isset($attendee['PARTSTAT'])
620
-				&& strcasecmp($attendee['PARTSTAT'], 'ACCEPTED') === 0) {
621
-				$attendeeHTML .= ' ✔︎';
622
-				$attendeeText .= ' ✔︎';
623
-			}
624
-			array_push($attendeesHTML, $attendeeHTML);
625
-			array_push($attendeesText, $attendeeText);
626
-		}
627
-
628
-		$template->addBodyListItem(implode('<br/>',$attendeesHTML), $l10n->t('Attendees:'),
629
-			$this->getAbsoluteImagePath('caldav/attendees.svg'),
630
-			implode("\n",$attendeesText),'',self::IMIP_INDENT);
631
-	}
632
-
633
-	/**
634
-	 * @param IEMailTemplate $template
635
-	 * @param IL10N $l10n
636
-	 * @param Message $iTipMessage
637
-	 * @param int $lastOccurrence
638
-	 */
639
-	private function addResponseButtons(IEMailTemplate $template, IL10N $l10n,
640
-										Message $iTipMessage, $lastOccurrence) {
641
-		$token = $this->createInvitationToken($iTipMessage, $lastOccurrence);
642
-
643
-		$template->addBodyButtonGroup(
644
-			$l10n->t('Accept'),
645
-			$this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.accept', [
646
-				'token' => $token,
647
-			]),
648
-			$l10n->t('Decline'),
649
-			$this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.decline', [
650
-				'token' => $token,
651
-			])
652
-		);
653
-
654
-		$moreOptionsURL = $this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.options', [
655
-			'token' => $token,
656
-		]);
657
-		$html = vsprintf('<small><a href="%s">%s</a></small>', [
658
-			$moreOptionsURL, $l10n->t('More options …')
659
-		]);
660
-		$text = $l10n->t('More options at %s', [$moreOptionsURL]);
661
-
662
-		$template->addBodyText($html, $text);
663
-	}
664
-
665
-	/**
666
-	 * @param string $path
667
-	 * @return string
668
-	 */
669
-	private function getAbsoluteImagePath($path) {
670
-		return $this->urlGenerator->getAbsoluteURL(
671
-			$this->urlGenerator->imagePath('core', $path)
672
-		);
673
-	}
674
-
675
-	/**
676
-	 * @param Message $iTipMessage
677
-	 * @param int $lastOccurrence
678
-	 * @return string
679
-	 */
680
-	private function createInvitationToken(Message $iTipMessage, $lastOccurrence):string {
681
-		$token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
682
-
683
-		/** @var VEvent $vevent */
684
-		$vevent = $iTipMessage->message->VEVENT;
685
-		$attendee = $iTipMessage->recipient;
686
-		$organizer = $iTipMessage->sender;
687
-		$sequence = $iTipMessage->sequence;
688
-		$recurrenceId = isset($vevent->{'RECURRENCE-ID'}) ?
689
-			$vevent->{'RECURRENCE-ID'}->serialize() : null;
690
-		$uid = $vevent->{'UID'};
691
-
692
-		$query = $this->db->getQueryBuilder();
693
-		$query->insert('calendar_invitations')
694
-			->values([
695
-				'token' => $query->createNamedParameter($token),
696
-				'attendee' => $query->createNamedParameter($attendee),
697
-				'organizer' => $query->createNamedParameter($organizer),
698
-				'sequence' => $query->createNamedParameter($sequence),
699
-				'recurrenceid' => $query->createNamedParameter($recurrenceId),
700
-				'expiration' => $query->createNamedParameter($lastOccurrence),
701
-				'uid' => $query->createNamedParameter($uid)
702
-			])
703
-			->execute();
704
-
705
-		return $token;
706
-	}
270
+            $recipientDomain = substr(strrchr($recipient, "@"), 1);
271
+            $invitationLinkRecipients = explode(',', preg_replace('/\s+/', '', strtolower($this->config->getAppValue('dav', 'invitation_link_recipients', 'yes'))));
272
+
273
+            if (strcmp('yes', $invitationLinkRecipients[0]) === 0
274
+                 || in_array(strtolower($recipient), $invitationLinkRecipients)
275
+                 || in_array(strtolower($recipientDomain), $invitationLinkRecipients)) {
276
+                $this->addResponseButtons($template, $l10n, $iTipMessage, $lastOccurrence);
277
+            }
278
+        }
279
+
280
+        $template->addFooter();
281
+
282
+        $message->useTemplate($template);
283
+
284
+        $attachment = $this->mailer->createAttachment(
285
+            $iTipMessage->message->serialize(),
286
+            'event.ics',// TODO(leon): Make file name unique, e.g. add event id
287
+            'text/calendar; method=' . $iTipMessage->method
288
+        );
289
+        $message->attach($attachment);
290
+
291
+        try {
292
+            $failed = $this->mailer->send($message);
293
+            $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
294
+            if ($failed) {
295
+                $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' =>  implode(', ', $failed)]);
296
+                $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
297
+            }
298
+        } catch (\Exception $ex) {
299
+            $this->logger->logException($ex, ['app' => 'dav']);
300
+            $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
301
+        }
302
+    }
303
+
304
+    /**
305
+     * check if event took place in the past already
306
+     * @param VCalendar $vObject
307
+     * @return int
308
+     */
309
+    private function getLastOccurrence(VCalendar $vObject) {
310
+        /** @var VEvent $component */
311
+        $component = $vObject->VEVENT;
312
+
313
+        $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
314
+        // Finding the last occurrence is a bit harder
315
+        if (!isset($component->RRULE)) {
316
+            if (isset($component->DTEND)) {
317
+                $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
318
+            } elseif (isset($component->DURATION)) {
319
+                /** @var \DateTime $endDate */
320
+                $endDate = clone $component->DTSTART->getDateTime();
321
+                // $component->DTEND->getDateTime() returns DateTimeImmutable
322
+                $endDate = $endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
323
+                $lastOccurrence = $endDate->getTimestamp();
324
+            } elseif (!$component->DTSTART->hasTime()) {
325
+                /** @var \DateTime $endDate */
326
+                $endDate = clone $component->DTSTART->getDateTime();
327
+                // $component->DTSTART->getDateTime() returns DateTimeImmutable
328
+                $endDate = $endDate->modify('+1 day');
329
+                $lastOccurrence = $endDate->getTimestamp();
330
+            } else {
331
+                $lastOccurrence = $firstOccurrence;
332
+            }
333
+        } else {
334
+            $it = new EventIterator($vObject, (string)$component->UID);
335
+            $maxDate = new \DateTime(self::MAX_DATE);
336
+            if ($it->isInfinite()) {
337
+                $lastOccurrence = $maxDate->getTimestamp();
338
+            } else {
339
+                $end = $it->getDtEnd();
340
+                while ($it->valid() && $end < $maxDate) {
341
+                    $end = $it->getDtEnd();
342
+                    $it->next();
343
+                }
344
+                $lastOccurrence = $end->getTimestamp();
345
+            }
346
+        }
347
+
348
+        return $lastOccurrence;
349
+    }
350
+
351
+    /**
352
+     * @param Message $iTipMessage
353
+     * @return null|Property
354
+     */
355
+    private function getCurrentAttendee(Message $iTipMessage) {
356
+        /** @var VEvent $vevent */
357
+        $vevent = $iTipMessage->message->VEVENT;
358
+        $attendees = $vevent->select('ATTENDEE');
359
+        foreach ($attendees as $attendee) {
360
+            /** @var Property $attendee */
361
+            if (strcasecmp($attendee->getValue(), $iTipMessage->recipient) === 0) {
362
+                return $attendee;
363
+            }
364
+        }
365
+        return null;
366
+    }
367
+
368
+    /**
369
+     * @param string $default
370
+     * @param Property|null $attendee
371
+     * @return string
372
+     */
373
+    private function getAttendeeLangOrDefault($default, Property $attendee = null) {
374
+        if ($attendee !== null) {
375
+            $lang = $attendee->offsetGet('LANGUAGE');
376
+            if ($lang instanceof Parameter) {
377
+                return $lang->getValue();
378
+            }
379
+        }
380
+        return $default;
381
+    }
382
+
383
+    /**
384
+     * @param Property|null $attendee
385
+     * @return bool
386
+     */
387
+    private function getAttendeeRSVP(Property $attendee = null) {
388
+        if ($attendee !== null) {
389
+            $rsvp = $attendee->offsetGet('RSVP');
390
+            if (($rsvp instanceof Parameter) && (strcasecmp($rsvp->getValue(), 'TRUE') === 0)) {
391
+                return true;
392
+            }
393
+        }
394
+        // RFC 5545 3.2.17: default RSVP is false
395
+        return false;
396
+    }
397
+
398
+    /**
399
+     * @param IL10N $l10n
400
+     * @param VEvent $vevent
401
+     */
402
+    private function generateWhenString(IL10N $l10n, VEvent $vevent) {
403
+        $dtstart = $vevent->DTSTART;
404
+        if (isset($vevent->DTEND)) {
405
+            $dtend = $vevent->DTEND;
406
+        } elseif (isset($vevent->DURATION)) {
407
+            $isFloating = $vevent->DTSTART->isFloating();
408
+            $dtend = clone $vevent->DTSTART;
409
+            $endDateTime = $dtend->getDateTime();
410
+            $endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
411
+            $dtend->setDateTime($endDateTime, $isFloating);
412
+        } elseif (!$vevent->DTSTART->hasTime()) {
413
+            $isFloating = $vevent->DTSTART->isFloating();
414
+            $dtend = clone $vevent->DTSTART;
415
+            $endDateTime = $dtend->getDateTime();
416
+            $endDateTime = $endDateTime->modify('+1 day');
417
+            $dtend->setDateTime($endDateTime, $isFloating);
418
+        } else {
419
+            $dtend = clone $vevent->DTSTART;
420
+        }
421
+
422
+        $isAllDay = $dtstart instanceof Property\ICalendar\Date;
423
+
424
+        /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */
425
+        /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtend */
426
+        /** @var \DateTimeImmutable $dtstartDt */
427
+        $dtstartDt = $dtstart->getDateTime();
428
+        /** @var \DateTimeImmutable $dtendDt */
429
+        $dtendDt = $dtend->getDateTime();
430
+
431
+        $diff = $dtstartDt->diff($dtendDt);
432
+
433
+        $dtstartDt = new \DateTime($dtstartDt->format(\DateTime::ATOM));
434
+        $dtendDt = new \DateTime($dtendDt->format(\DateTime::ATOM));
435
+
436
+        if ($isAllDay) {
437
+            // One day event
438
+            if ($diff->days === 1) {
439
+                return $l10n->l('date', $dtstartDt, ['width' => 'medium']);
440
+            }
441
+
442
+            // DTEND is exclusive, so if the ics data says 2020-01-01 to 2020-01-05,
443
+            // the email should show 2020-01-01 to 2020-01-04.
444
+            $dtendDt->modify('-1 day');
445
+
446
+            //event that spans over multiple days
447
+            $localeStart = $l10n->l('date', $dtstartDt, ['width' => 'medium']);
448
+            $localeEnd = $l10n->l('date', $dtendDt, ['width' => 'medium']);
449
+
450
+            return $localeStart . ' - ' . $localeEnd;
451
+        }
452
+
453
+        /** @var Property\ICalendar\DateTime $dtstart */
454
+        /** @var Property\ICalendar\DateTime $dtend */
455
+        $isFloating = $dtstart->isFloating();
456
+        $startTimezone = $endTimezone = null;
457
+        if (!$isFloating) {
458
+            $prop = $dtstart->offsetGet('TZID');
459
+            if ($prop instanceof Parameter) {
460
+                $startTimezone = $prop->getValue();
461
+            }
462
+
463
+            $prop = $dtend->offsetGet('TZID');
464
+            if ($prop instanceof Parameter) {
465
+                $endTimezone = $prop->getValue();
466
+            }
467
+        }
468
+
469
+        $localeStart = $l10n->l('weekdayName', $dtstartDt, ['width' => 'abbreviated']) . ', ' .
470
+            $l10n->l('datetime', $dtstartDt, ['width' => 'medium|short']);
471
+
472
+        // always show full date with timezone if timezones are different
473
+        if ($startTimezone !== $endTimezone) {
474
+            $localeEnd = $l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
475
+
476
+            return $localeStart . ' (' . $startTimezone . ') - ' .
477
+                $localeEnd . ' (' . $endTimezone . ')';
478
+        }
479
+
480
+        // show only end time if date is the same
481
+        if ($this->isDayEqual($dtstartDt, $dtendDt)) {
482
+            $localeEnd = $l10n->l('time', $dtendDt, ['width' => 'short']);
483
+        } else {
484
+            $localeEnd = $l10n->l('weekdayName', $dtendDt, ['width' => 'abbreviated']) . ', ' .
485
+                $l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
486
+        }
487
+
488
+        return  $localeStart . ' - ' . $localeEnd . ' (' . $startTimezone . ')';
489
+    }
490
+
491
+    /**
492
+     * @param \DateTime $dtStart
493
+     * @param \DateTime $dtEnd
494
+     * @return bool
495
+     */
496
+    private function isDayEqual(\DateTime $dtStart, \DateTime $dtEnd) {
497
+        return $dtStart->format('Y-m-d') === $dtEnd->format('Y-m-d');
498
+    }
499
+
500
+    /**
501
+     * @param IEMailTemplate $template
502
+     * @param IL10N $l10n
503
+     * @param string $method
504
+     * @param string $summary
505
+     */
506
+    private function addSubjectAndHeading(IEMailTemplate $template, IL10N $l10n,
507
+                                            $method, $summary) {
508
+        if ($method === self::METHOD_CANCEL) {
509
+            $template->setSubject('Canceled: ' . $summary);
510
+            $template->addHeading($l10n->t('Invitation canceled'));
511
+        } elseif ($method === self::METHOD_REPLY) {
512
+            $template->setSubject('Re: ' . $summary);
513
+            $template->addHeading($l10n->t('Invitation updated'));
514
+        } else {
515
+            $template->setSubject('Invitation: ' . $summary);
516
+            $template->addHeading($l10n->t('Invitation'));
517
+        }
518
+    }
519
+
520
+    /**
521
+     * @param IEMailTemplate $template
522
+     * @param IL10N $l10n
523
+     * @param VEVENT $vevent
524
+     */
525
+    private function addBulletList(IEMailTemplate $template, IL10N $l10n, $vevent) {
526
+        if ($vevent->SUMMARY) {
527
+            $template->addBodyListItem($vevent->SUMMARY, $l10n->t('Title:'),
528
+                $this->getAbsoluteImagePath('caldav/title.svg'),'','',self::IMIP_INDENT);
529
+        }
530
+        $meetingWhen = $this->generateWhenString($l10n, $vevent);
531
+        if ($meetingWhen) {
532
+            $template->addBodyListItem($meetingWhen, $l10n->t('Time:'),
533
+                $this->getAbsoluteImagePath('caldav/time.svg'),'','',self::IMIP_INDENT);
534
+        }
535
+        if ($vevent->LOCATION) {
536
+            $template->addBodyListItem($vevent->LOCATION, $l10n->t('Location:'),
537
+                $this->getAbsoluteImagePath('caldav/location.svg'),'','',self::IMIP_INDENT);
538
+        }
539
+        if ($vevent->URL) {
540
+            $url = $vevent->URL->getValue();
541
+            $template->addBodyListItem(sprintf('<a href="%s">%s</a>',
542
+                    htmlspecialchars($url),
543
+                    htmlspecialchars($url)),
544
+                $l10n->t('Link:'),
545
+                $this->getAbsoluteImagePath('caldav/link.svg'),
546
+                $url,'',self::IMIP_INDENT);
547
+        }
548
+
549
+        $this->addAttendees($template, $l10n, $vevent);
550
+
551
+        /* Put description last, like an email body, since it can be arbitrarily long */
552
+        if ($vevent->DESCRIPTION) {
553
+            $template->addBodyListItem($vevent->DESCRIPTION->getValue(), $l10n->t('Description:'),
554
+                $this->getAbsoluteImagePath('caldav/description.svg'),'','',self::IMIP_INDENT);
555
+        }
556
+    }
557
+
558
+    /**
559
+     * addAttendees: add organizer and attendee names/emails to iMip mail.
560
+     *
561
+     * Enable with DAV setting: invitation_list_attendees (default: no)
562
+     *
563
+     * The default is 'no', which matches old behavior, and is privacy preserving.
564
+     *
565
+     * To enable including attendees in invitation emails:
566
+     *   % php occ config:app:set dav invitation_list_attendees --value yes
567
+     *
568
+     * @param IEMailTemplate $template
569
+     * @param IL10N $l10n
570
+     * @param Message $iTipMessage
571
+     * @param int $lastOccurrence
572
+     * @author brad2014 on github.com
573
+     */
574
+
575
+    private function addAttendees(IEMailTemplate $template, IL10N $l10n, VEvent $vevent) {
576
+        if ($this->config->getAppValue('dav', 'invitation_list_attendees', 'no') === 'no') {
577
+            return;
578
+        }
579
+
580
+        if (isset($vevent->ORGANIZER)) {
581
+            /** @var Property\ICalendar\CalAddress $organizer */
582
+            $organizer = $vevent->ORGANIZER;
583
+            $organizerURI = $organizer->getNormalizedValue();
584
+            list($scheme,$organizerEmail) = explode(':',$organizerURI,2); # strip off scheme mailto:
585
+            /** @var string|null $organizerName */
586
+            $organizerName = isset($organizer['CN']) ? $organizer['CN'] : null;
587
+            $organizerHTML = sprintf('<a href="%s">%s</a>',
588
+                htmlspecialchars($organizerURI),
589
+                htmlspecialchars($organizerName ?: $organizerEmail));
590
+            $organizerText = sprintf('%s <%s>', $organizerName, $organizerEmail);
591
+            if (isset($organizer['PARTSTAT'])) {
592
+                /** @var Parameter $partstat */
593
+                $partstat = $organizer['PARTSTAT'];
594
+                if (strcasecmp($partstat->getValue(), 'ACCEPTED') === 0) {
595
+                    $organizerHTML .= ' ✔︎';
596
+                    $organizerText .= ' ✔︎';
597
+                }
598
+            }
599
+            $template->addBodyListItem($organizerHTML, $l10n->t('Organizer:'),
600
+                $this->getAbsoluteImagePath('caldav/organizer.svg'),
601
+                $organizerText,'',self::IMIP_INDENT);
602
+        }
603
+
604
+        $attendees = $vevent->select('ATTENDEE');
605
+        if (count($attendees) === 0) {
606
+            return;
607
+        }
608
+
609
+        $attendeesHTML = [];
610
+        $attendeesText = [];
611
+        foreach ($attendees as $attendee) {
612
+            $attendeeURI = $attendee->getNormalizedValue();
613
+            list($scheme,$attendeeEmail) = explode(':',$attendeeURI,2); # strip off scheme mailto:
614
+            $attendeeName = isset($attendee['CN']) ? $attendee['CN'] : null;
615
+            $attendeeHTML = sprintf('<a href="%s">%s</a>',
616
+                htmlspecialchars($attendeeURI),
617
+                htmlspecialchars($attendeeName ?: $attendeeEmail));
618
+            $attendeeText = sprintf('%s <%s>', $attendeeName, $attendeeEmail);
619
+            if (isset($attendee['PARTSTAT'])
620
+                && strcasecmp($attendee['PARTSTAT'], 'ACCEPTED') === 0) {
621
+                $attendeeHTML .= ' ✔︎';
622
+                $attendeeText .= ' ✔︎';
623
+            }
624
+            array_push($attendeesHTML, $attendeeHTML);
625
+            array_push($attendeesText, $attendeeText);
626
+        }
627
+
628
+        $template->addBodyListItem(implode('<br/>',$attendeesHTML), $l10n->t('Attendees:'),
629
+            $this->getAbsoluteImagePath('caldav/attendees.svg'),
630
+            implode("\n",$attendeesText),'',self::IMIP_INDENT);
631
+    }
632
+
633
+    /**
634
+     * @param IEMailTemplate $template
635
+     * @param IL10N $l10n
636
+     * @param Message $iTipMessage
637
+     * @param int $lastOccurrence
638
+     */
639
+    private function addResponseButtons(IEMailTemplate $template, IL10N $l10n,
640
+                                        Message $iTipMessage, $lastOccurrence) {
641
+        $token = $this->createInvitationToken($iTipMessage, $lastOccurrence);
642
+
643
+        $template->addBodyButtonGroup(
644
+            $l10n->t('Accept'),
645
+            $this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.accept', [
646
+                'token' => $token,
647
+            ]),
648
+            $l10n->t('Decline'),
649
+            $this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.decline', [
650
+                'token' => $token,
651
+            ])
652
+        );
653
+
654
+        $moreOptionsURL = $this->urlGenerator->linkToRouteAbsolute('dav.invitation_response.options', [
655
+            'token' => $token,
656
+        ]);
657
+        $html = vsprintf('<small><a href="%s">%s</a></small>', [
658
+            $moreOptionsURL, $l10n->t('More options …')
659
+        ]);
660
+        $text = $l10n->t('More options at %s', [$moreOptionsURL]);
661
+
662
+        $template->addBodyText($html, $text);
663
+    }
664
+
665
+    /**
666
+     * @param string $path
667
+     * @return string
668
+     */
669
+    private function getAbsoluteImagePath($path) {
670
+        return $this->urlGenerator->getAbsoluteURL(
671
+            $this->urlGenerator->imagePath('core', $path)
672
+        );
673
+    }
674
+
675
+    /**
676
+     * @param Message $iTipMessage
677
+     * @param int $lastOccurrence
678
+     * @return string
679
+     */
680
+    private function createInvitationToken(Message $iTipMessage, $lastOccurrence):string {
681
+        $token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
682
+
683
+        /** @var VEvent $vevent */
684
+        $vevent = $iTipMessage->message->VEVENT;
685
+        $attendee = $iTipMessage->recipient;
686
+        $organizer = $iTipMessage->sender;
687
+        $sequence = $iTipMessage->sequence;
688
+        $recurrenceId = isset($vevent->{'RECURRENCE-ID'}) ?
689
+            $vevent->{'RECURRENCE-ID'}->serialize() : null;
690
+        $uid = $vevent->{'UID'};
691
+
692
+        $query = $this->db->getQueryBuilder();
693
+        $query->insert('calendar_invitations')
694
+            ->values([
695
+                'token' => $query->createNamedParameter($token),
696
+                'attendee' => $query->createNamedParameter($attendee),
697
+                'organizer' => $query->createNamedParameter($organizer),
698
+                'sequence' => $query->createNamedParameter($sequence),
699
+                'recurrenceid' => $query->createNamedParameter($recurrenceId),
700
+                'expiration' => $query->createNamedParameter($lastOccurrence),
701
+                'uid' => $query->createNamedParameter($uid)
702
+            ])
703
+            ->execute();
704
+
705
+        return $token;
706
+    }
707 707
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
 		}
222 222
 
223 223
 		$data = [
224
-			'attendee_name' => (string)$meetingAttendeeName ?: $defaultVal,
225
-			'invitee_name' => (string)$meetingInviteeName ?: $defaultVal,
226
-			'meeting_title' => (string)$meetingTitle ?: $defaultVal,
227
-			'meeting_description' => (string)$meetingDescription ?: $defaultVal,
228
-			'meeting_url' => (string)$meetingUrl ?: $defaultVal,
224
+			'attendee_name' => (string) $meetingAttendeeName ?: $defaultVal,
225
+			'invitee_name' => (string) $meetingInviteeName ?: $defaultVal,
226
+			'meeting_title' => (string) $meetingTitle ?: $defaultVal,
227
+			'meeting_description' => (string) $meetingDescription ?: $defaultVal,
228
+			'meeting_url' => (string) $meetingUrl ?: $defaultVal,
229 229
 		];
230 230
 
231 231
 		$fromEMail = Util::getDefaultEmailAddress('invitations-noreply');
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 			->setReplyTo([$sender => $senderName])
237 237
 			->setTo([$recipient => $recipientName]);
238 238
 
239
-		$template = $this->mailer->createEMailTemplate('dav.calendarInvite.' . $method, $data);
239
+		$template = $this->mailer->createEMailTemplate('dav.calendarInvite.'.$method, $data);
240 240
 		$template->addHeader();
241 241
 
242 242
 		$summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Untitled event');
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
 
284 284
 		$attachment = $this->mailer->createAttachment(
285 285
 			$iTipMessage->message->serialize(),
286
-			'event.ics',// TODO(leon): Make file name unique, e.g. add event id
287
-			'text/calendar; method=' . $iTipMessage->method
286
+			'event.ics', // TODO(leon): Make file name unique, e.g. add event id
287
+			'text/calendar; method='.$iTipMessage->method
288 288
 		);
289 289
 		$message->attach($attachment);
290 290
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 				$lastOccurrence = $firstOccurrence;
332 332
 			}
333 333
 		} else {
334
-			$it = new EventIterator($vObject, (string)$component->UID);
334
+			$it = new EventIterator($vObject, (string) $component->UID);
335 335
 			$maxDate = new \DateTime(self::MAX_DATE);
336 336
 			if ($it->isInfinite()) {
337 337
 				$lastOccurrence = $maxDate->getTimestamp();
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 			$localeStart = $l10n->l('date', $dtstartDt, ['width' => 'medium']);
448 448
 			$localeEnd = $l10n->l('date', $dtendDt, ['width' => 'medium']);
449 449
 
450
-			return $localeStart . ' - ' . $localeEnd;
450
+			return $localeStart.' - '.$localeEnd;
451 451
 		}
452 452
 
453 453
 		/** @var Property\ICalendar\DateTime $dtstart */
@@ -466,26 +466,26 @@  discard block
 block discarded – undo
466 466
 			}
467 467
 		}
468 468
 
469
-		$localeStart = $l10n->l('weekdayName', $dtstartDt, ['width' => 'abbreviated']) . ', ' .
469
+		$localeStart = $l10n->l('weekdayName', $dtstartDt, ['width' => 'abbreviated']).', '.
470 470
 			$l10n->l('datetime', $dtstartDt, ['width' => 'medium|short']);
471 471
 
472 472
 		// always show full date with timezone if timezones are different
473 473
 		if ($startTimezone !== $endTimezone) {
474 474
 			$localeEnd = $l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
475 475
 
476
-			return $localeStart . ' (' . $startTimezone . ') - ' .
477
-				$localeEnd . ' (' . $endTimezone . ')';
476
+			return $localeStart.' ('.$startTimezone.') - '.
477
+				$localeEnd.' ('.$endTimezone.')';
478 478
 		}
479 479
 
480 480
 		// show only end time if date is the same
481 481
 		if ($this->isDayEqual($dtstartDt, $dtendDt)) {
482 482
 			$localeEnd = $l10n->l('time', $dtendDt, ['width' => 'short']);
483 483
 		} else {
484
-			$localeEnd = $l10n->l('weekdayName', $dtendDt, ['width' => 'abbreviated']) . ', ' .
484
+			$localeEnd = $l10n->l('weekdayName', $dtendDt, ['width' => 'abbreviated']).', '.
485 485
 				$l10n->l('datetime', $dtendDt, ['width' => 'medium|short']);
486 486
 		}
487 487
 
488
-		return  $localeStart . ' - ' . $localeEnd . ' (' . $startTimezone . ')';
488
+		return  $localeStart.' - '.$localeEnd.' ('.$startTimezone.')';
489 489
 	}
490 490
 
491 491
 	/**
@@ -506,13 +506,13 @@  discard block
 block discarded – undo
506 506
 	private function addSubjectAndHeading(IEMailTemplate $template, IL10N $l10n,
507 507
 										  $method, $summary) {
508 508
 		if ($method === self::METHOD_CANCEL) {
509
-			$template->setSubject('Canceled: ' . $summary);
509
+			$template->setSubject('Canceled: '.$summary);
510 510
 			$template->addHeading($l10n->t('Invitation canceled'));
511 511
 		} elseif ($method === self::METHOD_REPLY) {
512
-			$template->setSubject('Re: ' . $summary);
512
+			$template->setSubject('Re: '.$summary);
513 513
 			$template->addHeading($l10n->t('Invitation updated'));
514 514
 		} else {
515
-			$template->setSubject('Invitation: ' . $summary);
515
+			$template->setSubject('Invitation: '.$summary);
516 516
 			$template->addHeading($l10n->t('Invitation'));
517 517
 		}
518 518
 	}
@@ -525,16 +525,16 @@  discard block
 block discarded – undo
525 525
 	private function addBulletList(IEMailTemplate $template, IL10N $l10n, $vevent) {
526 526
 		if ($vevent->SUMMARY) {
527 527
 			$template->addBodyListItem($vevent->SUMMARY, $l10n->t('Title:'),
528
-				$this->getAbsoluteImagePath('caldav/title.svg'),'','',self::IMIP_INDENT);
528
+				$this->getAbsoluteImagePath('caldav/title.svg'), '', '', self::IMIP_INDENT);
529 529
 		}
530 530
 		$meetingWhen = $this->generateWhenString($l10n, $vevent);
531 531
 		if ($meetingWhen) {
532 532
 			$template->addBodyListItem($meetingWhen, $l10n->t('Time:'),
533
-				$this->getAbsoluteImagePath('caldav/time.svg'),'','',self::IMIP_INDENT);
533
+				$this->getAbsoluteImagePath('caldav/time.svg'), '', '', self::IMIP_INDENT);
534 534
 		}
535 535
 		if ($vevent->LOCATION) {
536 536
 			$template->addBodyListItem($vevent->LOCATION, $l10n->t('Location:'),
537
-				$this->getAbsoluteImagePath('caldav/location.svg'),'','',self::IMIP_INDENT);
537
+				$this->getAbsoluteImagePath('caldav/location.svg'), '', '', self::IMIP_INDENT);
538 538
 		}
539 539
 		if ($vevent->URL) {
540 540
 			$url = $vevent->URL->getValue();
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
 					htmlspecialchars($url)),
544 544
 				$l10n->t('Link:'),
545 545
 				$this->getAbsoluteImagePath('caldav/link.svg'),
546
-				$url,'',self::IMIP_INDENT);
546
+				$url, '', self::IMIP_INDENT);
547 547
 		}
548 548
 
549 549
 		$this->addAttendees($template, $l10n, $vevent);
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
 		/* Put description last, like an email body, since it can be arbitrarily long */
552 552
 		if ($vevent->DESCRIPTION) {
553 553
 			$template->addBodyListItem($vevent->DESCRIPTION->getValue(), $l10n->t('Description:'),
554
-				$this->getAbsoluteImagePath('caldav/description.svg'),'','',self::IMIP_INDENT);
554
+				$this->getAbsoluteImagePath('caldav/description.svg'), '', '', self::IMIP_INDENT);
555 555
 		}
556 556
 	}
557 557
 
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 			/** @var Property\ICalendar\CalAddress $organizer */
582 582
 			$organizer = $vevent->ORGANIZER;
583 583
 			$organizerURI = $organizer->getNormalizedValue();
584
-			list($scheme,$organizerEmail) = explode(':',$organizerURI,2); # strip off scheme mailto:
584
+			list($scheme, $organizerEmail) = explode(':', $organizerURI, 2); # strip off scheme mailto:
585 585
 			/** @var string|null $organizerName */
586 586
 			$organizerName = isset($organizer['CN']) ? $organizer['CN'] : null;
587 587
 			$organizerHTML = sprintf('<a href="%s">%s</a>',
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 			}
599 599
 			$template->addBodyListItem($organizerHTML, $l10n->t('Organizer:'),
600 600
 				$this->getAbsoluteImagePath('caldav/organizer.svg'),
601
-				$organizerText,'',self::IMIP_INDENT);
601
+				$organizerText, '', self::IMIP_INDENT);
602 602
 		}
603 603
 
604 604
 		$attendees = $vevent->select('ATTENDEE');
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 		$attendeesText = [];
611 611
 		foreach ($attendees as $attendee) {
612 612
 			$attendeeURI = $attendee->getNormalizedValue();
613
-			list($scheme,$attendeeEmail) = explode(':',$attendeeURI,2); # strip off scheme mailto:
613
+			list($scheme, $attendeeEmail) = explode(':', $attendeeURI, 2); # strip off scheme mailto:
614 614
 			$attendeeName = isset($attendee['CN']) ? $attendee['CN'] : null;
615 615
 			$attendeeHTML = sprintf('<a href="%s">%s</a>',
616 616
 				htmlspecialchars($attendeeURI),
@@ -625,9 +625,9 @@  discard block
 block discarded – undo
625 625
 			array_push($attendeesText, $attendeeText);
626 626
 		}
627 627
 
628
-		$template->addBodyListItem(implode('<br/>',$attendeesHTML), $l10n->t('Attendees:'),
628
+		$template->addBodyListItem(implode('<br/>', $attendeesHTML), $l10n->t('Attendees:'),
629 629
 			$this->getAbsoluteImagePath('caldav/attendees.svg'),
630
-			implode("\n",$attendeesText),'',self::IMIP_INDENT);
630
+			implode("\n", $attendeesText), '', self::IMIP_INDENT);
631 631
 	}
632 632
 
633 633
 	/**
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
 	 * @return string
679 679
 	 */
680 680
 	private function createInvitationToken(Message $iTipMessage, $lastOccurrence):string {
681
-		$token = $this->random->generate(60, ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS);
681
+		$token = $this->random->generate(60, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
682 682
 
683 683
 		/** @var VEvent $vevent */
684 684
 		$vevent = $iTipMessage->message->VEVENT;
Please login to merge, or discard this patch.