Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/apps.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKoS <github.com@koks.li>2016-10-23 20:25:44 +0300
committerGitHub <noreply@github.com>2016-10-23 20:25:44 +0300
commit4aadfd75c82b4ad33aa26953c18c3694d52a15b6 (patch)
tree8e51ed59c5938f643e2daf93fae0ad252f4d027c /user_external
parente36c5c8f2604c45045863147f0639cadb239d48a (diff)
IMAP login can be restricted to a specific domain name.
Diffstat (limited to 'user_external')
-rw-r--r--user_external/lib/imap.php23
1 files changed, 21 insertions, 2 deletions
diff --git a/user_external/lib/imap.php b/user_external/lib/imap.php
index 3ccebf094..4c5c57a78 100644
--- a/user_external/lib/imap.php
+++ b/user_external/lib/imap.php
@@ -17,16 +17,19 @@
*/
class OC_User_IMAP extends \OCA\user_external\Base {
private $mailbox;
+ private $domain;
/**
* Create new IMAP authentication provider
*
* @param string $mailbox PHP imap_open mailbox definition, e.g.
* {127.0.0.1:143/imap/readonly}
+ * @param string $domain If provided, loging will be restricted to this domain
*/
- public function __construct($mailbox) {
+ public function __construct($mailbox, $domain = '') {
parent::__construct($mailbox);
$this->mailbox=$mailbox;
+ $this->domain=$domain;
}
/**
@@ -42,7 +45,23 @@ class OC_User_IMAP extends \OCA\user_external\Base {
OCP\Util::writeLog('user_external', 'ERROR: PHP imap extension is not installed', OCP\Util::ERROR);
return false;
}
- $mbox = @imap_open($this->mailbox, $uid, $password, OP_HALFOPEN, 1);
+
+ // Check if we only want logins from ONE domain and strip the domain part from UID
+ if($this->domain != '') {
+ $pieces = explode('@', $uid);
+ if(count($pieces) == 1) {
+ $username = $uid . "@" . $this->domain;
+ }elseif((count($pieces) == 2) and ($pieces[1] == $this->domain)) {
+ $username = $uid;
+ $uid = $pieces[0];
+ }else{
+ return false;
+ }
+ }else{
+ $username = $uid;
+ }
+
+ $mbox = @imap_open($this->mailbox, $username, $password, OP_HALFOPEN, 1);
imap_errors();
imap_alerts();
if($mbox !== FALSE) {