Skip to content

Commit 6a44945

Browse files
brad2014Brad Rubenstein
authored andcommitted
Minor cleanup: bugs found by Psalm static checker
IEMailTemplate: The public interface to addBodyListItem also needs to include the new plainIndent parameter. IMipPlugin: Fixes an undefined variable for events that do not have DTEND. Also use explicit string conversion for parameters and properties in several places. Signed-off-by: Brad Rubenstein <[email protected]>
1 parent dfd02b2 commit 6a44945

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

apps/dav/lib/CalDAV/Schedule/IMipPlugin.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* @copyright Copyright (c) 2016, ownCloud, Inc.
44
* @copyright Copyright (c) 2017, Georg Ehrke
55
*
6-
* @author brad2014 <[email protected]>
76
* @author Brad Rubenstein <[email protected]>
87
* @author Christoph Wurst <[email protected]>
98
* @author Georg Ehrke <[email protected]>
@@ -242,8 +241,7 @@ public function schedule(Message $iTipMessage) {
242241

243242
$summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Untitled event');
244243

245-
$this->addSubjectAndHeading($template, $l10n, $method, $summary,
246-
$meetingAttendeeName, $meetingInviteeName);
244+
$this->addSubjectAndHeading($template, $l10n, $method, $summary);
247245
$this->addBulletList($template, $l10n, $vevent);
248246

249247

@@ -408,13 +406,13 @@ private function generateWhenString(IL10N $l10n, VEvent $vevent) {
408406
} elseif (isset($vevent->DURATION)) {
409407
$isFloating = $vevent->DTSTART->isFloating();
410408
$dtend = clone $vevent->DTSTART;
411-
$endDateTime = $end->getDateTime();
409+
$endDateTime = $dtend->getDateTime();
412410
$endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue()));
413411
$dtend->setDateTime($endDateTime, $isFloating);
414412
} elseif (!$vevent->DTSTART->hasTime()) {
415413
$isFloating = $vevent->DTSTART->isFloating();
416414
$dtend = clone $vevent->DTSTART;
417-
$endDateTime = $end->getDateTime();
415+
$endDateTime = $dtend->getDateTime();
418416
$endDateTime = $endDateTime->modify('+1 day');
419417
$dtend->setDateTime($endDateTime, $isFloating);
420418
} else {
@@ -539,19 +537,20 @@ private function addBulletList(IEMailTemplate $template, IL10N $l10n, $vevent) {
539537
$this->getAbsoluteImagePath('caldav/location.svg'),'','',self::IMIP_INDENT);
540538
}
541539
if ($vevent->URL) {
540+
$url = $vevent->URL->getValue();
542541
$template->addBodyListItem(sprintf('<a href="%s">%s</a>',
543-
htmlspecialchars($vevent->URL),
544-
htmlspecialchars($vevent->URL)),
542+
htmlspecialchars($url),
543+
htmlspecialchars($url)),
545544
$l10n->t('Link:'),
546545
$this->getAbsoluteImagePath('caldav/link.svg'),
547-
$vevent->URL,'',self::IMIP_INDENT);
546+
$url,'',self::IMIP_INDENT);
548547
}
549548

550549
$this->addAttendees($template, $l10n, $vevent);
551550

552551
/* Put description last, like an email body, since it can be arbitrarily long */
553552
if ($vevent->DESCRIPTION) {
554-
$template->addBodyListItem($vevent->DESCRIPTION, $l10n->t('Description:'),
553+
$template->addBodyListItem($vevent->DESCRIPTION->getValue(), $l10n->t('Description:'),
555554
$this->getAbsoluteImagePath('caldav/description.svg'),'','',self::IMIP_INDENT);
556555
}
557556
}
@@ -579,18 +578,23 @@ private function addAttendees(IEMailTemplate $template, IL10N $l10n, VEvent $vev
579578
}
580579

581580
if (isset($vevent->ORGANIZER)) {
581+
/** @var Property\ICalendar\CalAddress $organizer */
582582
$organizer = $vevent->ORGANIZER;
583583
$organizerURI = $organizer->getNormalizedValue();
584584
list($scheme,$organizerEmail) = explode(':',$organizerURI,2); # strip off scheme mailto:
585+
/** @var string|null $organizerName */
585586
$organizerName = isset($organizer['CN']) ? $organizer['CN'] : null;
586587
$organizerHTML = sprintf('<a href="%s">%s</a>',
587588
htmlspecialchars($organizerURI),
588589
htmlspecialchars($organizerName ?: $organizerEmail));
589590
$organizerText = sprintf('%s <%s>', $organizerName, $organizerEmail);
590-
if (isset($organizer['PARTSTAT'])
591-
&& strcasecmp($organizer['PARTSTAT'], 'ACCEPTED') === 0) {
592-
$organizerHTML .= ' ✔︎';
593-
$organizerText .= ' ✔︎';
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+
}
594598
}
595599
$template->addBodyListItem($organizerHTML, $l10n->t('Organizer:'),
596600
$this->getAbsoluteImagePath('caldav/organizer.svg'),

lib/private/Mail/EMailTemplate.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,21 +447,21 @@ public function addBodyText(string $text, $plainText = '') {
447447
* @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email
448448
* @param string $icon Absolute path, must be 16*16 pixels
449449
* @param string|bool $plainText Text that is used in the plain text email
450-
* if empty the $text is used, if false none will be used
450+
* if empty or true the $text is used, if false none will be used
451451
* @param string|bool $plainMetaInfo Meta info that is used in the plain text email
452-
* if empty the $metaInfo is used, if false none will be used
452+
* if empty or true the $metaInfo is used, if false none will be used
453453
* @param integer plainIndent If > 0, Indent plainText by this amount.
454454
* @since 12.0.0
455455
*/
456456
public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0) {
457457
$this->ensureBodyListOpened();
458458

459-
if ($plainText === '') {
459+
if ($plainText === '' || $plainText === true) {
460460
$plainText = $text;
461461
$text = htmlspecialchars($text);
462462
$text = str_replace("\n", "<br/>", $text); // convert newlines to HTML breaks
463463
}
464-
if ($plainMetaInfo === '') {
464+
if ($plainMetaInfo === '' || $plainMetaInfo === true) {
465465
$plainMetaInfo = $metaInfo;
466466
$metaInfo = htmlspecialchars($metaInfo);
467467
}
@@ -494,8 +494,10 @@ public function addBodyListItem(string $text, string $metaInfo = '', string $ico
494494
* "plainIndent". Multilines after the first are indented plainIndent+1
495495
* (to account for space after label). Fixes: #12391
496496
*/
497+
/** @var string $label */
498+
$label = ( $plainMetaInfo !== false )? $plainMetaInfo : '';
497499
$this->plainBody .= sprintf("%${plainIndent}s %s\n",
498-
$plainMetaInfo,
500+
$label,
499501
str_replace("\n", "\n" . str_repeat(' ', $plainIndent+1), $plainText));
500502
}
501503
}

lib/public/Mail/IEMailTemplate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ public function addBodyText(string $text, $plainText = '');
106106
* if empty the $text is used, if false none will be used
107107
* @param string|bool $plainMetaInfo Meta info that is used in the plain text email
108108
* if empty the $metaInfo is used, if false none will be used
109+
* @param integer plainIndent If > 0, Indent plainText by this amount.
109110
* @since 12.0.0
110111
*/
111-
public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '');
112+
public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0);
112113

113114
/**
114115
* Adds a button group of two buttons to the body of the email

0 commit comments

Comments
 (0)