From 6a449458bc1867ece71d8072ff3b07ca1b0b88fb Mon Sep 17 00:00:00 2001 From: brad2014 Date: Fri, 21 Aug 2020 00:12:01 +0200 Subject: [PATCH] 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 --- apps/dav/lib/CalDAV/Schedule/IMipPlugin.php | 30 ++++++++++++--------- lib/private/Mail/EMailTemplate.php | 12 +++++---- lib/public/Mail/IEMailTemplate.php | 3 ++- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php index c73a77630004c..56517ab28c127 100644 --- a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php +++ b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php @@ -3,7 +3,6 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2017, Georg Ehrke * - * @author brad2014 * @author Brad Rubenstein * @author Christoph Wurst * @author Georg Ehrke @@ -242,8 +241,7 @@ public function schedule(Message $iTipMessage) { $summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Untitled event'); - $this->addSubjectAndHeading($template, $l10n, $method, $summary, - $meetingAttendeeName, $meetingInviteeName); + $this->addSubjectAndHeading($template, $l10n, $method, $summary); $this->addBulletList($template, $l10n, $vevent); @@ -408,13 +406,13 @@ private function generateWhenString(IL10N $l10n, VEvent $vevent) { } elseif (isset($vevent->DURATION)) { $isFloating = $vevent->DTSTART->isFloating(); $dtend = clone $vevent->DTSTART; - $endDateTime = $end->getDateTime(); + $endDateTime = $dtend->getDateTime(); $endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue())); $dtend->setDateTime($endDateTime, $isFloating); } elseif (!$vevent->DTSTART->hasTime()) { $isFloating = $vevent->DTSTART->isFloating(); $dtend = clone $vevent->DTSTART; - $endDateTime = $end->getDateTime(); + $endDateTime = $dtend->getDateTime(); $endDateTime = $endDateTime->modify('+1 day'); $dtend->setDateTime($endDateTime, $isFloating); } else { @@ -539,19 +537,20 @@ private function addBulletList(IEMailTemplate $template, IL10N $l10n, $vevent) { $this->getAbsoluteImagePath('caldav/location.svg'),'','',self::IMIP_INDENT); } if ($vevent->URL) { + $url = $vevent->URL->getValue(); $template->addBodyListItem(sprintf('%s', - htmlspecialchars($vevent->URL), - htmlspecialchars($vevent->URL)), + htmlspecialchars($url), + htmlspecialchars($url)), $l10n->t('Link:'), $this->getAbsoluteImagePath('caldav/link.svg'), - $vevent->URL,'',self::IMIP_INDENT); + $url,'',self::IMIP_INDENT); } $this->addAttendees($template, $l10n, $vevent); /* Put description last, like an email body, since it can be arbitrarily long */ if ($vevent->DESCRIPTION) { - $template->addBodyListItem($vevent->DESCRIPTION, $l10n->t('Description:'), + $template->addBodyListItem($vevent->DESCRIPTION->getValue(), $l10n->t('Description:'), $this->getAbsoluteImagePath('caldav/description.svg'),'','',self::IMIP_INDENT); } } @@ -579,18 +578,23 @@ private function addAttendees(IEMailTemplate $template, IL10N $l10n, VEvent $vev } if (isset($vevent->ORGANIZER)) { + /** @var Property\ICalendar\CalAddress $organizer */ $organizer = $vevent->ORGANIZER; $organizerURI = $organizer->getNormalizedValue(); list($scheme,$organizerEmail) = explode(':',$organizerURI,2); # strip off scheme mailto: + /** @var string|null $organizerName */ $organizerName = isset($organizer['CN']) ? $organizer['CN'] : null; $organizerHTML = sprintf('%s', htmlspecialchars($organizerURI), htmlspecialchars($organizerName ?: $organizerEmail)); $organizerText = sprintf('%s <%s>', $organizerName, $organizerEmail); - if (isset($organizer['PARTSTAT']) - && strcasecmp($organizer['PARTSTAT'], 'ACCEPTED') === 0) { - $organizerHTML .= ' ✔︎'; - $organizerText .= ' ✔︎'; + if (isset($organizer['PARTSTAT'])) { + /** @var Parameter $partstat */ + $partstat = $organizer['PARTSTAT']; + if (strcasecmp($partstat->getValue(), 'ACCEPTED') === 0) { + $organizerHTML .= ' ✔︎'; + $organizerText .= ' ✔︎'; + } } $template->addBodyListItem($organizerHTML, $l10n->t('Organizer:'), $this->getAbsoluteImagePath('caldav/organizer.svg'), diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 054378c2afa01..a3c339df6650f 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -447,21 +447,21 @@ public function addBodyText(string $text, $plainText = '') { * @param string $metaInfo Note: When $plainMetaInfo falls back to this, HTML is automatically escaped in the HTML email * @param string $icon Absolute path, must be 16*16 pixels * @param string|bool $plainText Text that is used in the plain text email - * if empty the $text is used, if false none will be used + * if empty or true the $text is used, if false none will be used * @param string|bool $plainMetaInfo Meta info that is used in the plain text email - * if empty the $metaInfo is used, if false none will be used + * if empty or true the $metaInfo is used, if false none will be used * @param integer plainIndent If > 0, Indent plainText by this amount. * @since 12.0.0 */ public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0) { $this->ensureBodyListOpened(); - if ($plainText === '') { + if ($plainText === '' || $plainText === true) { $plainText = $text; $text = htmlspecialchars($text); $text = str_replace("\n", "
", $text); // convert newlines to HTML breaks } - if ($plainMetaInfo === '') { + if ($plainMetaInfo === '' || $plainMetaInfo === true) { $plainMetaInfo = $metaInfo; $metaInfo = htmlspecialchars($metaInfo); } @@ -494,8 +494,10 @@ public function addBodyListItem(string $text, string $metaInfo = '', string $ico * "plainIndent". Multilines after the first are indented plainIndent+1 * (to account for space after label). Fixes: #12391 */ + /** @var string $label */ + $label = ( $plainMetaInfo !== false )? $plainMetaInfo : ''; $this->plainBody .= sprintf("%${plainIndent}s %s\n", - $plainMetaInfo, + $label, str_replace("\n", "\n" . str_repeat(' ', $plainIndent+1), $plainText)); } } diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index 70046d5c508f3..a09132660f8ef 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -106,9 +106,10 @@ public function addBodyText(string $text, $plainText = ''); * if empty the $text is used, if false none will be used * @param string|bool $plainMetaInfo Meta info that is used in the plain text email * if empty the $metaInfo is used, if false none will be used + * @param integer plainIndent If > 0, Indent plainText by this amount. * @since 12.0.0 */ - public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = ''); + public function addBodyListItem(string $text, string $metaInfo = '', string $icon = '', $plainText = '', $plainMetaInfo = '', $plainIndent = 0); /** * Adds a button group of two buttons to the body of the email