👌 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 {
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);