From 893f10467019c22eb9939ecd446a191819f6401a Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 9 Apr 2018 10:31:04 +0200 Subject: [PATCH] Filter file name when sending internal mail --- lib/private/Share/MailNotifications.php | 11 ++++++++++- tests/lib/Share/MailNotificationsTest.php | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/private/Share/MailNotifications.php b/lib/private/Share/MailNotifications.php index 8f964c17a501..5a8a9ef7c5cf 100644 --- a/lib/private/Share/MailNotifications.php +++ b/lib/private/Share/MailNotifications.php @@ -37,6 +37,7 @@ use OCP\ILogger; use OCP\Defaults; use OCP\Util; +use OC\Share\Filters\MailNotificationFilter; /** * Class MailNotifications @@ -122,7 +123,6 @@ public function sendInternalShareMail($recipientList, $itemSource, $itemType) { $items = $this->getItemSharedWithUser($itemSource, $itemType, $recipient); $filename = trim($items[0]['file_target'], '/'); - $subject = (string) $this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $filename]); $expiration = null; if (isset($items[0]['expiration'])) { try { @@ -138,6 +138,15 @@ public function sendInternalShareMail($recipientList, $itemSource, $itemType) { ['fileId' => $items[0]['item_source']] ); + $filter = new MailNotificationFilter([ + 'link' => $link, + 'file' => $filename, + ]); + + $filename = $filter->getFile(); + $link = $filter->getLink(); + + $subject = (string) $this->l->t('%s shared »%s« with you', [$this->senderDisplayName, $filename]); list($htmlBody, $textBody) = $this->createMailBody($filename, $link, $expiration, null, 'internal'); // send it out now diff --git a/tests/lib/Share/MailNotificationsTest.php b/tests/lib/Share/MailNotificationsTest.php index ad6dc5efa4bd..3398090c327f 100644 --- a/tests/lib/Share/MailNotificationsTest.php +++ b/tests/lib/Share/MailNotificationsTest.php @@ -260,7 +260,7 @@ public function testSendLinkShareMailException() { } public function testSendInternalShareMail() { - $this->setupMailerMock('TestUser shared »welcome.txt« with you', ['recipient@owncloud.com' => 'Recipient'], false); + $this->setupMailerMock('TestUser shared »<welcome>.txt« with you', ['recipient@owncloud.com' => 'Recipient'], false); /** @var MailNotifications | \PHPUnit_Framework_MockObject_MockObject $mailNotifications */ $mailNotifications = $this->getMockBuilder('OC\Share\MailNotifications') @@ -278,7 +278,7 @@ public function testSendInternalShareMail() { $mailNotifications->method('getItemSharedWithUser') ->withAnyParameters() ->willReturn([ - ['file_target' => '/welcome.txt', 'item_source' => 123], + ['file_target' => '/.txt', 'item_source' => 123], ]); $recipient = $this->getMockBuilder('\OCP\IUser')