Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow an alternative domain splitter for IMAP authentication #151

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 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,20 @@ 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 (($this->domainSplitter != $domainSplitterEncoded)
&& !(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