Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: doctor madness on December 09, 2009, 04:06:30 AM

Title: Accounts plugin
Post by: doctor madness on December 09, 2009, 04:06:30 AM
Hi,

I'd like to use an external IMAP account from roundcube. I enabled accounts (and settings) plugin, I added my server in the list, then I try to create account from "Account administration"
but when I click "Add" button, I get the following error :
"Failed to establish connexion to remote host"

I can connect on port 143 to this host from the server hosting roundcube.
I don't see any error log, what should I do ?
Title: Accounts plugin
Post by: rosali on December 09, 2009, 06:26:50 AM
Use this test script to check if you are really able to connect from hosting server:



function test_connection($username,$password,$imap_host,$imap_port,$prot){
                 
     if(function_exists("imap_open")){
      if($prot){
         $imap_open = "{" . $imap_host . ":" . $imap_port . "/imap/" . $prot . "/novalidate-cert}INBOX";
       }
       else{
         $imap_open = "{" . $imap_host . ":" . $imap_port . "/novalidate-cert}INBOX";
       }
     
       if($res = @imap_open($imap_open, $username, $password)){
         $success = true;
         imap_close($res);
       }
       else{
         $success = false;
       }
     }
     else{
       $success = true;
     }
       
     return $success;
   
   }

   // DO NOT EDIT
   if(test_connection("demo@mail4us.net","demo","mail4us.net",143,false))
     echo "mail4us.net ok
";
   else
     echo "mail4us.net failed
";

   //EDIT USER AND PASSWORD
   if(test_connection("mygoogleaccount@gmail.com","mygooglepassword","imap.gmail.com",993,"ssl"))
     echo "ssl google ok
";
   else
     echo "ssl google failed
";
?>
Title: Accounts plugin
Post by: doctor madness on December 09, 2009, 01:24:32 PM
Hi,

i just tested :
$php5 test.php

the mail4us.net is ok
the gmail is failed

I added my server like this :
if(test_connection("login","password","my.imap.server",143,false))
     echo "my_own ok
";
   else
     echo "my_own failed
";
and my_own imap server is failed too.
It's an IMAP server. I can connect on it using :
telnet my.imap.server 143
Using thunderbird and other MUA is working too

It's php5 from debian stable.
any idea ?
Title: Accounts plugin
Post by: doctor madness on December 11, 2009, 08:14:27 AM
no one to help me with this little problem ?
Title: Accounts plugin
Post by: rosali on December 11, 2009, 08:19:01 AM
Does 'localhost' work for your own IMAP server? Gmail might fail due to missing ssl support of your PHP installation.
Title: Accounts plugin
Post by: doctor madness on December 11, 2009, 09:25:51 AM
the test on my locahost is working.
I think it may be related to the remote host. but this hosts is a corporate mail server. where hundreds or thousands people check their mails daily using IMAP (and/or POP)
so I think it should be a bad implementation of IMAP on server side, or php5 imap module
Title: Accounts plugin
Post by: rosali on December 12, 2009, 01:11:01 AM
Are you able to connect to gmail by configuring main.inc.php to use ssl://imap.gmail.com:993 ?
Title: Accounts plugin
Post by: doctor madness on December 15, 2009, 01:28:09 PM
Hi,

I'm not able to connect to gmail. Maybe I need some php modules, to deal with SSL, no ?
Title: Accounts plugin
Post by: SKaero on December 15, 2009, 01:41:29 PM
A lot of hosts block port 993 outbound, I say that's would be the first thing to check.
Title: Accounts plugin
Post by: doctor madness on December 16, 2009, 02:44:35 AM
nc -vz imap.gmail.com 993
DNS fwd/rev mismatch: gmail-imap.l.google.com != ew-in-f109.1e100.net
gmail-imap.l.google.com [74.125.77.109] 993 (imaps) open


It seems to be OK. This computer is on a unfiltered network
Title: Accounts plugin
Post by: SKaero on December 16, 2009, 06:48:06 AM
When to try to connect to gmail using RoundCube what shows up in the error log?
Title: Accounts plugin
Post by: doctor madness on December 21, 2009, 04:35:47 AM
Hi,

In my errors log file, I don't have anything regarding problem with Gmail.
I really think the problem with Gmail is due to SSL. Maybe a PEAR module is needed, no ?

My original problem is the access to a non SSL IMAP server. I can connect to mail4us.net using code provided by Rosali. But I can't connect to one of  mine...
Title: Accounts plugin
Post by: rosali on December 21, 2009, 04:50:28 AM
Remove "@" sign in front of imap_open command. Perhaps you get some hints by the error message when connection fails.
Title: Accounts plugin
Post by: doctor madness on December 21, 2009, 02:32:40 PM
Here are the errors reported when I execute your code without the @ before imap_open :
Warning: imap_open(): Couldn't open stream {imap.gmail.com:993/imap/ssl/novalidate-cert}
Title: Accounts plugin
Post by: doctor madness on January 04, 2010, 02:36:53 AM
No idea on this issue ?
Title: Accounts plugin
Post by: SKaero on January 04, 2010, 02:40:47 AM
Do you have OpenSSL?
Title: Accounts plugin
Post by: rosali on January 04, 2010, 04:27:00 AM
It does not word due to missing SSL support of you PHP installation. That's no Roundcube issue. Please contact your host.
Title: Accounts plugin
Post by: doctor madness on January 05, 2010, 02:55:20 PM
I can connect to my remote imap server using telnet, netcat, thunderbird. so I think it's not a problem on my host (i'm the admin of this host) neither network related problem. Maybe my php installation is wrong, but I'm very unskilled in this world. So any help should be very appreciated
Title: Accounts plugin
Post by: SKaero on January 06, 2010, 05:15:23 AM
You can try asking on http://serverfault.com/ you need to install OpenSSL for it to work.
Title: Accounts plugin
Post by: doctor madness on January 07, 2010, 02:56:17 AM
Hi,

Thank you for your suggestion, but my remote IMAP server is not using SSL.
Title: Accounts plugin
Post by: doctor madness on January 10, 2010, 09:18:38 AM
I finally get it working !

When i tried the code provided by Rosali, and I found I need to replace the "false" in the "$prot" variable with "notls" according to php_imap documentation. Then the test works.

So, I made the following changes in accounts.php :
Line 116 : $imap_open = "{" . $imap_host . ":" . $imap_port . "/imap/" . $prot . "/novalidate-cert}INBOX";
replaced with :
$imap_open = "{" . $imap_host . ":" . $imap_port . "/imap/" . $prot . "/notls}INBOX";
Line 120 : $imap_open = "{" . $imap_host . ":" . $imap_port . "/novalidate-cert}INBOX";
replaced with :
$imap_open = "{" . $imap_host . ":" . $imap_port . "/notls}INBOX";
Line 320 : $prot = FALSE;
replaced with :
$prot = notls;
Line 652 : $prot = FALSE;
Replaced with :
$prot = notls;

And it works !
So, I presume "false" make php_imap uses tls, but my remote IMAP server is nor SSL nor TLS compliant.
I don't have any skill in PHP, but I think a good thing could be to allow user to choose SSL/TLS/Nothing in accounts menu, or to allow RC admin to set this setting in config.php.inc

I contacted ppl developping this plugin to include my correction/suggestions

Regards,
Damien