diff --git a/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php b/apps/dav/lib/CalDAV/Schedule/IMipPlugin.php index 6358a3a029397..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 @@ -108,6 +107,7 @@ class IMipPlugin extends SabreIMipPlugin { public const METHOD_REQUEST = 'request'; public const METHOD_REPLY = 'reply'; public const METHOD_CANCEL = 'cancel'; + public const IMIP_INDENT = 15; // Enough for the length of all body bullet items, in all languages /** * @param IConfig $config @@ -204,26 +204,6 @@ public function schedule(Message $iTipMessage) { $meetingTitle = $vevent->SUMMARY; $meetingDescription = $vevent->DESCRIPTION; - $start = $vevent->DTSTART; - if (isset($vevent->DTEND)) { - $end = $vevent->DTEND; - } elseif (isset($vevent->DURATION)) { - $isFloating = $vevent->DTSTART->isFloating(); - $end = clone $vevent->DTSTART; - $endDateTime = $end->getDateTime(); - $endDateTime = $endDateTime->add(DateTimeParser::parse($vevent->DURATION->getValue())); - $end->setDateTime($endDateTime, $isFloating); - } elseif (!$vevent->DTSTART->hasTime()) { - $isFloating = $vevent->DTSTART->isFloating(); - $end = clone $vevent->DTSTART; - $endDateTime = $end->getDateTime(); - $endDateTime = $endDateTime->modify('+1 day'); - $end->setDateTime($endDateTime, $isFloating); - } else { - $end = clone $vevent->DTSTART; - } - - $meetingWhen = $this->generateWhenString($l10n, $start, $end); $meetingUrl = $vevent->URL; $meetingLocation = $vevent->LOCATION; @@ -261,10 +241,8 @@ public function schedule(Message $iTipMessage) { $summary = ((string) $summary !== '') ? (string) $summary : $l10n->t('Untitled event'); - $this->addSubjectAndHeading($template, $l10n, $method, $summary, - $meetingAttendeeName, $meetingInviteeName); - $this->addBulletList($template, $l10n, $meetingWhen, $meetingLocation, - $meetingDescription, $meetingUrl); + $this->addSubjectAndHeading($template, $l10n, $method, $summary); + $this->addBulletList($template, $l10n, $vevent); // Only add response buttons to invitation requests: Fix Issue #11230 @@ -370,7 +348,6 @@ private function getLastOccurrence(VCalendar $vObject) { return $lastOccurrence; } - /** * @param Message $iTipMessage * @return null|Property @@ -420,10 +397,28 @@ private function getAttendeeRSVP(Property $attendee = null) { /** * @param IL10N $l10n - * @param Property $dtstart - * @param Property $dtend + * @param VEvent $vevent */ - private function generateWhenString(IL10N $l10n, Property $dtstart, Property $dtend) { + private function generateWhenString(IL10N $l10n, VEvent $vevent) { + $dtstart = $vevent->DTSTART; + if (isset($vevent->DTEND)) { + $dtend = $vevent->DTEND; + } elseif (isset($vevent->DURATION)) { + $isFloating = $vevent->DTSTART->isFloating(); + $dtend = clone $vevent->DTSTART; + $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 = $dtend->getDateTime(); + $endDateTime = $endDateTime->modify('+1 day'); + $dtend->setDateTime($endDateTime, $isFloating); + } else { + $dtend = clone $vevent->DTSTART; + } + $isAllDay = $dtstart instanceof Property\ICalendar\Date; /** @var Property\ICalendar\Date | Property\ICalendar\DateTime $dtstart */ @@ -507,49 +502,132 @@ private function isDayEqual(\DateTime $dtStart, \DateTime $dtEnd) { * @param IL10N $l10n * @param string $method * @param string $summary - * @param string $attendeeName - * @param string $inviteeName */ private function addSubjectAndHeading(IEMailTemplate $template, IL10N $l10n, - $method, $summary, $attendeeName, $inviteeName) { + $method, $summary) { if ($method === self::METHOD_CANCEL) { - $template->setSubject('Cancelled: ' . $summary); - $template->addHeading($l10n->t('Invitation canceled'), $l10n->t('Hello %s,', [$attendeeName])); - $template->addBodyText($l10n->t('The meeting »%1$s« with %2$s was canceled.', [$summary, $inviteeName])); + $template->setSubject('Canceled: ' . $summary); + $template->addHeading($l10n->t('Invitation canceled')); } elseif ($method === self::METHOD_REPLY) { $template->setSubject('Re: ' . $summary); - $template->addHeading($l10n->t('Invitation updated'), $l10n->t('Hello %s,', [$attendeeName])); - $template->addBodyText($l10n->t('The meeting »%1$s« with %2$s was updated.', [$summary, $inviteeName])); + $template->addHeading($l10n->t('Invitation updated')); } else { $template->setSubject('Invitation: ' . $summary); - $template->addHeading($l10n->t('%1$s invited you to »%2$s«', [$inviteeName, $summary]), $l10n->t('Hello %s,', [$attendeeName])); + $template->addHeading($l10n->t('Invitation')); + } + } + + /** + * @param IEMailTemplate $template + * @param IL10N $l10n + * @param VEVENT $vevent + */ + private function addBulletList(IEMailTemplate $template, IL10N $l10n, $vevent) { + if ($vevent->SUMMARY) { + $template->addBodyListItem($vevent->SUMMARY, $l10n->t('Title:'), + $this->getAbsoluteImagePath('caldav/title.svg'),'','',self::IMIP_INDENT); + } + $meetingWhen = $this->generateWhenString($l10n, $vevent); + if ($meetingWhen) { + $template->addBodyListItem($meetingWhen, $l10n->t('Time:'), + $this->getAbsoluteImagePath('caldav/time.svg'),'','',self::IMIP_INDENT); + } + if ($vevent->LOCATION) { + $template->addBodyListItem($vevent->LOCATION, $l10n->t('Location:'), + $this->getAbsoluteImagePath('caldav/location.svg'),'','',self::IMIP_INDENT); + } + if ($vevent->URL) { + $url = $vevent->URL->getValue(); + $template->addBodyListItem(sprintf('%s', + htmlspecialchars($url), + htmlspecialchars($url)), + $l10n->t('Link:'), + $this->getAbsoluteImagePath('caldav/link.svg'), + $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->getValue(), $l10n->t('Description:'), + $this->getAbsoluteImagePath('caldav/description.svg'),'','',self::IMIP_INDENT); } } /** + * addAttendees: add organizer and attendee names/emails to iMip mail. + * + * Enable with DAV setting: invitation_list_attendees (default: no) + * + * The default is 'no', which matches old behavior, and is privacy preserving. + * + * To enable including attendees in invitation emails: + * % php occ config:app:set dav invitation_list_attendees --value yes + * * @param IEMailTemplate $template * @param IL10N $l10n - * @param string $time - * @param string $location - * @param string $description - * @param string $url + * @param Message $iTipMessage + * @param int $lastOccurrence + * @author brad2014 on github.com */ - private function addBulletList(IEMailTemplate $template, IL10N $l10n, $time, $location, $description, $url) { - $template->addBodyListItem($time, $l10n->t('When:'), - $this->getAbsoluteImagePath('filetypes/text-calendar.svg')); - if ($location) { - $template->addBodyListItem($location, $l10n->t('Where:'), - $this->getAbsoluteImagePath('filetypes/location.svg')); + private function addAttendees(IEMailTemplate $template, IL10N $l10n, VEvent $vevent) { + if ($this->config->getAppValue('dav', 'invitation_list_attendees', 'no') === 'no') { + return; } - if ($description) { - $template->addBodyListItem((string)$description, $l10n->t('Description:'), - $this->getAbsoluteImagePath('filetypes/text.svg')); + + 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'])) { + /** @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'), + $organizerText,'',self::IMIP_INDENT); } - if ($url) { - $template->addBodyListItem((string)$url, $l10n->t('Link:'), - $this->getAbsoluteImagePath('filetypes/link.svg')); + + $attendees = $vevent->select('ATTENDEE'); + if (count($attendees) === 0) { + return; + } + + $attendeesHTML = []; + $attendeesText = []; + foreach ($attendees as $attendee) { + $attendeeURI = $attendee->getNormalizedValue(); + list($scheme,$attendeeEmail) = explode(':',$attendeeURI,2); # strip off scheme mailto: + $attendeeName = isset($attendee['CN']) ? $attendee['CN'] : null; + $attendeeHTML = sprintf('%s', + htmlspecialchars($attendeeURI), + htmlspecialchars($attendeeName ?: $attendeeEmail)); + $attendeeText = sprintf('%s <%s>', $attendeeName, $attendeeEmail); + if (isset($attendee['PARTSTAT']) + && strcasecmp($attendee['PARTSTAT'], 'ACCEPTED') === 0) { + $attendeeHTML .= ' ✔︎'; + $attendeeText .= ' ✔︎'; + } + array_push($attendeesHTML, $attendeeHTML); + array_push($attendeesText, $attendeeText); } + + $template->addBodyListItem(implode('
',$attendeesHTML), $l10n->t('Attendees:'), + $this->getAbsoluteImagePath('caldav/attendees.svg'), + implode("\n",$attendeesText),'',self::IMIP_INDENT); } /** diff --git a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php index 8faa54f534a0c..a31fdfdc5f712 100644 --- a/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php +++ b/apps/dav/tests/unit/CalDAV/Schedule/IMipPluginTest.php @@ -136,6 +136,7 @@ protected function setUp(): void { public function testDelivery() { $this->config + ->expects($this->at(1)) ->method('getAppValue') ->with('dav', 'invitation_link_recipients', 'yes') ->willReturn('yes'); @@ -148,6 +149,7 @@ public function testDelivery() { public function testFailedDelivery() { $this->config + ->expects($this->at(1)) ->method('getAppValue') ->with('dav', 'invitation_link_recipients', 'yes') ->willReturn('yes'); @@ -163,6 +165,7 @@ public function testFailedDelivery() { public function testDeliveryWithNoCommonName() { $this->config + ->expects($this->at(1)) ->method('getAppValue') ->with('dav', 'invitation_link_recipients', 'yes') ->willReturn('yes'); @@ -188,9 +191,8 @@ public function testDeliveryWithNoCommonName() { */ public function testNoMessageSendForPastEvents(array $veventParams, bool $expectsMail) { $this->config - ->method('getAppValue') - ->with('dav', 'invitation_link_recipients', 'yes') - ->willReturn('yes'); + ->method('getAppValue') + ->willReturn('yes'); $message = $this->_testMessage($veventParams); @@ -228,6 +230,7 @@ public function testIncludeResponseButtons(string $config_setting, string $recip $this->_expectSend($recipient, true, $has_buttons); $this->config + ->expects($this->at(1)) ->method('getAppValue') ->with('dav', 'invitation_link_recipients', 'yes') ->willReturn($config_setting); @@ -252,14 +255,13 @@ public function dataIncludeResponseButtons() { public function testMessageSendWhenEventWithoutName() { $this->config ->method('getAppValue') - ->with('dav', 'invitation_link_recipients', 'yes') ->willReturn('yes'); $message = $this->_testMessage(['SUMMARY' => '']); $this->_expectSend('frodo@hobb.it', true, true,'Invitation: Untitled event'); $this->emailTemplate->expects($this->once()) ->method('addHeading') - ->with('Mr. Wizard invited you to »Untitled event«'); + ->with('Invitation'); $this->plugin->schedule($message); $this->assertEquals('1.1', $message->getScheduleStatus()); } diff --git a/apps/settings/tests/Mailer/NewUserMailHelperTest.php b/apps/settings/tests/Mailer/NewUserMailHelperTest.php index fdb5da3bb548b..7507c8a9dac7f 100644 --- a/apps/settings/tests/Mailer/NewUserMailHelperTest.php +++ b/apps/settings/tests/Mailer/NewUserMailHelperTest.php @@ -599,6 +599,7 @@ public function testGenerateTemplateWithoutPasswordResetToken() { Your username is: john + Go to TestCloud: https://example.com/ Install Client: https://nextcloud.com/install/#install-clients @@ -817,6 +818,7 @@ public function testGenerateTemplateWithoutUserId() { Welcome to your TestCloud account, you can add, protect, and share your data. + Go to TestCloud: https://example.com/ Install Client: https://nextcloud.com/install/#install-clients diff --git a/core/img/caldav/attendees.svg b/core/img/caldav/attendees.svg new file mode 100644 index 0000000000000..86c3d4a413201 --- /dev/null +++ b/core/img/caldav/attendees.svg @@ -0,0 +1 @@ + diff --git a/core/img/caldav/description.svg b/core/img/caldav/description.svg new file mode 100644 index 0000000000000..57c2b1f57251d --- /dev/null +++ b/core/img/caldav/description.svg @@ -0,0 +1 @@ + diff --git a/core/img/caldav/link.svg b/core/img/caldav/link.svg new file mode 100644 index 0000000000000..7bfbe1eb2de7e --- /dev/null +++ b/core/img/caldav/link.svg @@ -0,0 +1 @@ + diff --git a/core/img/caldav/location.svg b/core/img/caldav/location.svg new file mode 100644 index 0000000000000..5e63f7563cd4a --- /dev/null +++ b/core/img/caldav/location.svg @@ -0,0 +1 @@ + diff --git a/core/img/caldav/organizer.svg b/core/img/caldav/organizer.svg new file mode 100644 index 0000000000000..7b75d9e29a6d9 --- /dev/null +++ b/core/img/caldav/organizer.svg @@ -0,0 +1 @@ + diff --git a/core/img/caldav/time.svg b/core/img/caldav/time.svg new file mode 100644 index 0000000000000..2fdfde6796071 --- /dev/null +++ b/core/img/caldav/time.svg @@ -0,0 +1 @@ + diff --git a/core/img/caldav/title.svg b/core/img/caldav/title.svg new file mode 100644 index 0000000000000..57d674b9f2c4e --- /dev/null +++ b/core/img/caldav/title.svg @@ -0,0 +1 @@ + diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 2c8efa7e010f9..e3768ae6cde8a 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -447,19 +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 = '') { + 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); } @@ -475,11 +477,29 @@ public function addBodyListItem(string $text, string $metaInfo = '', string $ico } $this->htmlBody .= vsprintf($this->listItem, [$icon, $htmlText]); if ($plainText !== false) { - $this->plainBody .= ' * ' . $plainText; - if ($plainMetaInfo !== false) { - $this->plainBody .= ' (' . $plainMetaInfo . ')'; + if ($plainIndent === 0) { + /* + * If plainIndent is not set by caller, this is the old NC17 layout code. + */ + $this->plainBody .= ' * ' . $plainText; + if ($plainMetaInfo !== false) { + $this->plainBody .= ' (' . $plainMetaInfo . ')'; + } + $this->plainBody .= PHP_EOL; + } else { + /* + * Caller can set plainIndent > 0 to format plainText in tabular fashion. + * with plainMetaInfo in column 1, and plainText in column 2. + * The plainMetaInfo label is right justified in a field of width + * "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", + $label, + str_replace("\n", "\n" . str_repeat(' ', $plainIndent+1), $plainText)); } - $this->plainBody .= PHP_EOL; } } @@ -538,7 +558,7 @@ public function addBodyButtonGroup(string $textLeft, $textColor = $this->themingDefaults->getTextColorPrimary(); $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textColor, $textColor, $textLeft, $urlRight, $textRight]); - $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; + $this->plainBody .= PHP_EOL . $plainTextLeft . ': ' . $urlLeft . PHP_EOL; $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; } diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index 70046d5c508f3..5f4e235a7eef5 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 diff --git a/tests/data/emails/new-account-email-custom-text-alternative.txt b/tests/data/emails/new-account-email-custom-text-alternative.txt index f65744b20d906..03cb99c1d76c2 100644 --- a/tests/data/emails/new-account-email-custom-text-alternative.txt +++ b/tests/data/emails/new-account-email-custom-text-alternative.txt @@ -4,6 +4,7 @@ Welcome to your Nextcloud account, you can add, protect, and share your data. - Your username is: abc + Set your password - text: https://example.org/resetPassword/123 Install Client - text: https://nextcloud.com/install/#install-clients diff --git a/tests/data/emails/new-account-email-custom.txt b/tests/data/emails/new-account-email-custom.txt index 57c5202a744ed..c075c49d64900 100644 --- a/tests/data/emails/new-account-email-custom.txt +++ b/tests/data/emails/new-account-email-custom.txt @@ -4,6 +4,7 @@ Welcome to your Nextcloud account, you can add, protect, and share your data. Your username is: abc + Set your password: https://example.org/resetPassword/123 Install Client: https://nextcloud.com/install/#install-clients diff --git a/tests/data/emails/new-account-email.txt b/tests/data/emails/new-account-email.txt index 895241341831c..b246482af13f6 100644 --- a/tests/data/emails/new-account-email.txt +++ b/tests/data/emails/new-account-email.txt @@ -4,6 +4,7 @@ Welcome to your Nextcloud account, you can add, protect, and share your data. Your username is: abc + Set your password: https://example.org/resetPassword/123 Install Client: https://nextcloud.com/install/#install-clients