👌 IMPROVE: correctly pass all parameters

Signed-off-by: Jonas Sulzer <jonas@violoncello.ch>
This commit is contained in:
Jonas Sulzer
2019-03-13 18:46:46 +01:00
parent 9df4e318d6
commit 8685369c65

View File

@@ -19,19 +19,24 @@ use OCA\user_external\imap\imap_rcube;
*/ */
class OC_User_IMAP extends \OCA\user_external\Base { class OC_User_IMAP extends \OCA\user_external\Base {
private $mailbox; private $mailbox;
private $port;
private $sslmode;
private $domain; private $domain;
/** /**
* Create new IMAP authentication provider * Create new IMAP authentication provider
* *
* @param string $mailbox PHP imap_open mailbox definition, e.g. * @param string $mailbox IMAP server domain/IP
* {127.0.0.1:143/imap/readonly} * @param string $port IMAP server $port
* @param string $sslmode
* @param string $domain If provided, loging will be restricted to this domain * @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); parent::__construct($mailbox);
$this->mailbox=$mailbox; $this->mailbox = $mailbox;
$this->domain=$domain; $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 * @return true/false
*/ */
public function checkPassword($uid, $password) { 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) // 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 // but only if there is no @ symbol and if there is a %40 inside the uid
if (!(strpos($uid, '@') !== false) && (strpos($uid, '%40') !== false)) { 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(); $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); $params = ["port"=>$this->port, "timeout"=>10];
$imapErrors = imap_errors();
$imapAlerts = imap_alerts(); if ($this->sslmode !== null){
if (!empty($imapErrors)) { $params["ssl_mode"] = $this->sslmode;
OC::$server->getLogger()->error(
'ERROR: IMAP Error: ' . print_r($imapErrors, true),
['app' => 'user_external']
);
} }
if (!empty($imapAlerts)) { $canconnect = $rcube->connect(
OC::$server->getLogger()->warning( $this->mailbox,
'WARNING: IMAP Warning: ' . print_r($imapAlerts, true), $username,
['app' => 'user_external'] $password,
); $params
}*/ );
if($canconnect) { if($canconnect) {
$uid = mb_strtolower($uid); $uid = mb_strtolower($uid);