Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ class ShareesAPIController extends OCSController {
'users' => [],
'groups' => [],
'remotes' => [],
'emails' => [],
],
'users' => [],
'groups' => [],
'remotes' => [],
'emails' => [],
];

protected $reachedEndFor = [];
Expand Down Expand Up @@ -402,6 +404,68 @@ protected function fixRemoteURL($remote) {
return $remote;
}

/**
* @param string $search
*/
protected function getEmails($search) {
$this->result['emails'] = [];
$this->result['exact']['emails'] = [];

$foundEmail = false;

// Search in contacts
//@todo Pagination missing
$addressBookContacts = $this->contactsManager->search($search, ['FN', 'EMAIL']);
foreach ($addressBookContacts as $contact) {
if (!isset($contact['EMAIL'])) {
continue;
}

$emails = $contact['EMAIL'];
if (!is_array($emails)) {
$emails = [$emails];
}

foreach ($emails as $email) {
if (strtolower($search) === strtolower($contact['FN']) ||
strtolower($search) === strtolower($email)
) {
if (strtolower($search) === strtolower($email)) {
$foundEmail = true;
}

$this->result['exact']['emails'][] = [
'label' => $contact['FN'],
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
'shareWith' => $email,
],
];
} else if ($this->shareeEnumeration) {
$this->result['emails'][] = [
'label' => $contact['FN'],
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
'shareWith' => $email,
],
];
}
}
}

if (!$foundEmail && substr_count($search, '@') >= 1 && $this->offset === 0) {
$this->result['exact']['emails'][] = [
'label' => $search,
'value' => [
'shareType' => Share::SHARE_TYPE_EMAIL,
'shareWith' => $search,
],
];
}

$this->reachedEndFor[] = 'emails';
}

/**
* @NoAdminRequired
*
Expand Down Expand Up @@ -429,6 +493,7 @@ public function search($search = '', $itemType = null, $page = 1, $perPage = 200
$shareTypes[] = Share::SHARE_TYPE_GROUP;
}

$shareTypes[] = Share::SHARE_TYPE_EMAIL;
$shareTypes[] = Share::SHARE_TYPE_REMOTE;

if (is_array($shareType)) {
Expand Down Expand Up @@ -499,6 +564,11 @@ protected function searchSharees($search, $itemType, array $shareTypes, $page, $
$this->getRemote($search);
}

// Get email
if (in_array(Share::SHARE_TYPE_EMAIL, $shareTypes)) {
$this->getEmails($search);
}

$response = new Http\DataResponse($this->result);

if (sizeof($this->reachedEndFor) < 3) {
Expand Down
Loading