Author Topic: error rcube_imap.php line 993  (Read 9579 times)

Offline noordkriek

  • Newbie
  • *
  • Posts: 6
error rcube_imap.php line 993
« on: August 15, 2016, 03:04:13 PM »
Hi,

I upgraded from Ubuntu Server LTS 14.04 to 16.04 and now mysql is up to version 5.7, PHP is 7 and roundcube is 1.2-beta (but I also tested by installed 1.2.1 from the website). The problem is that I cannot login from the browser. It says 'connection to IMAP server failed' (or something like that, because I translate it from Dutch). The log file 'errors' read the next lines. I put in two lines because I tried on a different port. 994 is my SSL and 144 is for IMAP.

Code: [Select]
[15-Aug-2016 20:36:04 +0200]: <tt056q6g> IMAP Error: Login failed for myuser@mydomain.nl from 192.168.0.3. Could not connect to ssl://localhost:994: Unknown reason in /var/www/roundcube/program/lib/Roundcube/rcube_imap.php on line 193 (POST /roundcube/?_task=login&_action=login)
[15-Aug-2016 20:37:08 +0200]: <tt056q6g> IMAP Error: Login failed for myuser@mydomain.nl from 192.168.0.3. Could not connect to ssl://localhost:144: Unknown reason in /var/www/roundcube/program/lib/Roundcube/rcube_imap.php on line 193 (POST /roundcube/?_task=login&_action=login) 

What can I try to fix this. I see in the forum nobody else with the message like this involving rcube_imap.php + line 993. I can login from Thunderbird which is using port 144 and no problems reading my mail.

Tnx, Ron

Offline gszabo

  • Newbie
  • *
  • Posts: 1
Re: error rcube_imap.php line 993
« Reply #1 on: August 19, 2016, 02:49:37 AM »
Hi, same problem here on debian8.

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,879
    • SKaero - Custom Roundcube development
Re: error rcube_imap.php line 993
« Reply #2 on: August 19, 2016, 11:09:47 AM »
Enable imap_debug and post the log.

Offline chtse53

  • Newbie
  • *
  • Posts: 1
Re: error rcube_imap.php line 993
« Reply #3 on: August 21, 2016, 02:00:58 AM »
I may be having a similar/related issue.  My roundcube has been working all along (v1.21) on ubuntu 16.04LTS, php5.6, nginx. Suddenly, I got login failure problem.  I use IMAPS to localhost through a domain name.  I finally got it working again by disabling ipv6 for my server.  It appears that the IMAPS login fails through resolving the domain name to an ipv6 address.  I could'nt figure what caused this problem. It might be introduced by an updated php 5.6.  I move the roundcube to another server running ubuntu 14.04LTS with most updated php 5.6.  Same behavior -- not working.

Offline noordkriek

  • Newbie
  • *
  • Posts: 6
Re: error rcube_imap.php line 193
« Reply #4 on: August 21, 2016, 09:17:29 AM »
First, I changed the subject to 'line 193', I just noticed the mistake.

My errors file in Roundcube doesn't show any additional lines when enabling 'imap_debug'. In /var/log/mail.log I see these lines when attempting to login:
Code: [Select]
Aug 21 15:11:08 servername dovecot: imap-login: Disconnected (disconnected before auth was ready, waited 0 secs): user=<>, rip=127.0.0.1, lip=127.0.0.1, secured, session=<Usk4qpQ61r9/AAAB>
Aug 21 15:11:22 servername dovecot: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=127.0.0.1, lip=127.0.0.1, secured, session=<584Oq5Q62r9/AAAB>

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,879
    • SKaero - Custom Roundcube development
Re: error rcube_imap.php line 993
« Reply #5 on: August 21, 2016, 12:39:14 PM »
When you enable imap_debug a new imap log file should be created.

Offline noordkriek

  • Newbie
  • *
  • Posts: 6
Re: error rcube_imap.php line 993
« Reply #6 on: August 21, 2016, 01:46:27 PM »
Hmm, no new file was created, so I enabled all debug options. After that, the file sql is created, nothing else. So debugging does work and the directory has the right permissions.

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,879
    • SKaero - Custom Roundcube development
