Skip to content

Commit a08575c

Browse files
susnuxAltahrim
andcommitted
fix(Collaboration): Allow to enforce strict email format on sharees API
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` Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Co-authored-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 576e249 commit a08575c

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

lib/private/Collaboration/Collaborators/MailPlugin.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
*/
2727
namespace OC\Collaboration\Collaborators;
2828

29+
use Egulias\EmailValidator\EmailValidator;
30+
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
31+
use Egulias\EmailValidator\Validation\RFCValidation;
2932
use OC\KnownUser\KnownUserService;
3033
use OCP\Collaboration\Collaborators\ISearchPlugin;
3134
use OCP\Collaboration\Collaborators\ISearchResult;
@@ -251,15 +254,21 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
251254
$userResults['wide'] = array_slice($userResults['wide'], $offset, $limit);
252255
}
253256

254-
if (!$searchResult->hasExactIdMatch($emailType) && $this->mailer->validateMailAddress($search)) {
255-
$result['exact'][] = [
256-
'label' => $search,
257-
'uuid' => $search,
258-
'value' => [
259-
'shareType' => IShare::TYPE_EMAIL,
260-
'shareWith' => $search,
261-
],
262-
];
257+
if ($search && !$searchResult->hasExactIdMatch($emailType)) {
258+
$strictMailCheck = $this->config->getAppValue('core', 'shareapi_enforce_strict_email', 'yes') === 'yes';
259+
$validator = new EmailValidator();
260+
$validation = $strictMailCheck ? new RFCValidation() : new NoRFCWarningsValidation();
261+
262+
if ($validator->isValid($search, $validation)) {
263+
$result['exact'][] = [
264+
'label' => $search,
265+
'uuid' => $search,
266+
'value' => [
267+
'shareType' => IShare::TYPE_EMAIL,
268+
'shareWith' => $search,
269+
],
270+
];
271+
}
263272
}
264273

265274
if (!empty($userResults['wide'])) {

0 commit comments

Comments
 (0)