Skip to content

Commit

Permalink
Minor cleanup: bugs found by Psalm static checker
Browse files Browse the repository at this point in the history
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 <brad@wbr.tech>
  • Loading branch information
brad2014 authored and Brad Rubenstein committed Aug 21, 2020
1 parent dfd02b2 commit 6a44945
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
30 changes: 17 additions & 13 deletions apps/dav/lib/CalDAV/Schedule/IMipPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2017, Georg Ehrke
*
* @author brad2014 <brad2014@users.noreply.github.com>
* @author Brad Rubenstein <brad@wbr.tech>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Georg Ehrke <oc.list@georgehrke.com>
Expand Down Expand Up @@ -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);


Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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('<a href="%s">%s</a>',
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);
}
}
Expand Down Expand Up @@ -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('<a href="%s">%s</a>',
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'),
Expand Down
12 changes: 7 additions & 5 deletions lib/private/Mail/EMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<br/>", $text); // convert newlines to HTML breaks
}
if ($plainMetaInfo === '') {
if ($plainMetaInfo === '' || $plainMetaInfo === true) {
$plainMetaInfo = $metaInfo;
$metaInfo = htmlspecialchars($metaInfo);
}
Expand Down Expand Up @@ -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));
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/public/Mail/IEMailTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a44945

Please sign in to comment.