Skip to content

Commit

Permalink
Merge pull request #36505 from owncloud/sender-email-validation-fix
Browse files Browse the repository at this point in the history
[For 10.4] Add validation for sender email address
  • Loading branch information
phil-davis authored Dec 5, 2019
2 parents 471637d + aa63dc0 commit 9fae369
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/36505
Original file line number Diff line number Diff line change
@@ -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
16 changes: 14 additions & 2 deletions lib/private/Share/MailNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public function sendInternalShareMail($sender, $node, $shareType, $recipientList
'internal',
$recipientL10N
);
$replyTo = $this->getReplyTo($sender->getEMailAddress());

// send it out now
try {
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]" should have received an email with the body containing
"""
just letting you know that user0 shared simple-folder with you.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]" should have received an email with the body containing
"""
user0 shared simple-folder with you
"""
And the email address "[email protected]" should have received an email containing the last shared public link

0 comments on commit 9fae369

Please sign in to comment.