Skip to content

Commit 624f064

Browse files
Peter Vanpouckepeter-vanpoucke
authored andcommitted
Add domainSplitter
Signed-off-by: Peter Vanpoucke <peter.vanpoucke@rw3.be>
1 parent 24c9ad5 commit 624f064

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

lib/imap.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class OC_User_IMAP extends \OCA\user_external\Base {
2424
private $domain;
2525
private $stripeDomain;
2626
private $groupDomain;
27+
private $domainSplitter;
2728

2829
/**
2930
* Create new IMAP authentication provider
@@ -34,15 +35,17 @@ class OC_User_IMAP extends \OCA\user_external\Base {
3435
* @param string $domain If provided, loging will be restricted to this domain
3536
* @param boolean $stripeDomain (whether to stripe the domain part from the username or not)
3637
* @param boolean $groupDomain (whether to add the usere to a group corresponding to the domain of the address)
38+
* @param boolean $domainSplitter (consider this the domain splitter, default '@')
3739
*/
38-
public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false) {
40+
public function __construct($mailbox, $port = null, $sslmode = null, $domain = null, $stripeDomain = true, $groupDomain = false, $domainSplitter = null) {
3941
parent::__construct($mailbox);
4042
$this->mailbox = $mailbox;
4143
$this->port = $port === null ? 143 : $port;
4244
$this->sslmode = $sslmode;
4345
$this->domain = $domain === null ? '' : $domain;
4446
$this->stripeDomain = $stripeDomain;
4547
$this->groupDomain = $groupDomain;
48+
$this->domainSplitter = $domainSplitter === null ? '@' : $domainSplitter;
4649
}
4750

4851
/**
@@ -54,16 +57,18 @@ public function __construct($mailbox, $port = null, $sslmode = null, $domain = n
5457
* @return true/false
5558
*/
5659
public function checkPassword($uid, $password) {
57-
// Replace escaped @ symbol in uid (which is a mail address)
58-
// but only if there is no @ symbol and if there is a %40 inside the uid
59-
if (!(strpos($uid, '@') !== false) && (strpos($uid, '%40') !== false)) {
60-
$uid = str_replace("%40","@",$uid);
60+
$domainSplitterEncoded = urlencode($this->domainSplitter);
61+
62+
// Replace escaped splitter in uid
63+
// but only if there is no splitter symbol and if there is a escaped splitter inside the uid
64+
if (!(strpos($uid, $this->domainSplitter) !== false) && (strpos($uid, $domainSplitterEncoded) !== false)) {
65+
$uid = str_replace($domainSplitterEncoded,$this->domainSplitter,$uid);
6166
}
6267

63-
$pieces = explode('@', $uid);
68+
$pieces = explode($this->domainSplitter, $uid);
6469
if ($this->domain !== '') {
6570
if (count($pieces) === 1) {
66-
$username = $uid . '@' . $this->domain;
71+
$username = $uid . $this->domainSplitter . $this->domain;
6772
} else if(count($pieces) === 2 && $pieces[1] === $this->domain) {
6873
$username = $uid;
6974
if ($this->stripeDomain) {

0 commit comments

Comments
 (0)