@@ -21,245 +21,245 @@ |
||
| 21 | 21 | use OCP\Share\IShare; |
| 22 | 22 | |
| 23 | 23 | class MailPlugin implements ISearchPlugin { |
| 24 | - protected bool $shareWithGroupOnly; |
|
| 25 | - |
|
| 26 | - protected bool $shareeEnumeration; |
|
| 27 | - |
|
| 28 | - protected bool $shareeEnumerationInGroupOnly; |
|
| 29 | - |
|
| 30 | - protected bool $shareeEnumerationPhone; |
|
| 31 | - |
|
| 32 | - protected bool $shareeEnumerationFullMatch; |
|
| 33 | - |
|
| 34 | - protected bool $shareeEnumerationFullMatchEmail; |
|
| 35 | - |
|
| 36 | - public function __construct( |
|
| 37 | - private IManager $contactsManager, |
|
| 38 | - private ICloudIdManager $cloudIdManager, |
|
| 39 | - private IConfig $config, |
|
| 40 | - private IGroupManager $groupManager, |
|
| 41 | - private KnownUserService $knownUserService, |
|
| 42 | - private IUserSession $userSession, |
|
| 43 | - private IEmailValidator $emailValidator, |
|
| 44 | - private mixed $shareWithGroupOnlyExcludeGroupsList = [], |
|
| 45 | - ) { |
|
| 46 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 47 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 48 | - $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 49 | - $this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
| 50 | - $this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; |
|
| 51 | - $this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes'; |
|
| 52 | - |
|
| 53 | - if ($this->shareWithGroupOnly) { |
|
| 54 | - $this->shareWithGroupOnlyExcludeGroupsList = json_decode($this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''), true) ?? []; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * {@inheritdoc} |
|
| 60 | - */ |
|
| 61 | - public function search($search, $limit, $offset, ISearchResult $searchResult): bool { |
|
| 62 | - if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) { |
|
| 63 | - return false; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // Extract the email address from "Foo Bar <[email protected]>" and then search with "[email protected]" instead |
|
| 67 | - $result = preg_match('/<([^@]+@.+)>$/', $search, $matches); |
|
| 68 | - if ($result && filter_var($matches[1], FILTER_VALIDATE_EMAIL)) { |
|
| 69 | - return $this->search($matches[1], $limit, $offset, $searchResult); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $currentUserId = $this->userSession->getUser()->getUID(); |
|
| 73 | - |
|
| 74 | - $result = $userResults = ['wide' => [], 'exact' => []]; |
|
| 75 | - $userType = new SearchResultType('users'); |
|
| 76 | - $emailType = new SearchResultType('emails'); |
|
| 77 | - |
|
| 78 | - // Search in contacts |
|
| 79 | - $addressBookContacts = $this->contactsManager->search( |
|
| 80 | - $search, |
|
| 81 | - ['EMAIL', 'FN'], |
|
| 82 | - [ |
|
| 83 | - 'limit' => $limit, |
|
| 84 | - 'offset' => $offset, |
|
| 85 | - 'enumeration' => $this->shareeEnumeration, |
|
| 86 | - 'fullmatch' => $this->shareeEnumerationFullMatch, |
|
| 87 | - ] |
|
| 88 | - ); |
|
| 89 | - $lowerSearch = strtolower($search); |
|
| 90 | - foreach ($addressBookContacts as $contact) { |
|
| 91 | - if (isset($contact['EMAIL'])) { |
|
| 92 | - $emailAddresses = $contact['EMAIL']; |
|
| 93 | - if (\is_string($emailAddresses)) { |
|
| 94 | - $emailAddresses = [$emailAddresses]; |
|
| 95 | - } |
|
| 96 | - foreach ($emailAddresses as $type => $emailAddress) { |
|
| 97 | - $displayName = $emailAddress; |
|
| 98 | - $emailAddressType = null; |
|
| 99 | - if (\is_array($emailAddress)) { |
|
| 100 | - $emailAddressData = $emailAddress; |
|
| 101 | - $emailAddress = $emailAddressData['value']; |
|
| 102 | - $emailAddressType = $emailAddressData['type']; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { |
|
| 106 | - continue; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if (isset($contact['FN'])) { |
|
| 110 | - $displayName = $contact['FN'] . ' (' . $emailAddress . ')'; |
|
| 111 | - } |
|
| 112 | - $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
|
| 113 | - |
|
| 114 | - if (isset($contact['isLocalSystemBook'])) { |
|
| 115 | - if ($this->shareWithGroupOnly) { |
|
| 116 | - /* |
|
| 24 | + protected bool $shareWithGroupOnly; |
|
| 25 | + |
|
| 26 | + protected bool $shareeEnumeration; |
|
| 27 | + |
|
| 28 | + protected bool $shareeEnumerationInGroupOnly; |
|
| 29 | + |
|
| 30 | + protected bool $shareeEnumerationPhone; |
|
| 31 | + |
|
| 32 | + protected bool $shareeEnumerationFullMatch; |
|
| 33 | + |
|
| 34 | + protected bool $shareeEnumerationFullMatchEmail; |
|
| 35 | + |
|
| 36 | + public function __construct( |
|
| 37 | + private IManager $contactsManager, |
|
| 38 | + private ICloudIdManager $cloudIdManager, |
|
| 39 | + private IConfig $config, |
|
| 40 | + private IGroupManager $groupManager, |
|
| 41 | + private KnownUserService $knownUserService, |
|
| 42 | + private IUserSession $userSession, |
|
| 43 | + private IEmailValidator $emailValidator, |
|
| 44 | + private mixed $shareWithGroupOnlyExcludeGroupsList = [], |
|
| 45 | + ) { |
|
| 46 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
| 47 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
| 48 | + $this->shareeEnumerationInGroupOnly = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes'; |
|
| 49 | + $this->shareeEnumerationPhone = $this->shareeEnumeration && $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes'; |
|
| 50 | + $this->shareeEnumerationFullMatch = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes'; |
|
| 51 | + $this->shareeEnumerationFullMatchEmail = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match_email', 'yes') === 'yes'; |
|
| 52 | + |
|
| 53 | + if ($this->shareWithGroupOnly) { |
|
| 54 | + $this->shareWithGroupOnlyExcludeGroupsList = json_decode($this->config->getAppValue('core', 'shareapi_only_share_with_group_members_exclude_group_list', ''), true) ?? []; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * {@inheritdoc} |
|
| 60 | + */ |
|
| 61 | + public function search($search, $limit, $offset, ISearchResult $searchResult): bool { |
|
| 62 | + if ($this->shareeEnumerationFullMatch && !$this->shareeEnumerationFullMatchEmail) { |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // Extract the email address from "Foo Bar <[email protected]>" and then search with "[email protected]" instead |
|
| 67 | + $result = preg_match('/<([^@]+@.+)>$/', $search, $matches); |
|
| 68 | + if ($result && filter_var($matches[1], FILTER_VALIDATE_EMAIL)) { |
|
| 69 | + return $this->search($matches[1], $limit, $offset, $searchResult); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $currentUserId = $this->userSession->getUser()->getUID(); |
|
| 73 | + |
|
| 74 | + $result = $userResults = ['wide' => [], 'exact' => []]; |
|
| 75 | + $userType = new SearchResultType('users'); |
|
| 76 | + $emailType = new SearchResultType('emails'); |
|
| 77 | + |
|
| 78 | + // Search in contacts |
|
| 79 | + $addressBookContacts = $this->contactsManager->search( |
|
| 80 | + $search, |
|
| 81 | + ['EMAIL', 'FN'], |
|
| 82 | + [ |
|
| 83 | + 'limit' => $limit, |
|
| 84 | + 'offset' => $offset, |
|
| 85 | + 'enumeration' => $this->shareeEnumeration, |
|
| 86 | + 'fullmatch' => $this->shareeEnumerationFullMatch, |
|
| 87 | + ] |
|
| 88 | + ); |
|
| 89 | + $lowerSearch = strtolower($search); |
|
| 90 | + foreach ($addressBookContacts as $contact) { |
|
| 91 | + if (isset($contact['EMAIL'])) { |
|
| 92 | + $emailAddresses = $contact['EMAIL']; |
|
| 93 | + if (\is_string($emailAddresses)) { |
|
| 94 | + $emailAddresses = [$emailAddresses]; |
|
| 95 | + } |
|
| 96 | + foreach ($emailAddresses as $type => $emailAddress) { |
|
| 97 | + $displayName = $emailAddress; |
|
| 98 | + $emailAddressType = null; |
|
| 99 | + if (\is_array($emailAddress)) { |
|
| 100 | + $emailAddressData = $emailAddress; |
|
| 101 | + $emailAddress = $emailAddressData['value']; |
|
| 102 | + $emailAddressType = $emailAddressData['type']; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + if (!filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) { |
|
| 106 | + continue; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if (isset($contact['FN'])) { |
|
| 110 | + $displayName = $contact['FN'] . ' (' . $emailAddress . ')'; |
|
| 111 | + } |
|
| 112 | + $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
|
| 113 | + |
|
| 114 | + if (isset($contact['isLocalSystemBook'])) { |
|
| 115 | + if ($this->shareWithGroupOnly) { |
|
| 116 | + /* |
|
| 117 | 117 | * Check if the user may share with the user associated with the e-mail of the just found contact |
| 118 | 118 | */ |
| 119 | - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
| 120 | - |
|
| 121 | - // ShareWithGroupOnly filtering |
|
| 122 | - $userGroups = array_diff($userGroups, $this->shareWithGroupOnlyExcludeGroupsList); |
|
| 123 | - |
|
| 124 | - $found = false; |
|
| 125 | - foreach ($userGroups as $userGroup) { |
|
| 126 | - if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) { |
|
| 127 | - $found = true; |
|
| 128 | - break; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (!$found) { |
|
| 132 | - continue; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if ($exactEmailMatch && $this->shareeEnumerationFullMatch) { |
|
| 136 | - try { |
|
| 137 | - $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0] ?? ''); |
|
| 138 | - } catch (\InvalidArgumentException $e) { |
|
| 139 | - continue; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) { |
|
| 143 | - $singleResult = [[ |
|
| 144 | - 'label' => $displayName, |
|
| 145 | - 'uuid' => $contact['UID'] ?? $emailAddress, |
|
| 146 | - 'name' => $contact['FN'] ?? $displayName, |
|
| 147 | - 'value' => [ |
|
| 148 | - 'shareType' => IShare::TYPE_USER, |
|
| 149 | - 'shareWith' => $cloud->getUser(), |
|
| 150 | - ], |
|
| 151 | - 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() |
|
| 152 | - |
|
| 153 | - ]]; |
|
| 154 | - $searchResult->addResultSet($userType, [], $singleResult); |
|
| 155 | - $searchResult->markExactIdMatch($emailType); |
|
| 156 | - } |
|
| 157 | - return false; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - if ($this->shareeEnumeration) { |
|
| 161 | - try { |
|
| 162 | - if (!isset($contact['CLOUD'])) { |
|
| 163 | - continue; |
|
| 164 | - } |
|
| 165 | - $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0] ?? ''); |
|
| 166 | - } catch (\InvalidArgumentException $e) { |
|
| 167 | - continue; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $addToWide = !($this->shareeEnumerationInGroupOnly || $this->shareeEnumerationPhone); |
|
| 171 | - if (!$addToWide && $this->shareeEnumerationPhone && $this->knownUserService->isKnownToUser($currentUserId, $contact['UID'])) { |
|
| 172 | - $addToWide = true; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if (!$addToWide && $this->shareeEnumerationInGroupOnly) { |
|
| 176 | - $addToWide = false; |
|
| 177 | - $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
| 178 | - foreach ($userGroups as $userGroup) { |
|
| 179 | - if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) { |
|
| 180 | - $addToWide = true; |
|
| 181 | - break; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - if ($addToWide && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) { |
|
| 186 | - $userResults['wide'][] = [ |
|
| 187 | - 'label' => $displayName, |
|
| 188 | - 'uuid' => $contact['UID'] ?? $emailAddress, |
|
| 189 | - 'name' => $contact['FN'] ?? $displayName, |
|
| 190 | - 'value' => [ |
|
| 191 | - 'shareType' => IShare::TYPE_USER, |
|
| 192 | - 'shareWith' => $cloud->getUser(), |
|
| 193 | - ], |
|
| 194 | - 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() |
|
| 195 | - ]; |
|
| 196 | - continue; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - continue; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($exactEmailMatch |
|
| 203 | - || (isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)) { |
|
| 204 | - if ($exactEmailMatch) { |
|
| 205 | - $searchResult->markExactIdMatch($emailType); |
|
| 206 | - } |
|
| 207 | - $result['exact'][] = [ |
|
| 208 | - 'label' => $displayName, |
|
| 209 | - 'uuid' => $contact['UID'] ?? $emailAddress, |
|
| 210 | - 'name' => $contact['FN'] ?? $displayName, |
|
| 211 | - 'type' => $emailAddressType ?? '', |
|
| 212 | - 'value' => [ |
|
| 213 | - 'shareType' => IShare::TYPE_EMAIL, |
|
| 214 | - 'shareWith' => $emailAddress, |
|
| 215 | - ], |
|
| 216 | - ]; |
|
| 217 | - } else { |
|
| 218 | - $result['wide'][] = [ |
|
| 219 | - 'label' => $displayName, |
|
| 220 | - 'uuid' => $contact['UID'] ?? $emailAddress, |
|
| 221 | - 'name' => $contact['FN'] ?? $displayName, |
|
| 222 | - 'type' => $emailAddressType ?? '', |
|
| 223 | - 'value' => [ |
|
| 224 | - 'shareType' => IShare::TYPE_EMAIL, |
|
| 225 | - 'shareWith' => $emailAddress, |
|
| 226 | - ], |
|
| 227 | - ]; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - $reachedEnd = true; |
|
| 234 | - if ($this->shareeEnumeration) { |
|
| 235 | - $reachedEnd = (count($result['wide']) < $offset + $limit) |
|
| 236 | - && (count($userResults['wide']) < $offset + $limit); |
|
| 237 | - |
|
| 238 | - $result['wide'] = array_slice($result['wide'], $offset, $limit); |
|
| 239 | - $userResults['wide'] = array_slice($userResults['wide'], $offset, $limit); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if (!$searchResult->hasExactIdMatch($emailType) && $this->emailValidator->isValid($search)) { |
|
| 243 | - $result['exact'][] = [ |
|
| 244 | - 'label' => $search, |
|
| 245 | - 'uuid' => $search, |
|
| 246 | - 'value' => [ |
|
| 247 | - 'shareType' => IShare::TYPE_EMAIL, |
|
| 248 | - 'shareWith' => $search, |
|
| 249 | - ], |
|
| 250 | - ]; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - if (!empty($userResults['wide'])) { |
|
| 254 | - $searchResult->addResultSet($userType, $userResults['wide'], []); |
|
| 255 | - } |
|
| 256 | - $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); |
|
| 257 | - |
|
| 258 | - return !$reachedEnd; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - public function isCurrentUser(ICloudId $cloud): bool { |
|
| 262 | - $currentUser = $this->userSession->getUser(); |
|
| 263 | - return $currentUser instanceof IUser && $currentUser->getUID() === $cloud->getUser(); |
|
| 264 | - } |
|
| 119 | + $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
| 120 | + |
|
| 121 | + // ShareWithGroupOnly filtering |
|
| 122 | + $userGroups = array_diff($userGroups, $this->shareWithGroupOnlyExcludeGroupsList); |
|
| 123 | + |
|
| 124 | + $found = false; |
|
| 125 | + foreach ($userGroups as $userGroup) { |
|
| 126 | + if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) { |
|
| 127 | + $found = true; |
|
| 128 | + break; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (!$found) { |
|
| 132 | + continue; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if ($exactEmailMatch && $this->shareeEnumerationFullMatch) { |
|
| 136 | + try { |
|
| 137 | + $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0] ?? ''); |
|
| 138 | + } catch (\InvalidArgumentException $e) { |
|
| 139 | + continue; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + if (!$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) { |
|
| 143 | + $singleResult = [[ |
|
| 144 | + 'label' => $displayName, |
|
| 145 | + 'uuid' => $contact['UID'] ?? $emailAddress, |
|
| 146 | + 'name' => $contact['FN'] ?? $displayName, |
|
| 147 | + 'value' => [ |
|
| 148 | + 'shareType' => IShare::TYPE_USER, |
|
| 149 | + 'shareWith' => $cloud->getUser(), |
|
| 150 | + ], |
|
| 151 | + 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() |
|
| 152 | + |
|
| 153 | + ]]; |
|
| 154 | + $searchResult->addResultSet($userType, [], $singleResult); |
|
| 155 | + $searchResult->markExactIdMatch($emailType); |
|
| 156 | + } |
|
| 157 | + return false; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + if ($this->shareeEnumeration) { |
|
| 161 | + try { |
|
| 162 | + if (!isset($contact['CLOUD'])) { |
|
| 163 | + continue; |
|
| 164 | + } |
|
| 165 | + $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0] ?? ''); |
|
| 166 | + } catch (\InvalidArgumentException $e) { |
|
| 167 | + continue; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $addToWide = !($this->shareeEnumerationInGroupOnly || $this->shareeEnumerationPhone); |
|
| 171 | + if (!$addToWide && $this->shareeEnumerationPhone && $this->knownUserService->isKnownToUser($currentUserId, $contact['UID'])) { |
|
| 172 | + $addToWide = true; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if (!$addToWide && $this->shareeEnumerationInGroupOnly) { |
|
| 176 | + $addToWide = false; |
|
| 177 | + $userGroups = $this->groupManager->getUserGroupIds($this->userSession->getUser()); |
|
| 178 | + foreach ($userGroups as $userGroup) { |
|
| 179 | + if ($this->groupManager->isInGroup($contact['UID'], $userGroup)) { |
|
| 180 | + $addToWide = true; |
|
| 181 | + break; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + if ($addToWide && !$this->isCurrentUser($cloud) && !$searchResult->hasResult($userType, $cloud->getUser())) { |
|
| 186 | + $userResults['wide'][] = [ |
|
| 187 | + 'label' => $displayName, |
|
| 188 | + 'uuid' => $contact['UID'] ?? $emailAddress, |
|
| 189 | + 'name' => $contact['FN'] ?? $displayName, |
|
| 190 | + 'value' => [ |
|
| 191 | + 'shareType' => IShare::TYPE_USER, |
|
| 192 | + 'shareWith' => $cloud->getUser(), |
|
| 193 | + ], |
|
| 194 | + 'shareWithDisplayNameUnique' => !empty($emailAddress) ? $emailAddress : $cloud->getUser() |
|
| 195 | + ]; |
|
| 196 | + continue; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + continue; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($exactEmailMatch |
|
| 203 | + || (isset($contact['FN']) && strtolower($contact['FN']) === $lowerSearch)) { |
|
| 204 | + if ($exactEmailMatch) { |
|
| 205 | + $searchResult->markExactIdMatch($emailType); |
|
| 206 | + } |
|
| 207 | + $result['exact'][] = [ |
|
| 208 | + 'label' => $displayName, |
|
| 209 | + 'uuid' => $contact['UID'] ?? $emailAddress, |
|
| 210 | + 'name' => $contact['FN'] ?? $displayName, |
|
| 211 | + 'type' => $emailAddressType ?? '', |
|
| 212 | + 'value' => [ |
|
| 213 | + 'shareType' => IShare::TYPE_EMAIL, |
|
| 214 | + 'shareWith' => $emailAddress, |
|
| 215 | + ], |
|
| 216 | + ]; |
|
| 217 | + } else { |
|
| 218 | + $result['wide'][] = [ |
|
| 219 | + 'label' => $displayName, |
|
| 220 | + 'uuid' => $contact['UID'] ?? $emailAddress, |
|
| 221 | + 'name' => $contact['FN'] ?? $displayName, |
|
| 222 | + 'type' => $emailAddressType ?? '', |
|
| 223 | + 'value' => [ |
|
| 224 | + 'shareType' => IShare::TYPE_EMAIL, |
|
| 225 | + 'shareWith' => $emailAddress, |
|
| 226 | + ], |
|
| 227 | + ]; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + $reachedEnd = true; |
|
| 234 | + if ($this->shareeEnumeration) { |
|
| 235 | + $reachedEnd = (count($result['wide']) < $offset + $limit) |
|
| 236 | + && (count($userResults['wide']) < $offset + $limit); |
|
| 237 | + |
|
| 238 | + $result['wide'] = array_slice($result['wide'], $offset, $limit); |
|
| 239 | + $userResults['wide'] = array_slice($userResults['wide'], $offset, $limit); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if (!$searchResult->hasExactIdMatch($emailType) && $this->emailValidator->isValid($search)) { |
|
| 243 | + $result['exact'][] = [ |
|
| 244 | + 'label' => $search, |
|
| 245 | + 'uuid' => $search, |
|
| 246 | + 'value' => [ |
|
| 247 | + 'shareType' => IShare::TYPE_EMAIL, |
|
| 248 | + 'shareWith' => $search, |
|
| 249 | + ], |
|
| 250 | + ]; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + if (!empty($userResults['wide'])) { |
|
| 254 | + $searchResult->addResultSet($userType, $userResults['wide'], []); |
|
| 255 | + } |
|
| 256 | + $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); |
|
| 257 | + |
|
| 258 | + return !$reachedEnd; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + public function isCurrentUser(ICloudId $cloud): bool { |
|
| 262 | + $currentUser = $this->userSession->getUser(); |
|
| 263 | + return $currentUser instanceof IUser && $currentUser->getUID() === $cloud->getUser(); |
|
| 264 | + } |
|
| 265 | 265 | } |