diff --git a/changelog/unreleased/36505 b/changelog/unreleased/36505 new file mode 100644 index 000000000000..f5fa6a3384f2 --- /dev/null +++ b/changelog/unreleased/36505 @@ -0,0 +1,5 @@ +Bugfix: enhance validation for sender e-mail address for e-mail notifications + +If a user wanted to use the e-mail notification mechanism in order to notify other users when creating public links as well as internal shares, an error was triggered if the e-mail address for this user was not set. The behavior has now been fixed. + +https://github.com/owncloud/core/pull/36505 diff --git a/lib/private/Share/MailNotifications.php b/lib/private/Share/MailNotifications.php index b5b7ac9a9856..0934d93f1f7e 100644 --- a/lib/private/Share/MailNotifications.php +++ b/lib/private/Share/MailNotifications.php @@ -183,6 +183,7 @@ public function sendInternalShareMail($sender, $node, $shareType, $recipientList 'internal', $recipientL10N ); + $replyTo = $this->getReplyTo($sender->getEMailAddress()); // send it out now try { @@ -192,7 +193,7 @@ public function sendInternalShareMail($sender, $node, $shareType, $recipientList $message->setHtmlBody($htmlBody); $message->setPlainBody($textBody); $message->setFrom($this->getFrom($this->l, $filter->getSenderDisplayName())); - $message->setReplyTo([$sender->getEMailAddress()]); + $message->setReplyTo([$replyTo]); $this->mailer->send($message); } catch (\Exception $e) { @@ -263,7 +264,7 @@ public function sendLinkShareMail($sender, $recipients, $link, $personalNote = n $l10n ); $from = $this->getFrom($l10n, $filter->getSenderDisplayName()); - $replyTo = $sender->getEMailAddress(); + $replyTo = $this->getReplyTo($sender->getEMailAddress()); $event = new GenericEvent(null, ['link' => $link, 'to' => $recipientsAsString]); $this->eventDispatcher->dispatch('share.sendmail', $event); @@ -403,4 +404,15 @@ protected function getFrom($l10n, $senderDisplayName) { ) ]; } + + /** + * @param string $senderMailAddress + * @return string + */ + protected function getReplyTo($senderMailAddress) { + if (empty($senderMailAddress)) { + return Util::getDefaultEmailAddress('sharing-noreply'); + } + return $senderMailAddress; + } } diff --git a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature index 266673d59091..c75ef7d34ad9 100644 --- a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature +++ b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature @@ -659,3 +659,21 @@ Feature: Sharing files and folders with internal users And the option to delete file "lorem.txt" should not be available on the webUI When the user shares file "lorem.txt" with user "User Three" using the webUI Then as "user3" file "lorem.txt" should exist + + @mailhog + Scenario: user without email should be able to send notification by email when allow share mail notification has been enabled + Given parameter "shareapi_allow_mail_notification" of app "core" has been set to "yes" + And these users have been created without skeleton files: + | username | password | + | user0 | 1234 | + And user "user1" has been created with default attributes and without skeleton files + And user "user0" has created folder "/simple-folder" + And user "user0" has logged in using the webUI + And user "user0" has shared folder "simple-folder" with user "user1" + And the user has opened the share dialog for folder "simple-folder" + When the user sends the share notification by email using the webUI + Then a notification should be displayed on the webUI with the text "Email notification was sent!" + And the email address "user1@example.org" should have received an email with the body containing + """ + just letting you know that user0 shared simple-folder with you. + """ diff --git a/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature b/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature index f74cf16b1403..d639f496b9ee 100644 --- a/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature +++ b/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature @@ -647,3 +647,19 @@ Feature: Share by public link And the public accesses the last created public link using the webUI Then the text preview of the public link should contain "original content" And all the links to download the public share should be the same + + @mailhog + Scenario: user without email shares a public link via email + Given these users have been created without skeleton files: + | username | password | + | user0 | 1234 | + And user "user0" has created folder "/simple-folder" + And parameter "shareapi_allow_public_notification" of app "core" has been set to "yes" + And user "user0" has logged in using the webUI + When the user creates a new public link for folder "simple-folder" using the webUI with + | email | foo@bar.co | + Then the email address "foo@bar.co" should have received an email with the body containing + """ + user0 shared simple-folder with you + """ + And the email address "foo@bar.co" should have received an email containing the last shared public link \ No newline at end of file