Replace imap_rcube library with curl call

This commit removes the imap_rcube library with a curl call to the imap endpoint.
Since curl is a dependency of nextcloud this should not cause any issues.

This closes #116

Signed-off-by: Tim Wichmann <tim@wichmann.online>
This commit is contained in:
Tim Wichmann
2020-01-23 15:54:20 +01:00
parent f5629eb367
commit 8d48ce91a7
3 changed files with 12 additions and 4153 deletions

View File

@@ -8,8 +8,6 @@
* See the COPYING-README file.
*/
use OCA\user_external\imap\imap_rcube;
/**
* User authentication against an IMAP mail server
*
@@ -87,31 +85,30 @@ class OC_User_IMAP extends \OCA\user_external\Base {
$groups[] = $pieces[1];
}
$rcube = new imap_rcube();
$protocol = $this->sslmode ? "imaps" : "imap";
$url = "{$protocol}://{$this->mailbox}:{$this->port}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$params = ["port"=>$this->port, "timeout"=>10];
$params["ssl_mode"] = $this->sslmode ? $this->sslmode : null;
$params["force_caps"] = false;
$canconnect = $rcube->connect(
$this->mailbox,
$username,
$password,
$params
);
$canconnect = curl_exec($ch);
if($canconnect) {
$rcube->closeConnection();
curl_close($ch);
$uid = mb_strtolower($uid);
$this->storeUser($uid, $groups);
return $uid;
} else {
OC::$server->getLogger()->error(
'ERROR: Could not connect via roundcube lib: '.$rcube->error,
'ERROR: Could not connect to imap server via curl: '.curl_error($ch),
['app' => 'user_external']
);
}
curl_close($ch);
return false;
}
}