From 448ee8e30de63d6af679d2b43e198a87720e24fe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 8 Dec 2021 16:59:32 +0100 Subject: [PATCH] Only limit search in the system address book Signed-off-by: Joas Schilling --- .../Collaboration/Collaborators/MailPlugin.php | 3 ++- lib/private/ContactsManager.php | 16 ++++++++++++++-- lib/public/Contacts/IManager.php | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/private/Collaboration/Collaborators/MailPlugin.php b/lib/private/Collaboration/Collaborators/MailPlugin.php index 2f79a7977af..e6171f403b4 100644 --- a/lib/private/Collaboration/Collaborators/MailPlugin.php +++ b/lib/private/Collaboration/Collaborators/MailPlugin.php @@ -108,7 +108,8 @@ class MailPlugin implements ISearchPlugin { [ 'limit' => $limit, 'offset' => $offset, - 'wildcard' => $this->shareeEnumeration, + 'enumeration' => $this->shareeEnumeration, + 'fullmatch' => $this->shareeEnumerationFullMatch, ] ); $lowerSearch = strtolower($search); diff --git a/lib/private/ContactsManager.php b/lib/private/ContactsManager.php index 88256bcd88e..2751f221485 100644 --- a/lib/private/ContactsManager.php +++ b/lib/private/ContactsManager.php @@ -43,14 +43,26 @@ class ContactsManager implements IManager { * - 'escape_like_param' - If set to false wildcards _ and % are not escaped * - 'limit' - Set a numeric limit for the search results * - 'offset' - Set the offset for the limited search results - * - 'wildcard' - Whether the search should use wildcards + * - 'enumeration' - Whether user enumeration on system address book is allowed + * - 'fullmatch' - Whether matching on full detail in system address book is allowed * @return array an array of contacts which are arrays of key-value-pairs */ public function search($pattern, $searchProperties = [], $options = []) { $this->loadAddressBooks(); $result = []; foreach ($this->addressBooks as $addressBook) { - $r = $addressBook->search($pattern, $searchProperties, $options); + $searchOptions = $options; + + if ($addressBook->isSystemAddressBook()) { + $fullMatch = !\array_key_exists('fullmatch', $options) || $options['fullmatch'] !== false; + if (!$fullMatch) { + // Neither full match is allowed, so skip the system address book + continue; + } + $searchOptions['wildcard'] = !\array_key_exists('enumeration', $options) || $options['enumeration'] !== false; + } + + $r = $addressBook->search($pattern, $searchProperties, $searchOptions); $contacts = []; foreach ($r as $c) { $c['addressbook-key'] = $addressBook->getKey(); diff --git a/lib/public/Contacts/IManager.php b/lib/public/Contacts/IManager.php index 86b98b706d2..827c4f5724b 100644 --- a/lib/public/Contacts/IManager.php +++ b/lib/public/Contacts/IManager.php @@ -99,7 +99,8 @@ interface IManager { * - 'escape_like_param' - If set to false wildcards _ and % are not escaped * - 'limit' - Set a numeric limit for the search results * - 'offset' - Set the offset for the limited search results - * - 'wildcard' - Whether the search should use wildcards + * - 'enumeration' - Whether user enumeration on system address book is allowed + * - 'fullmatch' - Whether matching on full detail in system addresss book is allowed * @return array an array of contacts which are arrays of key-value-pairs * @since 6.0.0 */