Skip to content

Commit

Permalink
fix(Collaboration): Allow to enforce strict email format on sharees API
Browse files Browse the repository at this point in the history
Only recommend a email address as sharee if it satisfies the strict format checking.
Meaning before `a@b` was valid, while now with strict checking it is invalid and needs
to be at least `a@b.c`

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed May 21, 2024
1 parent 5a6e48e commit 1070d96
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/private/Collaboration/Collaborators/MailPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
*/
namespace OC\Collaboration\Collaborators;

use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
use Egulias\EmailValidator\Validation\RFCValidation;
use OC\KnownUser\KnownUserService;
use OCP\Collaboration\Collaborators\ISearchPlugin;
use OCP\Collaboration\Collaborators\ISearchResult;
Expand Down Expand Up @@ -251,7 +254,15 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
$userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
}

if (!$searchResult->hasExactIdMatch($emailType) && $this->mailer->validateMailAddress($search)) {
if ($search && !$searchResult->hasExactIdMatch($emailType)) {
$strictMailCheck = $this->config->getAppValue('core', 'shareapi_enforce_strict_email', 'yes') === 'yes';
$validator = new EmailValidator();
$validation = match ($strictMailCheck) {
false => new RFCValidation(),
true => new NoRFCWarningsValidation(),
};

if ($validator->isValid($search, $validation))
$result['exact'][] = [
'label' => $search,
'uuid' => $search,
Expand Down

0 comments on commit 1070d96

Please sign in to comment.