Hi noordkriek,
I experienced the same error message as you, and for me the cause of the issue was that my IMAP server's SSL certificate's CN did not match the hostname used by roundcube's $config['default_host'] entry. The mismatch was deliberate by me during a testing of a new server, but the lack of a proper error message did not help diagnosis.
I traced it to the rcube_imap_generic::_connect() method in rcube_imap_generic.php, which has the following code:
940 if (!empty($this->prefs['socket_options'])) {
941 $context = stream_context_create($this->prefs['socket_options']);
942 $this->fp = stream_socket_client($host . ':' . $this->prefs['port'], $errno, $errstr,
943 $this->prefs['timeout'], STREAM_CLIENT_CONNECT, $context);
944 }
945 else {
946 $this->fp = @fsockopen($host, $this->prefs['port'], $errno, $errstr, $this->prefs['timeout']);
947 }
948
949 if (!$this->fp) {
950 $this->setError(self::ERROR_BAD, sprintf("Could not connect to %s:%d: %s",
951 $host, $this->prefs['port'], $errstr ?: "Unknown reason"));
952
953 return false;
954 }
In an out-of-the-box roundcube config on Ubuntu, the 'socket_options' preferences will not be set, so the above code uses the fsockopen() codepath. The function returns FALSE and the $errno variable comes back as zero. According to
http://php.net/manual/en/function.fsockopen.php, this implies "This is most likely due to a problem initializing the socket".
A test program immediately showed the issue:
<?php
$fp = fsockopen("ssl://servername", 993, $errno, $errstr, 30);
if ($fp) {
echo "Success";
fclose($fp);
}
else {
echo "Fail: errstr=\"$errstr\", errno=\"$errno\"";
}
$ php fsockopen_ssl_imap_test.php
PHP Warning: fsockopen(): Peer certificate CN=`actualservername' did not match expected CN=`servername' in fsockopen_ssl_imap_test.php on line 2
PHP Warning: fsockopen(): Failed to enable crypto in fsockopen_ssl_imap_test.php on line 2
PHP Warning: fsockopen(): unable to connect to ssl://servername:993 (Unknown error) in fsockopen_ssl_imap_test.php on line 2
Fail: errstr="", errno="0"
Those PHP warnings don't show up in the Roundcube logs, which is why the error message ("unknown reason") is cryptic.
Anyway, you could try that test program yourself and see what the issue is on your server. If it's a CN mismatch like mine, and the mismatch is deliberate, you can set the following in your config.inc.php file:
// IMAP socket context options
$config['imap_conn_options'] = array(
'ssl' => array(
'peer_name' => 'actualservername'
),
);This uses the other codepath (with stream_context_client()) and allows you to set a number of options to make the SSL connection work. The full list is at
http://php.net/manual/en/context.ssl.php.
If it's a CN mismatch and it was unintentional, fix your SSL setup :-).
Hope that helps!
Note to Roundcube devs: is there an easy way of improving the error message when fsockopen() is used?