From 5f11d68ee7cd4cec187a843bdc3b23b0acce0856 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Thu, 16 Sep 2021 09:34:42 +0200 Subject: [PATCH] modcache.sh: Support imap connections with tls/ssl --- plugins/libkolab/bin/modcache.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/plugins/libkolab/bin/modcache.sh b/plugins/libkolab/bin/modcache.sh index 2e671b0c..fc87b1fa 100755 --- a/plugins/libkolab/bin/modcache.sh +++ b/plugins/libkolab/bin/modcache.sh @@ -210,9 +210,22 @@ function authenticate(&$opts) else if (empty($opts['user'])) $opts['user'] = $opts['username']; + // parse $host URL + $url = parse_url(trim($opts['host'])); + if (!empty($url['host'])) { + $imap_host = $url['host']; + $imap_ssl = isset($url['scheme']) && in_array($url['scheme'], array('ssl','imaps','tls')) ? $url['scheme'] : false; + $imap_port = isset($url['port']) ? $url['port'] : ($imap_ssl && $imap_ssl != 'tls' ? 993 : 143); + } + else { + $imap_host = trim($opts['host']); + $imap_port = 143; + $imap_ssl = false; + } + // let the kolab_auth plugin do its magic $auth = $rcmail->plugins->exec_hook('authenticate', array( - 'host' => trim($opts['host']), + 'host' => $imap_host, 'user' => trim($opts['user']), 'pass' => $opts['password'], 'cookiecheck' => false, @@ -221,7 +234,7 @@ function authenticate(&$opts) if ($auth['valid']) { $storage = $rcmail->get_storage(); - if ($storage->connect($auth['host'], $auth['user'], $auth['pass'], 143, false)) { + if ($storage->connect($imap_host, $auth['user'], $auth['pass'], $imap_port, $imap_ssl)) { if ($opts['verbose']) echo "IMAP login succeeded.\n"; if (($user = rcube_user::query($opts['username'], $auth['host'])) && $user->ID)