From 8685369c65c84d0a0fba7917353ce185358a1ad4 Mon Sep 17 00:00:00 2001 From: Jonas Sulzer Date: Wed, 13 Mar 2019 18:46:46 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20IMPROVE:=20correctly=20pass=20al?= =?UTF-8?q?l=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sulzer --- lib/imap.php | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/lib/imap.php b/lib/imap.php index 6e942f0..ae4a0ac 100644 --- a/lib/imap.php +++ b/lib/imap.php @@ -19,19 +19,24 @@ use OCA\user_external\imap\imap_rcube; */ class OC_User_IMAP extends \OCA\user_external\Base { private $mailbox; + private $port; + private $sslmode; 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 $mailbox IMAP server domain/IP + * @param string $port IMAP server $port + * @param string $sslmode * @param string $domain If provided, loging will be restricted to this domain */ - public function __construct($mailbox, $domain = '') { + public function __construct($mailbox, $port = null, $sslmode = null, $domain = null) { parent::__construct($mailbox); - $this->mailbox=$mailbox; - $this->domain=$domain; + $this->mailbox = $mailbox; + $this->port = $port === null ? 143 : $port; + $this->sslmode = $sslmode; + $this->domain= $domain === null ? '' : $domain; } /** @@ -43,11 +48,6 @@ class OC_User_IMAP extends \OCA\user_external\Base { * @return true/false */ public function checkPassword($uid, $password) { - if (!function_exists('imap_open')) { - OC::$server->getLogger()->error('ERROR: PHP imap extension is not installed', ['app' => 'user_external']); - return false; - } - // 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)) { @@ -69,23 +69,18 @@ class OC_User_IMAP extends \OCA\user_external\Base { } $rcube = new imap_rcube(); - $canconnect = $rcube->connect($this->mailbox, $username, $password, ["port"=>993, "ssl_mode"=>"tls", "timeout"=>10]); - /*$mbox = @imap_open($this->mailbox, $username, $password, OP_HALFOPEN, 1); - $imapErrors = imap_errors(); - $imapAlerts = imap_alerts(); - if (!empty($imapErrors)) { - OC::$server->getLogger()->error( - 'ERROR: IMAP Error: ' . print_r($imapErrors, true), - ['app' => 'user_external'] - ); + $params = ["port"=>$this->port, "timeout"=>10]; + + if ($this->sslmode !== null){ + $params["ssl_mode"] = $this->sslmode; } - if (!empty($imapAlerts)) { - OC::$server->getLogger()->warning( - 'WARNING: IMAP Warning: ' . print_r($imapAlerts, true), - ['app' => 'user_external'] - ); - }*/ + $canconnect = $rcube->connect( + $this->mailbox, + $username, + $password, + $params + ); if($canconnect) { $uid = mb_strtolower($uid);