From 5df91c5740d437bb0c59f522f522bba9085d57d6 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Wed, 20 Jun 2018 20:33:14 +0545 Subject: [PATCH 1/2] return all failed recipients in sendLinkShareMailFromBody --- lib/private/Share/MailNotifications.php | 24 ++++++++++++-- tests/lib/Share/MailNotificationsTest.php | 38 +++++++++++++++++++++-- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/lib/private/Share/MailNotifications.php b/lib/private/Share/MailNotifications.php index e48cc4ad6702..d188ed63b175 100644 --- a/lib/private/Share/MailNotifications.php +++ b/lib/private/Share/MailNotifications.php @@ -253,8 +253,28 @@ public function sendLinkShareMailFromBody($recipient, $subject, $htmlBody, $text return $this->mailer->send($message); } catch (\Exception $e) { - $this->logger->error("Can't send mail with public link to $recipient: ".$e->getMessage(), ['app' => 'sharing']); - return [$recipient]; + $allRecipientsArr = []; + if ($recipient !== null && $recipient !== '') { + $allRecipientsArr = \explode(',', $recipient); + } + if (isset($options['cc']) && $options['cc'] !== '') { + $allRecipientsArr = \array_merge( + $allRecipientsArr, + \explode(',', $options['cc']) + ); + } + if (isset($options['bcc']) && $options['bcc'] !== '') { + $allRecipientsArr = \array_merge( + $allRecipientsArr, + \explode(',', $options['bcc']) + ); + } + $allRecipients = \implode(',', $allRecipientsArr); + $this->logger->error( + "Can't send mail with public link to $allRecipients: ".$e->getMessage(), + ['app' => 'sharing'] + ); + return [$allRecipients]; } } diff --git a/tests/lib/Share/MailNotificationsTest.php b/tests/lib/Share/MailNotificationsTest.php index 5be414e04d40..03645ccff000 100644 --- a/tests/lib/Share/MailNotificationsTest.php +++ b/tests/lib/Share/MailNotificationsTest.php @@ -331,8 +331,27 @@ public function testSendLinkShareMailWithReplyTo($to, array $expectedTo) { $this->assertSame([], $mailNotifications->sendLinkShareMail($to, 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600)); } - public function testSendLinkShareMailException() { - $this->setupMailerMock('TestUser shared »MyFile« with you', ['lukas@owncloud.com']); + public function dataSendLinkShareMailException() { + return [ + ['lukas@owncloud.com', '', '', 'lukas@owncloud.com'], + ['you@owncloud.com', 'cc1@example.com,cc2@example.com', '', 'you@owncloud.com,cc1@example.com,cc2@example.com'], + ['you@owncloud.com', '', 'phil@example.com,jim@example.com.np', 'you@owncloud.com,phil@example.com,jim@example.com.np'], + ['you@owncloud.com', 'cc1@example.com,cc2@example.com', 'phil@example.com,jim@example.com.np', 'you@owncloud.com,cc1@example.com,cc2@example.com,phil@example.com,jim@example.com.np'], + ['', 'cc1@example.com,cc2@example.com', '', 'cc1@example.com,cc2@example.com'], + ['', '', 'phil@example.com,jim@example.com.np', 'phil@example.com,jim@example.com.np'], + ['', 'cc1@example.com,cc2@example.com', 'phil@example.com,jim@example.com.np', 'cc1@example.com,cc2@example.com,phil@example.com,jim@example.com.np'], + ]; + } + + /** + * @dataProvider dataSendLinkShareMailException + * @param string $to + * @param string $cc + * @param string $bcc + * @param string $expectedRecipientErrorList + */ + public function testSendLinkShareMailException($to, $cc, $bcc, string $expectedRecipientErrorList) { + $this->setupMailerMock('TestUser shared »MyFile« with you', [$to]); $mailNotifications = new MailNotifications( $this->user, @@ -344,7 +363,20 @@ public function testSendLinkShareMailException() { $this->eventDispatcher ); - $this->assertSame(['lukas@owncloud.com'], $mailNotifications->sendLinkShareMail('lukas@owncloud.com', 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600)); + $options = []; + + if ($cc !== '') { + $options['cc'] = $cc; + } + + if ($bcc !== '') { + $options['bcc'] = $bcc; + } + + $this->assertSame( + [$expectedRecipientErrorList], + $mailNotifications->sendLinkShareMail($to, 'MyFile', 'https://owncloud.com/file/?foo=bar', 3600, null, $options) + ); } public function testSendInternalShareMail() { From 72ead41783355453d469f01c7f62b7af952c7a80 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 28 Jun 2018 17:48:42 +0545 Subject: [PATCH 2/2] Remove string parameter type from testSendLinkShareMailException parameter --- tests/lib/Share/MailNotificationsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/Share/MailNotificationsTest.php b/tests/lib/Share/MailNotificationsTest.php index 03645ccff000..d290c563f8ec 100644 --- a/tests/lib/Share/MailNotificationsTest.php +++ b/tests/lib/Share/MailNotificationsTest.php @@ -350,7 +350,7 @@ public function dataSendLinkShareMailException() { * @param string $bcc * @param string $expectedRecipientErrorList */ - public function testSendLinkShareMailException($to, $cc, $bcc, string $expectedRecipientErrorList) { + public function testSendLinkShareMailException($to, $cc, $bcc, $expectedRecipientErrorList) { $this->setupMailerMock('TestUser shared »MyFile« with you', [$to]); $mailNotifications = new MailNotifications(