From 53adfebee2f3f1765c6e22b90c963706962d672c Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Sun, 14 Apr 2019 11:56:19 -0100 Subject: [PATCH] add multiples mails Signed-off-by: Maxence Lange --- lib/Service/MembersService.php | 36 ++++++++++++++++++++++++++++++---- lib/Service/MiscService.php | 11 ++++++----- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/lib/Service/MembersService.php b/lib/Service/MembersService.php index 836eafcf..86431b00 100644 --- a/lib/Service/MembersService.php +++ b/lib/Service/MembersService.php @@ -180,6 +180,10 @@ class MembersService { return $this->addGroupMembers($circle, $ident); } + if ($type === Member::TYPE_USER) { + return $this->addMassiveMails($circle, $ident); + } + return false; } @@ -320,9 +324,8 @@ class MembersService { } $tmpContact = $this->userId . ':' . $ident; - try { - MiscService::getContactData($tmpContact); - } catch (Exception $e) { + $result = MiscService::getContactData($tmpContact); + if (empty($result)) { throw new NoUserException($this->l10n->t("This contact is not available")); } @@ -358,6 +361,31 @@ class MembersService { } + /** + * @param Circle $circle + * @param string $mails + * + * @return bool + */ + private function addMassiveMails(Circle $circle, $mails) { + + foreach (explode(' ', trim($mails)) as $mail) { + if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) { + return false; + } + } + + foreach (explode(' ', trim($mails)) as $mail) { + try { + $this->addMember($circle->getUniqueId(), $mail, Member::TYPE_MAIL); + } catch (Exception $e) { + } + } + + return true; + } + + /** * getMember(); * @@ -543,4 +571,4 @@ class MembersService { } -} \ No newline at end of file +} diff --git a/lib/Service/MiscService.php b/lib/Service/MiscService.php index 4a09d8a8..947a9427 100644 --- a/lib/Service/MiscService.php +++ b/lib/Service/MiscService.php @@ -141,6 +141,7 @@ class MiscService { } $user = array_shift($result); + return $user->getUID(); } @@ -200,12 +201,12 @@ class MiscService { * @return mixed|string */ public static function getContactData($ident) { - list($userId, $contactId) = explode(':', $ident); - - if (!class_exists(\OCA\DAV\AppInfo\Application::class)) { - return null; + if (!class_exists(\OCA\DAV\AppInfo\Application::class) || !strpos(':', $ident)) { + return []; } + list($userId, $contactId) = explode(':', $ident); + try { /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ $contactApp = new \OCA\DAV\AppInfo\Application(); @@ -217,7 +218,7 @@ class MiscService { } catch (Exception $e) { } - return null; + return []; }