From 050ce1d40bf344510338a401ce6b68f76ed3f5e5 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 11 Apr 2017 16:13:34 -0500 Subject: [PATCH 1/9] Add addBodyButton to add a single button to email templates Signed-off-by: Morris Jobke --- lib/private/Mail/EMailTemplate.php | 64 +++++++ lib/public/Mail/IEMailTemplate.php | 10 + .../new-account-email-single-button.html | 174 ++++++++++++++++++ .../new-account-email-single-button.txt | 9 + tests/lib/Mail/EMailTemplateTest.php | 38 ++++ 5 files changed, 295 insertions(+) create mode 100644 tests/data/emails/new-account-email-single-button.html create mode 100644 tests/data/emails/new-account-email-single-button.txt diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index 338f6594f5e57..b47dcf09bfb3f 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -225,6 +225,46 @@ class EMailTemplate implements IEMailTemplate { +EOF; + + protected $button = << + + +   + + + + + + + + + +
+ + + + + +
+
+ + + + +
+ + + + +
+ %s +
+
+
+
+
EOF; protected $bodyEnd = <<footerAdded) { + return; + } + + if (!$this->bodyOpened) { + $this->htmlBody .= $this->bodyBegin; + $this->bodyOpened = true; + } + + $color = $this->themingDefaults->getColorPrimary(); + $this->htmlBody .= vsprintf($this->button, [$color, $color, $url, $color, htmlspecialchars($text)]); + $this->plainBody .= $text . ': ' . $url . PHP_EOL; + + } + /** * Adds a logo and a text to the footer.
in the text will be replaced by new lines in the plain text email * diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index a1922e86151b8..7b85c154c3628 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -92,6 +92,16 @@ public function addBodyText($text, $plainText = ''); */ public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = ''); + /** + * Adds a button to the body of the email + * + * @param string $text Text of button + * @param string $url URL of button + * + * @since 12.0.0 + */ + public function addBodyButton($text, $url); + /** * Adds a logo and a text to the footer.
in the text will be replaced by new lines in the plain text email * diff --git a/tests/data/emails/new-account-email-single-button.html b/tests/data/emails/new-account-email-single-button.html new file mode 100644 index 0000000000000..c204bedb23410 --- /dev/null +++ b/tests/data/emails/new-account-email-single-button.html @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + +
+
+ + + +
+ + + + + + +
+ + + +
+ +
+ + +
+
+
+ + + + + + +
 
+ + + + + +
+

Welcome aboard

+
+ + + + + + +
 
+ + + +
+ + + + + + +
+ + + + + + +
 
+ + + + + +
+ + + + + +
+

You have now an Nextcloud account, you can add, protect, and share your data.

+
+
+ + + + + +
+ + + + + +
+

Your username is: abc

+
+
+ + + + + +
 
+ + + + + + +
+ + + + + +
+
+ + + + +
+ + + + +
+ Set your password +
+
+
+
+
+
+
+ + + + + +
 
+ + + + +
+
+ +
                                                           
+ + \ No newline at end of file diff --git a/tests/data/emails/new-account-email-single-button.txt b/tests/data/emails/new-account-email-single-button.txt new file mode 100644 index 0000000000000..b93321f8c9a3f --- /dev/null +++ b/tests/data/emails/new-account-email-single-button.txt @@ -0,0 +1,9 @@ +Welcome aboard + +You have now an Nextcloud account, you can add, protect, and share your data. + +Your username is: abc + +Set your password: https://example.org/resetPassword/123 +-- +TestCloud - A safe home for your data diff --git a/tests/lib/Mail/EMailTemplateTest.php b/tests/lib/Mail/EMailTemplateTest.php index 9f80dad642a39..664da6c17e57e 100644 --- a/tests/lib/Mail/EMailTemplateTest.php +++ b/tests/lib/Mail/EMailTemplateTest.php @@ -125,6 +125,44 @@ public function testEMailTemplateDefaultFooter() { $this->assertSame($expectedTXT, $this->emailTemplate->renderText()); } + public function testEMailTemplateSingleButton() { + $this->defaults + ->expects($this->any()) + ->method('getColorPrimary') + ->willReturn('#0082c9'); + $this->defaults + ->expects($this->any()) + ->method('getName') + ->willReturn('TestCloud'); + $this->defaults + ->expects($this->any()) + ->method('getSlogan') + ->willReturn('A safe home for your data'); + $this->defaults + ->expects($this->any()) + ->method('getLogo') + ->willReturn('/img/logo-mail-header.png'); + $this->urlGenerator + ->expects($this->once()) + ->method('getAbsoluteURL') + ->with('/img/logo-mail-header.png') + ->willReturn('https://example.org/img/logo-mail-header.png'); + + $this->emailTemplate->addHeader(); + $this->emailTemplate->addHeading('Welcome aboard'); + $this->emailTemplate->addBodyText('You have now an Nextcloud account, you can add, protect, and share your data.'); + $this->emailTemplate->addBodyText('Your username is: abc'); + $this->emailTemplate->addBodyButton( + 'Set your password', 'https://example.org/resetPassword/123' + ); + $this->emailTemplate->addFooter(); + + $expectedHTML = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-single-button.html'); + $this->assertSame($expectedHTML, $this->emailTemplate->renderHTML()); + $expectedTXT = file_get_contents(\OC::$SERVERROOT . '/tests/data/emails/new-account-email-single-button.txt'); + $this->assertSame($expectedTXT, $this->emailTemplate->renderText()); + } + public function testEMailTemplateAlternativePlainTexts() { From 33e077c1c1243884342d51ddc57a1aca4f33049d Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 11 Apr 2017 16:17:44 -0500 Subject: [PATCH 2/9] Properly escape heading, body and button text Signed-off-by: Morris Jobke --- lib/private/Mail/EMailTemplate.php | 16 +++++++++++----- lib/public/Mail/IEMailTemplate.php | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index b47dcf09bfb3f..bfaee72beddc0 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -345,7 +345,7 @@ public function addHeading($title, $plainTitle = '') { $plainTitle = $title; } - $this->htmlBody .= vsprintf($this->heading, [$title]); + $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; } @@ -368,7 +368,7 @@ public function addBodyText($text, $plainText = '') { $this->bodyOpened = true; } - $this->htmlBody .= vsprintf($this->bodyText, [$text]); + $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; } @@ -382,7 +382,12 @@ public function addBodyText($text, $plainText = '') { * @param string $plainTextLeft Text of left button that is used in the plain text version - if unset the $textLeft is used * @param string $plainTextRight Text of right button that is used in the plain text version - if unset the $textRight is used */ - public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $plainTextLeft = '', $plainTextRight = '') { + public function addBodyButtonGroup($textLeft, + $urlLeft, + $textRight, + $urlRight, + $plainTextLeft = '', + $plainTextRight = '') { if ($this->footerAdded) { return; } @@ -400,7 +405,8 @@ public function addBodyButtonGroup($textLeft, $urlLeft, $textRight, $urlRight, $ } $color = $this->themingDefaults->getColorPrimary(); - $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, $textLeft, $urlRight, $textRight]); + + $this->htmlBody .= vsprintf($this->buttonGroup, [$color, $color, $urlLeft, $color, htmlspecialchars($textLeft), $urlRight, htmlspecialchars($textRight)]); $this->plainBody .= $plainTextLeft . ': ' . $urlLeft . PHP_EOL; $this->plainBody .= $plainTextRight . ': ' . $urlRight . PHP_EOL . PHP_EOL; @@ -433,7 +439,7 @@ public function addBodyButton($text, $url) { /** * Adds a logo and a text to the footer.
in the text will be replaced by new lines in the plain text email * - * @param string $text + * @param string $text If the text is empty the default "Name - Slogan
This is an automatically generated email" will be used */ public function addFooter($text = '') { if($text === '') { diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index 7b85c154c3628..d0123f227395c 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -105,7 +105,7 @@ public function addBodyButton($text, $url); /** * Adds a logo and a text to the footer.
in the text will be replaced by new lines in the plain text email * - * @param string $text + * @param string $text If the text is empty the default "Name - Slogan
This is an automatically generated email" will be used * * @since 12.0.0 */ From d0bae447fb4a8ad6e7b3d51390cb9a2bdbf24591 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Tue, 11 Apr 2017 16:18:31 -0500 Subject: [PATCH 3/9] Use new email design for sharebymail emails Signed-off-by: Morris Jobke --- apps/sharebymail/lib/ShareByMailProvider.php | 99 ++++++++----------- apps/sharebymail/templates/altmail.php | 36 ------- .../sharebymail/templates/altmailpassword.php | 32 ------ apps/sharebymail/templates/mail.php | 63 ------------ apps/sharebymail/templates/mailpassword.php | 59 ----------- 5 files changed, 39 insertions(+), 250 deletions(-) delete mode 100644 apps/sharebymail/templates/altmail.php delete mode 100644 apps/sharebymail/templates/altmailpassword.php delete mode 100644 apps/sharebymail/templates/mail.php delete mode 100644 apps/sharebymail/templates/mailpassword.php diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index ec9568b734e2e..8f63ef028d929 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -260,42 +260,34 @@ protected function sendMailNotification($filename, $link, $owner, $initiator, $s } $message = $this->mailer->createMessage(); - $htmlBody = $this->createMailBody('mail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); - $textBody = $this->createMailBody('altmail', $filename, $link, $ownerDisplayName, $initiatorDisplayName); - $message->setTo([$shareWith]); - $message->setSubject($subject); - $message->setBody($textBody, 'text/plain'); - $message->setHtmlBody($htmlBody); - $this->mailer->send($message); - } + $emailTemplate = $this->mailer->createEMailTemplate(); - /** - * create mail body - * - * @param $filename - * @param $link - * @param $owner - * @param $initiator - * @return string plain text mail - * @throws HintException - */ - protected function createMailBody($template, $filename, $link, $owner, $initiator) { - - $mailBodyTemplate = new Template('sharebymail', $template, ''); - $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); - $mailBodyTemplate->assign ('link', $link); - $mailBodyTemplate->assign ('owner', \OCP\Util::sanitizeHTML($owner)); - $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); - $mailBodyTemplate->assign ('onBehalfOf', $initiator !== $owner); - $mailBody = $mailBodyTemplate->fetchPage(); - - if (is_string($mailBody)) { - return $mailBody; + $emailTemplate->addHeader(); + $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename])); + + if ($owner === $initiator) { + $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); + } else { + $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); } - throw new HintException('Failed to create the E-mail', - $this->l->t('Failed to create the E-mail')); + $text .= ' ' . $this->l->t('Click the button below to open it.'); + + $emailTemplate->addBodyText($text); + + $emailTemplate->addBodyButton( + $this->l->t('Open »%s«', [$filename]), + $link + ); + $emailTemplate->addFooter(); + + $message->setTo([$shareWith]); + $message->setSubject($subject); + $message->setBody($emailTemplate->renderText(), 'text/plain'); + $message->setHtmlBody($emailTemplate->renderHTML()); + $this->mailer->send($message); + } /** @@ -316,39 +308,26 @@ protected function sendPassword($filename, $initiator, $shareWith, $password) { $subject = (string)$this->l->t('Password to access »%s« shared to you by %s', [$filename, $initiatorDisplayName]); $message = $this->mailer->createMessage(); - $htmlBody = $this->createMailBodyToSendPassword('mailpassword', $filename, $initiatorDisplayName, $password); - $textBody = $this->createMailBodyToSendPassword('altmailpassword', $filename,$initiatorDisplayName, $password); - $message->setTo([$shareWith]); - $message->setSubject($subject); - $message->setBody($textBody, 'text/plain'); - $message->setHtmlBody($htmlBody); - $this->mailer->send($message); - } + $emailTemplate = $this->mailer->createEMailTemplate(); - /** - * create mail body to send password to recipient - * - * @param string $filename - * @param string $initiator - * @param string $password - * @return string plain text mail - * @throws HintException - */ - protected function createMailBodyToSendPassword($template, $filename, $initiator, $password) { + $emailTemplate->addHeader(); + $emailTemplate->addHeading($this->l->t('Password to access »%s«', [$filename])); - $mailBodyTemplate = new Template('sharebymail', $template, ''); - $mailBodyTemplate->assign ('filename', \OCP\Util::sanitizeHTML($filename)); - $mailBodyTemplate->assign ('password', \OCP\Util::sanitizeHTML($password)); - $mailBodyTemplate->assign ('initiator', \OCP\Util::sanitizeHTML($initiator)); - $mailBody = $mailBodyTemplate->fetchPage(); + $emailTemplate->addBodyText($this->l->t( + '%s shared »%s« with you. You should have already received a separate mail with a link to access it.', + [$initiatorDisplayName, $filename] + )); + $emailTemplate->addBodyText($this->l->t('It is protected with the following password: %s', [$password])); - if (is_string($mailBody)) { - return $mailBody; - } + $emailTemplate->addFooter(); + + $message->setTo([$shareWith]); + $message->setSubject($subject); + $message->setBody($emailTemplate->renderText(), 'text/plain'); + $message->setHtmlBody($emailTemplate->renderHTML()); + $this->mailer->send($message); - throw new HintException('Failed to create the E-mail', - $this->l->t('Failed to create the E-mail')); } diff --git a/apps/sharebymail/templates/altmail.php b/apps/sharebymail/templates/altmail.php deleted file mode 100644 index 7b9de6295ff9a..0000000000000 --- a/apps/sharebymail/templates/altmail.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -/** @var OC_Theme $theme */ -/** @var array $_ */ -if ($_['onBehalfOf']) { - print_unescaped($l->t("Hey there,\n\n%s shared »%s« with you on behalf of %s.\n\n%s\n\n", [$_['owner'], $_['filename'], $_['initiator'], $_['link']])); -} else { - print_unescaped($l->t("Hey there,\n\n%s shared »%s« with you.\n\n%s\n\n", [$_['owner'], $_['filename'], $_['link']])); -} -// TRANSLATORS term at the end of a mail -p($l->t("Cheers!")); -print_unescaped("\n"); -?> - --- -getName() . ' - ' . $theme->getSlogan()); ?> -getBaseUrl()); diff --git a/apps/sharebymail/templates/altmailpassword.php b/apps/sharebymail/templates/altmailpassword.php deleted file mode 100644 index f6e4c5b415859..0000000000000 --- a/apps/sharebymail/templates/altmailpassword.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -/** @var OC_Theme $theme */ -/** @var array $_ */ -print_unescaped($l->t("Hey there,\n\n%s shared »%s« with you.\nYou should have already received a separate mail with a link to access it.\n\nIt is protected with the following password: %s\n\n", [$_['initiator'], $_['filename'], $_['password']])); -// TRANSLATORS term at the end of a mail -p($l->t("Cheers!")); -print_unescaped("\n"); -?> - - -- -getName() . ' - ' . $theme->getSlogan()); ?> -getBaseUrl()); diff --git a/apps/sharebymail/templates/mail.php b/apps/sharebymail/templates/mail.php deleted file mode 100644 index daf12fe034a71..0000000000000 --- a/apps/sharebymail/templates/mail.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -/** @var OC_Theme $theme */ -/** @var array $_ */ -?> - - - -
- - - - - - - - - - - - - - - - - -
- <?php p($theme->getName()); ?> -
 
  - t('Hey there,

%s shared %s with you on behalf of %s.

', [$_['owner'], $_['link'], $_['filename'], $_['initiator']])); - } else { - print_unescaped($l->t('Hey there,

%s shared %s with you.

', [$_['owner'], $_['link'], $_['filename']])); - } - // TRANSLATORS term at the end of a mail - p($l->t('Cheers!')); - ?> -
 
 --
- getName()); ?> - - getSlogan()); ?> -
getBaseUrl());?> -
 
-
diff --git a/apps/sharebymail/templates/mailpassword.php b/apps/sharebymail/templates/mailpassword.php deleted file mode 100644 index 714a61cecd923..0000000000000 --- a/apps/sharebymail/templates/mailpassword.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -/** @var OCA\Theming\ThemingDefaults $theme */ -/** @var array $_ */ -?> - - - -
- - - - - - - - - - - - - - - - - -
- <?php p($theme->getName()); ?> -
 
  - t('Hey there,

%s shared %s with you.
You should have already received a separate mail with a link to access it.

It is protected with the following password: %s

', [$_['initiator'], $_['filename'], $_['password']])); - // TRANSLATORS term at the end of a mail - p($l->t('Cheers!')); - ?> -
 
 --
- getName()); ?> - - getSlogan()); ?> -
getBaseUrl());?> -
 
