Skip to content

Commit

Permalink
Add domainSplitter
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Vanpoucke <[email protected]>
  • Loading branch information
Peter Vanpoucke authored and peter-vanpoucke committed May 24, 2020
1 parent 24c9ad5 commit 624f064
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/imap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,15 +35,17 @@ 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;
$this->sslmode = $sslmode;
$this->domain = $domain === null ? '' : $domain;
$this->stripeDomain = $stripeDomain;
$this->groupDomain = $groupDomain;
$this->domainSplitter = $domainSplitter === null ? '@' : $domainSplitter;
}

/**
Expand All @@ -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) {
Expand Down

0 comments on commit 624f064

Please sign in to comment.