diff options
author | Carl Schwan <carl@carlschwan.eu> | 2022-01-13 09:24:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-13 09:24:26 +0100 |
commit | b1048864f0f8e4218a512b05c6a3a62ba4f6d565 (patch) | |
tree | 680620cd6d0762ba554261eb9b287cf754c4224b /apps/sharebymail | |
parent | 094fbb9c0db38b40d73dcf776a31f0f639f83085 (diff) | |
parent | fffc19f5c3e2e1789564542f3562a7b56b587c8c (diff) | |
download | nextcloud-server-b1048864f0f8e4218a512b05c6a3a62ba4f6d565.tar.gz nextcloud-server-b1048864f0f8e4218a512b05c6a3a62ba4f6d565.zip |
Merge pull request #30600 from nextcloud/fix/30595/idn-email-share
Fix idn emails not working in shares
Diffstat (limited to 'apps/sharebymail')
-rw-r--r-- | apps/sharebymail/lib/ShareByMailProvider.php | 18 | ||||
-rw-r--r-- | apps/sharebymail/tests/ShareByMailProviderTest.php | 6 |
2 files changed, 19 insertions, 5 deletions
diff --git a/apps/sharebymail/lib/ShareByMailProvider.php b/apps/sharebymail/lib/ShareByMailProvider.php index 62ba9d35f3f..c1438c01125 100644 --- a/apps/sharebymail/lib/ShareByMailProvider.php +++ b/apps/sharebymail/lib/ShareByMailProvider.php @@ -334,6 +334,16 @@ class ShareByMailProvider implements IShareProvider { $share->getNote() ); + if (!$this->mailer->validateMailAddress($share->getSharedWith())) { + $this->removeShareFromTable($shareId); + $e = new HintException('Failed to send share by mail. Got an invalid email address: ' . $share->getSharedWith(), + $this->l->t('Failed to send share by email. Got an invalid email address')); + $this->logger->error('Failed to send share by mail. Got an invalid email address ' . $share->getSharedWith(), [ + 'app' => 'sharebymail', + 'exception' => $e, + ]); + } + try { $link = $this->urlGenerator->linkToRouteAbsolute('files_sharing.sharecontroller.showShare', ['token' => $share->getToken()]); @@ -679,7 +689,7 @@ class ShareByMailProvider implements IShareProvider { * @param \DateTime|null $expirationTime * @return int */ - protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload, $label, $expirationTime, $note = '') { + protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload, $label, $expirationTime, $note = ''): int { $qb = $this->dbConnection->getQueryBuilder(); $qb->insert('share') ->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_EMAIL)) @@ -774,7 +784,7 @@ class ShareByMailProvider implements IShareProvider { } catch (\Exception $e) { } - $this->removeShareFromTable($share->getId()); + $this->removeShareFromTable((int)$share->getId()); } /** @@ -970,9 +980,9 @@ class ShareByMailProvider implements IShareProvider { /** * remove share from table * - * @param string $shareId + * @param int $shareId */ - protected function removeShareFromTable($shareId) { + protected function removeShareFromTable(int $shareId): void { $qb = $this->dbConnection->getQueryBuilder(); $qb->delete('share') ->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId))); diff --git a/apps/sharebymail/tests/ShareByMailProviderTest.php b/apps/sharebymail/tests/ShareByMailProviderTest.php index bbe5516408d..af2d5bad57c 100644 --- a/apps/sharebymail/tests/ShareByMailProviderTest.php +++ b/apps/sharebymail/tests/ShareByMailProviderTest.php @@ -217,7 +217,7 @@ class ShareByMailProviderTest extends TestCase { public function testCreateSendPasswordByMailWithoutEnforcedPasswordProtection() { $share = $this->getMockBuilder(IShare::class)->getMock(); - $share->expects($this->any())->method('getSharedWith')->willReturn('receiver@example.com'); + $share->expects($this->any())->method('getSharedWith')->willReturn('receiver@examplelölöl.com'); $share->expects($this->any())->method('getSendPasswordByTalk')->willReturn(false); $share->expects($this->any())->method('getSharedBy')->willReturn('owner'); @@ -459,6 +459,7 @@ class ShareByMailProviderTest extends TestCase { public function testCreateMailShare() { $this->share->expects($this->any())->method('getToken')->willReturn('token'); $this->share->expects($this->once())->method('setToken')->with('token'); + $this->share->expects($this->any())->method('getSharedWith')->willReturn('valid@valid.com'); $node = $this->getMockBuilder('OCP\Files\Node')->getMock(); $node->expects($this->any())->method('getName')->willReturn('fileName'); $this->share->expects($this->any())->method('getNode')->willReturn($node); @@ -483,6 +484,7 @@ class ShareByMailProviderTest extends TestCase { $this->share->expects($this->any())->method('getToken')->willReturn('token'); $this->share->expects($this->once())->method('setToken')->with('token'); + $this->share->expects($this->any())->method('getSharedWith')->willReturn('valid@valid.com'); $node = $this->getMockBuilder('OCP\Files\Node')->getMock(); $node->expects($this->any())->method('getName')->willReturn('fileName'); $this->share->expects($this->any())->method('getNode')->willReturn($node); @@ -987,6 +989,7 @@ class ShareByMailProviderTest extends TestCase { ->willReturn(new \OC\Share20\Share($rootFolder, $userManager)); $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); $u1 = $userManager->createUser('testFed', md5(time())); $u2 = $userManager->createUser('testFed2', md5(time())); @@ -1033,6 +1036,7 @@ class ShareByMailProviderTest extends TestCase { ->willReturn(new \OC\Share20\Share($rootFolder, $userManager)); $provider = $this->getInstance(['sendMailNotification', 'createShareActivity']); + $this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true); $u1 = $userManager->createUser('testFed', md5(time())); $u2 = $userManager->createUser('testFed2', md5(time())); |