-
From 506c7731a6168e35bff28c32d9bea933aee907d4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 12 Apr 2017 11:52:33 +0200 Subject: [PATCH 4/9] Don't duplicate the sentence with the header Signed-off-by: Joas Schilling --- apps/sharebymail/lib/ShareByMailProvider.php | 2 +- lib/private/Mail/EMailTemplate.php | 7 +++++-- lib/public/Mail/IEMailTemplate.php | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 8f63ef028d929..f2c68f9376d85 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -264,7 +264,7 @@ protected function sendMailNotification($filename, $link, $owner, $initiator, $s $emailTemplate = $this->mailer->createEMailTemplate(); $emailTemplate->addHeader(); - $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename])); + $emailTemplate->addHeading($this->l->t('%s shared »%s« with you', [$ownerDisplayName, $filename]), false); if ($owner === $initiator) { $text = $this->l->t('%s shared »%s« with you.', [$ownerDisplayName, $filename]); diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index bfaee72beddc0..f82ddc689ebb8 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -353,7 +353,8 @@ public function addHeading($title, $plainTitle = '') { * Adds a paragraph to the body of the email * * @param string $text - * @param string $plainText Text that is used in the plain text email - if empty the $text is used + * @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 */ public function addBodyText($text, $plainText = '') { if ($this->footerAdded) { @@ -369,7 +370,9 @@ public function addBodyText($text, $plainText = '') { } $this->htmlBody .= vsprintf($this->bodyText, [htmlspecialchars($text)]); - $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; + if ($plainText !== false) { + $this->plainBody .= $plainText . PHP_EOL . PHP_EOL; + } } /** diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index d0123f227395c..8e3233ee426d6 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -72,7 +72,8 @@ public function addHeading($title, $plainTitle = ''); * Adds a paragraph to the body of the email * * @param string $text - * @param string $plainText Text that is used in the plain text email - if empty the $text is used + * @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 * * @since 12.0.0 */ From 1c8c62272c6862405c435e015c107b1767e43b9b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 12 Apr 2017 11:52:58 +0200 Subject: [PATCH 5/9] Use instance name as alt-text Signed-off-by: Joas Schilling --- lib/private/Mail/EMailTemplate.php | 4 ++-- tests/data/emails/new-account-email-custom.html | 2 +- tests/data/emails/new-account-email-single-button.html | 2 +- tests/data/emails/new-account-email.html | 2 +- tests/lib/Mail/EMailTemplateTest.php | 4 ++++ 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index f82ddc689ebb8..dd5cf605c99f5 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -98,7 +98,7 @@ class EMailTemplate implements IEMailTemplate {
- +
@@ -328,7 +328,7 @@ public function addHeader() { $this->headerAdded = true; $logoUrl = $this->urlGenerator->getAbsoluteURL($this->themingDefaults->getLogo()); - $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl]); + $this->htmlBody .= vsprintf($this->header, [$this->themingDefaults->getColorPrimary(), $logoUrl, $this->themingDefaults->getName()]); } /** diff --git a/tests/data/emails/new-account-email-custom.html b/tests/data/emails/new-account-email-custom.html index c754412e6810b..a60902ae306f5 100644 --- a/tests/data/emails/new-account-email-custom.html +++ b/tests/data/emails/new-account-email-custom.html @@ -23,7 +23,7 @@
- +
diff --git a/tests/data/emails/new-account-email-single-button.html b/tests/data/emails/new-account-email-single-button.html index c204bedb23410..50763efa5b5fe 100644 --- a/tests/data/emails/new-account-email-single-button.html +++ b/tests/data/emails/new-account-email-single-button.html @@ -23,7 +23,7 @@
- +
diff --git a/tests/data/emails/new-account-email.html b/tests/data/emails/new-account-email.html index 4fb6f5af15e0b..2e3866163d7af 100644 --- a/tests/data/emails/new-account-email.html +++ b/tests/data/emails/new-account-email.html @@ -23,7 +23,7 @@
- +
diff --git a/tests/lib/Mail/EMailTemplateTest.php b/tests/lib/Mail/EMailTemplateTest.php index 664da6c17e57e..f9e1ecf29cad1 100644 --- a/tests/lib/Mail/EMailTemplateTest.php +++ b/tests/lib/Mail/EMailTemplateTest.php @@ -62,6 +62,10 @@ public function testEMailTemplateCustomFooter() { ->expects($this->any()) ->method('getLogo') ->willReturn('/img/logo-mail-header.png'); + $this->defaults + ->expects($this->any()) + ->method('getName') + ->willReturn('TestCloud'); $this->urlGenerator ->expects($this->once()) ->method('getAbsoluteURL') From 0a464dfb61a485a1340ecc9279e0db262154f059 Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 12 Apr 2017 12:43:55 +0200 Subject: [PATCH 6/9] make the plain text footer standard compliant and add a space after '--'. It also adds a line break in front so that there is some spacing between the mail body and the footer Signed-off-by: Bjoern Schiessle --- lib/private/Mail/EMailTemplate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index dd5cf605c99f5..b0378496d9ecd 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -461,7 +461,7 @@ public function addFooter($text = '') { $this->htmlBody .= vsprintf($this->footer, [$text]); $this->htmlBody .= $this->tail; - $this->plainBody .= '--' . PHP_EOL; + $this->plainBody .= PHP_EOL . '-- ' . PHP_EOL; $this->plainBody .= str_replace('
', PHP_EOL, $text); } From 4b639e276322b6294b8ac62d88de0985c0ab637a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 12 Apr 2017 15:33:14 +0200 Subject: [PATCH 7/9] No newlines when heading is empty Signed-off-by: Joas Schilling --- lib/private/Mail/EMailTemplate.php | 7 +++++-- lib/public/Mail/IEMailTemplate.php | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/private/Mail/EMailTemplate.php b/lib/private/Mail/EMailTemplate.php index b0378496d9ecd..805126d2ad836 100644 --- a/lib/private/Mail/EMailTemplate.php +++ b/lib/private/Mail/EMailTemplate.php @@ -335,7 +335,8 @@ public function addHeader() { * Adds a heading to the email * * @param string $title - * @param string $plainTitle Title that is used in the plain text email - if empty the $title is used + * @param string $plainTitle|bool Title that is used in the plain text email + * if empty the $title is used, if false none will be used */ public function addHeading($title, $plainTitle = '') { if ($this->footerAdded) { @@ -346,7 +347,9 @@ public function addHeading($title, $plainTitle = '') { } $this->htmlBody .= vsprintf($this->heading, [htmlspecialchars($title)]); - $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; + if ($plainTitle !== false) { + $this->plainBody .= $plainTitle . PHP_EOL . PHP_EOL; + } } /** diff --git a/lib/public/Mail/IEMailTemplate.php b/lib/public/Mail/IEMailTemplate.php index 8e3233ee426d6..4e308509c42f3 100644 --- a/lib/public/Mail/IEMailTemplate.php +++ b/lib/public/Mail/IEMailTemplate.php @@ -62,7 +62,8 @@ public function addHeader(); * Adds a heading to the email * * @param string $title - * @param string $plainTitle Title that is used in the plain text email - if empty the $title is used + * @param string $plainTitle|bool Title that is used in the plain text email + * if empty the $title is used, if false none will be used * * @since 12.0.0 */ From 983210de2e2798a70d8dcdce898c6f4f2d01c9fa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 12 Apr 2017 15:33:35 +0200 Subject: [PATCH 8/9] Dont add click-button text for plaintext mails Signed-off-by: Joas Schilling --- apps/sharebymail/lib/ShareByMailProvider.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index f2c68f9376d85..0b959ce4265e8 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -272,9 +272,10 @@ protected function sendMailNotification($filename, $link, $owner, $initiator, $s $text= $this->l->t('%s shared »%s« with you on behalf of %s.', [$ownerDisplayName, $filename, $initiator]); } - $text .= ' ' . $this->l->t('Click the button below to open it.'); - - $emailTemplate->addBodyText($text); + $emailTemplate->addBodyText( + $text . ' ' . $this->l->t('Click the button below to open it.'), + $text + ); $emailTemplate->addBodyButton( $this->l->t('Open »%s«', [$filename]), From ae4c2893a218461099d01071faf64ede78f9bc40 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Wed, 12 Apr 2017 12:34:42 -0500 Subject: [PATCH 9/9] Fix unit tests Signed-off-by: Morris Jobke --- .../Settings/Mailer/NewUserMailHelperTest.php | 20 ++++++++++--------- ...-account-email-custom-text-alternative.txt | 3 ++- .../data/emails/new-account-email-custom.txt | 3 ++- .../new-account-email-single-button.txt | 3 ++- tests/data/emails/new-account-email.txt | 3 ++- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/tests/Settings/Mailer/NewUserMailHelperTest.php b/tests/Settings/Mailer/NewUserMailHelperTest.php index ef9dae8766c7c..707abe9588da8 100644 --- a/tests/Settings/Mailer/NewUserMailHelperTest.php +++ b/tests/Settings/Mailer/NewUserMailHelperTest.php @@ -144,7 +144,7 @@ public function testGenerateTemplateWithPasswordResetToken() { ->method('getUID') ->willReturn('john'); $this->defaults - ->expects($this->at(0)) + ->expects($this->any()) ->method('getName') ->willReturn('TestCloud'); @@ -174,7 +174,7 @@ public function testGenerateTemplateWithPasswordResetToken() {
- +
@@ -227,7 +227,7 @@ public function testGenerateTemplateWithPasswordResetToken() { @@ -324,7 +324,7 @@ public function testGenerateTemplateWithPasswordResetToken() {
-

You have now an account, you can add, protect, and share your data.

+

You have now an TestCloud account, you can add, protect, and share your data.

-

-
This is an automatically generated email, please do not reply.

+

TestCloud -
This is an automatically generated email, please do not reply.

@@ -340,15 +340,16 @@ public function testGenerateTemplateWithPasswordResetToken() { $expectedTextBody = <<
- +
@@ -579,7 +580,8 @@ public function testGenerateTemplateWithoutPasswordResetToken() { Go to TestCloud: https://example.com/ Install Client: https://nextcloud.com/install/#install-clients --- + +-- TestCloud - This is an automatically generated email, please do not reply. EOF; 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 bcbc6632175e5..9f02563edfeca 100644 --- a/tests/data/emails/new-account-email-custom-text-alternative.txt +++ b/tests/data/emails/new-account-email-custom-text-alternative.txt @@ -7,5 +7,6 @@ Your username is: abc Set your password - text: https://example.org/resetPassword/123 Install Client - text: https://nextcloud.com/install/#install-clients --- + +-- TestCloud - A safe home for your data diff --git a/tests/data/emails/new-account-email-custom.txt b/tests/data/emails/new-account-email-custom.txt index 962128980e018..e849c73d941a3 100644 --- a/tests/data/emails/new-account-email-custom.txt +++ b/tests/data/emails/new-account-email-custom.txt @@ -7,5 +7,6 @@ Your username is: abc Set your password: https://example.org/resetPassword/123 Install Client: https://nextcloud.com/install/#install-clients --- + +-- TestCloud - A safe home for your data diff --git a/tests/data/emails/new-account-email-single-button.txt b/tests/data/emails/new-account-email-single-button.txt index b93321f8c9a3f..5595496140033 100644 --- a/tests/data/emails/new-account-email-single-button.txt +++ b/tests/data/emails/new-account-email-single-button.txt @@ -5,5 +5,6 @@ You have now an Nextcloud account, you can add, protect, and share your data. Your username is: abc Set your password: https://example.org/resetPassword/123 --- + +-- TestCloud - A safe home for your data diff --git a/tests/data/emails/new-account-email.txt b/tests/data/emails/new-account-email.txt index 6732d806d765e..e01268b562016 100644 --- a/tests/data/emails/new-account-email.txt +++ b/tests/data/emails/new-account-email.txt @@ -7,6 +7,7 @@ Your username is: abc Set your password: https://example.org/resetPassword/123 Install Client: https://nextcloud.com/install/#install-clients --- + +-- TestCloud - A safe home for your data This is an automatically generated email, please do not reply. \ No newline at end of file