From 624f064c695d2810e49eb2fde7cd7d3b7cf942fe Mon Sep 17 00:00:00 2001 From: Peter Vanpoucke Date: Sun, 24 May 2020 12:31:32 +0200 Subject: [PATCH 1/2] Add domainSplitter Signed-off-by: Peter Vanpoucke --- lib/imap.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/imap.php b/lib/imap.php index c48fba6..a88c15c 100644 --- a/lib/imap.php +++ b/lib/imap.php @@ -24,6 +24,7 @@ class OC_User_IMAP extends \OCA\user_external\Base { private $domain; private $stripeDomain; private $groupDomain; + private $domainSplitter; /** * Create new IMAP authentication provider @@ -34,8 +35,9 @@ class OC_User_IMAP extends \OCA\user_external\Base { * @param string $domain If provided, loging will be restricted to this domain * @param boolean $stripeDomain (whether to stripe the domain part from the username or not) * @param boolean $groupDomain (whether to add the usere to a group corresponding to the domain of the address) + * @param boolean $domainSplitter (consider this the domain splitter, default '@') */ - public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false) { + public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false, $domainSplitter = null) { parent::__construct($mailbox); $this->mailbox = $mailbox; $this->port = $port === null ? 143 : $port; @@ -43,6 +45,7 @@ public function __construct($mailbox, $port = null, $sslmode = null, $domain = n $this->domain = $domain === null ? '' : $domain; $this->stripeDomain = $stripeDomain; $this->groupDomain = $groupDomain; + $this->domainSplitter = $domainSplitter === null ? '@' : $domainSplitter; } /** @@ -54,16 +57,18 @@ public function __construct($mailbox, $port = null, $sslmode = null, $domain = n * @return true/false */ public function checkPassword($uid, $password) { - // Replace escaped @ symbol in uid (which is a mail address) - // but only if there is no @ symbol and if there is a %40 inside the uid - if (!(strpos($uid, '@') !== false) && (strpos($uid, '%40') !== false)) { - $uid = str_replace("%40","@",$uid); + $domainSplitterEncoded = urlencode($this->domainSplitter); + + // Replace escaped splitter in uid + // but only if there is no splitter symbol and if there is a escaped splitter inside the uid + if (!(strpos($uid, $this->domainSplitter) !== false) && (strpos($uid, $domainSplitterEncoded) !== false)) { + $uid = str_replace($domainSplitterEncoded,$this->domainSplitter,$uid); } - $pieces = explode('@', $uid); + $pieces = explode($this->domainSplitter, $uid); if ($this->domain !== '') { if (count($pieces) === 1) { - $username = $uid . '@' . $this->domain; + $username = $uid . $this->domainSplitter . $this->domain; } else if(count($pieces) === 2 && $pieces[1] === $this->domain) { $username = $uid; if ($this->stripeDomain) { From 96b712f9fcd73a5b2b1f1dbdfb55c31f6c2faed3 Mon Sep 17 00:00:00 2001 From: Peter Vanpoucke Date: Sun, 24 May 2020 15:38:23 +0200 Subject: [PATCH 2/2] Add domainSplitter: check if replace is still necessary Signed-off-by: Peter Vanpoucke --- lib/imap.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/imap.php b/lib/imap.php index a88c15c..42c490c 100644 --- a/lib/imap.php +++ b/lib/imap.php @@ -61,7 +61,9 @@ public function checkPassword($uid, $password) { // Replace escaped splitter in uid // but only if there is no splitter symbol and if there is a escaped splitter inside the uid - if (!(strpos($uid, $this->domainSplitter) !== false) && (strpos($uid, $domainSplitterEncoded) !== false)) { + if (($this->domainSplitter != $domainSplitterEncoded) + && !(strpos($uid, $this->domainSplitter) !== false) + && (strpos($uid, $domainSplitterEncoded) !== false)) { $uid = str_replace($domainSplitterEncoded,$this->domainSplitter,$uid); }