diff --git a/lib/private/Collaboration/Collaborators/RemotePlugin.php b/lib/private/Collaboration/Collaborators/RemotePlugin.php index 828ec984148..99e23d471e0 100644 --- a/lib/private/Collaboration/Collaborators/RemotePlugin.php +++ b/lib/private/Collaboration/Collaborators/RemotePlugin.php @@ -42,7 +42,7 @@ class RemotePlugin implements ISearchPlugin { $resultType = new SearchResultType('remotes'); // Search in contacts - $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], [ + $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN', 'EMAIL'], [ 'limit' => $limit, 'offset' => $offset, 'enumeration' => false, @@ -84,7 +84,17 @@ class RemotePlugin implements ISearchPlugin { ]; } - if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { + $emailMatch = false; + if (isset($contact['EMAIL'])) { + $emails = is_array($contact['EMAIL']) ? $contact['EMAIL'] : [$contact['EMAIL']]; + foreach ($emails as $email) { + if (is_string($email) && strtolower($email) === $lowerSearch) { + $emailMatch = true; + break; + } + } + } + if ($emailMatch || strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) { if (strtolower($cloudId) === $lowerSearch) { $searchResult->markExactIdMatch($resultType); } diff --git a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php index 2d2f2743677..06196d15d09 100644 --- a/tests/lib/Collaboration/Collaborators/RemotePluginTest.php +++ b/tests/lib/Collaboration/Collaborators/RemotePluginTest.php @@ -180,6 +180,46 @@ class RemotePluginTest extends TestCase { $this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']); } + public function testEmailSearchInContacts(): void { + $this->config->expects($this->any()) + ->method('getAppValue') + ->willReturnCallback( + function ($appName, $key, $default) { + if ($appName === 'core' && $key === 'shareapi_allow_share_dialog_user_enumeration') { + return 'yes'; + } + return $default; + } + ); + + $this->trustedServers->expects($this->any()) + ->method('isTrustedServer') + ->willReturnCallback(function ($serverUrl) { + return $serverUrl === 'trustedserver.com'; + }); + + $this->instantiatePlugin(); + + $this->contactsManager->expects($this->once()) + ->method('search') + ->with('john@gmail.com', ['CLOUD', 'FN', 'EMAIL']) + ->willReturn([ + [ + 'FN' => 'John Doe', + 'EMAIL' => 'john@gmail.com', + 'CLOUD' => 'john@trustedserver.com', + 'UID' => 'john-contact-id' + ] + ]); + + $this->plugin->search('john@gmail.com', 2, 0, $this->searchResult); + $result = $this->searchResult->asArray(); + + $this->assertNotEmpty($result['exact']['remotes']); + $this->assertEquals('john@trustedserver.com', $result['exact']['remotes'][0]['value']['shareWith']); + $this->assertTrue($result['exact']['remotes'][0]['value']['isTrustedServer']); + } + public static function dataGetRemote() { return [ ['test', [], true, ['remotes' => [], 'exact' => ['remotes' => []]], false, true],