Changeset View
Changeset View
Standalone View
Standalone View
src/app/Utils.php
Show First 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | public static function generatePassphrase() | ||||
} | } | ||||
return $result; | return $result; | ||||
} | } | ||||
/** | /** | ||||
* Find an object that is the recipient for the specified address. | * Find an object that is the recipient for the specified address. | ||||
* | * | ||||
* @param string $address | * @param string $address E-mail address | ||||
* | * | ||||
* @return array | * @return array<\App\User|\App\Resource|\App\SharedFolder> List of objects | ||||
*/ | */ | ||||
public static function findObjectsByRecipientAddress($address) | public static function findObjectsByRecipientAddress($address) | ||||
{ | { | ||||
$address = \App\Utils::normalizeAddress($address); | $address = \App\Utils::normalizeAddress($address); | ||||
if (strpos($address, '@') === false) { | |||||
return []; | |||||
} | |||||
list($local, $domainName) = explode('@', $address); | list($local, $domainName) = explode('@', $address); | ||||
$domain = \App\Domain::where('namespace', $domainName)->first(); | $domain = \App\Domain::where('namespace', $domainName)->first(); | ||||
if (!$domain) { | if (!$domain) { | ||||
return []; | return []; | ||||
} | } | ||||
// Find user/shared-folder/resource with specified address | |||||
// Note: Groups also have email address, but they aren't mailrecipients in LDAP | |||||
$user = \App\User::where('email', $address)->first(); | $user = \App\User::where('email', $address)->first(); | ||||
if ($user) { | if ($user) { | ||||
return [$user]; | return [$user]; | ||||
} | } | ||||
$userAliases = \App\UserAlias::where('alias', $address)->get(); | $folder = \App\SharedFolder::where('email', $address)->first(); | ||||
if ($folder) { | |||||
return [$folder]; | |||||
} | |||||
if (count($userAliases) > 0) { | $resource = \App\Resource::where('email', $address)->first(); | ||||
$users = []; | |||||
foreach ($userAliases as $userAlias) { | if ($resource) { | ||||
$users[] = $userAlias->user; | return [$resource]; | ||||
} | } | ||||
return $users; | // Find aliases with specified address | ||||
// TODO: Folders and users can have the same alias, should we merge the result (and return both)? | |||||
$users = \App\User::select('users.*') | |||||
->join('user_aliases', 'user_aliases.user_id', '=', 'users.id') | |||||
->where('alias', $address) | |||||
->get(); | |||||
if (count($users) > 0) { | |||||
return $users->all(); | |||||
} | |||||
$folders = \App\SharedFolder::select('shared_folders.*') | |||||
->join('shared_folder_aliases', 'shared_folder_aliases.shared_folder_id', '=', 'shared_folders.id') | |||||
->where('alias', $address) | |||||
->get(); | |||||
if (count($folders) > 0) { | |||||
return $folders->all(); | |||||
} | } | ||||
$userAliases = \App\UserAlias::where('alias', "catchall@{$domain->namespace}")->get(); | // Use catchall@ alias if exists | ||||
// TODO: Folders and users can have the same alias, should we merge the result (and return both)? | |||||
if (count($userAliases) > 0) { | $users = \App\User::select('users.*') | ||||
$users = []; | ->join('user_aliases', 'user_aliases.user_id', '=', 'users.id') | ||||
->where('alias', "catchall@{$domain->namespace}") | |||||
->get(); | |||||
foreach ($userAliases as $userAlias) { | if (count($users) > 0) { | ||||
$users[] = $userAlias->user; | return $users->all(); | ||||
} | } | ||||
return $users; | $folders = \App\SharedFolder::select('shared_folders.*') | ||||
->join('shared_folder_aliases', 'shared_folder_aliases.shared_folder_id', '=', 'shared_folders.id') | |||||
->where('alias', "catchall@{$domain->namespace}") | |||||
->get(); | |||||
if (count($folders) > 0) { | |||||
return $folders->all(); | |||||
} | } | ||||
return []; | return []; | ||||
} | } | ||||
/** | /** | ||||
* Retrieve the network ID and Type from a client address | * Retrieve the network ID and Type from a client address | ||||
* | * | ||||
▲ Show 20 Lines • Show All 345 Lines • Show Last 20 Lines |