Re: error rcube_imap.php line 993
« Reply #7 on: August 22, 2016, 12:59:33 AM »
So its not connecting to the mail server at all, I'm going to guess there is some sort of problem with openssl. If you can try connecting without encryption and see if that works.

Offline noordkriek

  • Newbie
  • *
  • Posts: 6
Re: error rcube_imap.php line 993
« Reply #8 on: August 23, 2016, 01:34:24 PM »
Thanks SKaero!
In config.inc.php I changed the line with default_host from ssl://localhost to localhost and now I can login.
So your thought was right.

That makes me think, I know dovecot is listening on port 994 instead of 993 so maybe roundcube does not know to use port 994?
So I tried the config back to ssl://localhost and change 'default_port' to 994 but that did not work.
Maybe you have an idea?

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,879
    • SKaero - Custom Roundcube development
Re: error rcube_imap.php line 993
« Reply #9 on: August 23, 2016, 03:17:37 PM »
You can see in the log that is was connecting to 994 since it said "Could not connect to ssl://localhost:994: Unknown reason" have you tried tls:// instead of ssl://

Offline noordkriek

  • Newbie
  • *
  • Posts: 6
Re: error rcube_imap.php line 993
« Reply #10 on: August 24, 2016, 03:53:35 PM »
Just tried tls, I took a longer time before it gave the error that it could not connect to imap server. In logfile errors it gives the same message about line 193 but this time with the message "empty startup greeting localhost:994" instead of "unknown reason"
There are no additional messages in other logs. imap logfile only shows info from the (succesfull) attempt without ssl (port 144)

Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,879
    • SKaero - Custom Roundcube development
Re: error rcube_imap.php line 993
« Reply #11 on: August 24, 2016, 10:49:25 PM »
OK, it sounds like tls isn't used in your setup. The problem definitely sounds like its with openssl or the php configuration, without anymore errors its hard to narrow it down further.

Offline noordkriek

  • Newbie
  • *
  • Posts: 6
Re: error rcube_imap.php line 993
« Reply #12 on: August 27, 2016, 04:11:26 PM »
Thanks for thinking with me so far. At least now I can use Roundcube, just without encryption until I find the solution. It seems there is not a real issue or broken system and other software is working as expected, One other problem (I think) is that 'apt upgrade' is showing "packages that are installed automatically and are no longer required":

Code: [Select]
De volgende pakketten zijn automatisch geïnstalleerd en zijn niet langer nodig:
  aspell aspell-en dictionaries-common emacsen-common libaspell15 libc-client2007e mlock php-auth php-auth-sasl php-db
  php-imap php-intl php-ldap php-log php-mail php-mail-mime php-mail-mimedecode php-mdb2 php-net-ldap2 php-net-ldap3
  php-net-sieve php-net-smtp php-net-socket php-pspell php-soap php7.0-imap php7.0-intl php7.0-ldap php7.0-pspell php7.0-soap
Gebruik 'sudo apt autoremove' om ze te verwijderen.
0 opgewaardeerd, 0 nieuw geïnstalleerd, 0 te verwijderen en 0 niet opgewaardeerd.

Some of them are dependencies for Roundcube (I checked with 'apt show roundcube-core'. Because I did not use apt to install Roundcube, it wants to uninstall those packages. Do I have to exclude them in apt? Or can I use autoremove and then install the depencies manually?
Or can I safely autoremove because I used the 'complete' package from Roundcube website?

Offline mr_smidge

  • Newbie
  • *
  • Posts: 1
Re: error rcube_imap.php line 993
« Reply #13 on: September 11, 2016, 09:33:22 AM »
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?

Offline alec

  • Hero Member
  • *****
  • Posts: 1,365
Re: error rcube_imap.php line 993
« Reply #14 on: September 12, 2016, 02:29:19 AM »
As you see this is more a PHP issue. I think it should set $errstr and $errno, but it does not. Probably this is documented, but not very useful. So, maybe we should get rid of @-operator.