Author Topic: [Solved] Is it possible to define several imap/stmp ports ?  (Read 309 times)

Offline xuo

  • Jr. Member
  • **
  • Posts: 16
[Solved] Is it possible to define several imap/stmp ports ?
« on: March 21, 2020, 03:44:04 PM »
Hi,

I'm using roundcube 1.4.3 with the ident_switch plugin and everything is working correctly.
For the moment, lets forget the ident_switch plugin.
I can connect to RC using 3 identities. All use the same imap port with ssl (993) and the same smtp port with ssl (465).
I would like to add another identity, the one from my work.
Currently, I can access to this work email account on Thunderbird through davmail, with port 1143 for imap and port 1025 for smtp. The server name in both cases is mydomain.fr.

I'd like to know how I can define several ssl imap and smtp ports.

I tried something like :
$config['default_host'] = array (
    'ssl://imap.free.fr' => 'imap.free.fr',
    'ssl://mail.gandi.net' => 'mail.gandi.net',
    'ssl://mydomain.fr' => 'mydomain.fr'
);

// TCP port used for IMAP connections

$config['default_port'] = array (
    'ssl://imap.free.fr' => '993',
    'ssl://mail.gandi.net' => '993',
     'ssl://mydomain.fr' => '1143'
);

$config['smtp_server'] = array (
    'imap.free.fr' => '465',
    'mail.gandi.net' => '465',
    'mydomain.fr' => '1025'
);

but it does not work. Is there a way to do that ?
(I get the following error : translated from french) :
Connection error to the storage server.

Regards.

Xuo.
« Last Edit: March 26, 2020, 02:14:23 PM by xuo »

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,388
Re: Is it possible to define several imap/stmp ports ?
« Reply #1 on: March 22, 2020, 02:52:15 AM »
the port can be specified as part of the host string eg:
Code: [Select]
$config['default_host'] = array (
    'ssl://imap.free.fr:123' => 'imap.free.fr',
    'ssl://mail.gandi.net:456' => 'mail.gandi.net',
    'ssl://mydomain.fr:789' => 'mydomain.fr'
);
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline xuo

  • Jr. Member
  • **
  • Posts: 16
Re: Is it possible to define several imap/stmp ports ?
« Reply #2 on: March 22, 2020, 01:55:26 PM »
Hi,

Thank you for your answer but unfortunately I couldn't make it work.
I get the following errors in log/errors.log :

[22-Mar-2020 18:49:12 +0100]: <362486sr> DB Error: [1364] Field 'alias' doesn't have a default value (SQL Query: INSERT INTO `users` (`created`, `last_login`, `username`, `mail_host`, `language`) VALUES (now(), now(), 'xuo@company.com', 'mydomain.fr', 'fr_FR')) in /usr/share/roundcubemail-1.4.3/program/lib/Roundcube/rcube_db.php on line 543 (POST /?_task=login&_action=login)
[22-Mar-2020 18:49:12 +0100]: <362486sr> PHP Error: Failed to create new user in /usr/share/roundcubemail-1.4.3/program/lib/Roundcube/rcube_user.php on line 703 (POST /?_task=login&_action=login)
[22-Mar-2020 18:49:12 +0100]: <362486sr> PHP Error: Failed to create a user record. Maybe aborted by a plugin? in /usr/share/roundcubemail-1.4.3/program/include/rcmail.php on line 652 (POST /?_task=login&_action=login)

The "maybe aborted by a plugin ?" looks weird. I can try to remove the ident_switch plugin to test.
EDIT : Removing the plugin didn't change anything.
EDIT 2 : using the username and password defined in the config.inc.php file, I can manually connect to the phpmyadmin roundcubemail database.

Any idea ?

Regards.

Xuo.
« Last Edit: March 22, 2020, 02:06:24 PM by xuo »

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,388
Re: Is it possible to define several imap/stmp ports ?
« Reply #3 on: March 22, 2020, 02:30:26 PM »
Did you update from an earlier version of Roundcube to 1.4? The `alias` column was removed from the users table years ago, I think in version 0.9.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline xuo

  • Jr. Member
  • **
  • Posts: 16
Re: Is it possible to define several imap/stmp ports ?
« Reply #4 on: March 22, 2020, 02:45:21 PM »
Hi,

Yes, I'm upgrading each time there is a new version. I don't remember which version was the first one I've installed. I've maybe done something wrong one day.
Should I remove the alias field (manually) ? The problem is taht in this case, there is potentially a lot of bad fields.
EDIT : removing  the "alias" field from the "users" database entry make the connection to succeed.

Regards.

Xuo.
« Last Edit: March 22, 2020, 03:42:38 PM by xuo »

Offline xuo

  • Jr. Member
  • **
  • Posts: 16
Re: Is it possible to define several imap/stmp ports ?
« Reply #5 on: March 22, 2020, 04:01:32 PM »
Hi,

Now that I can log in, is there a way to define several smtp ports ?
I've tried :

$config['smtp_server'] = array (
    'imap.free.fr' => ssl://smtp.free.fr:465'
    'mail.gandi.net' => 'ssl://smtp.gandi.net:465'
    'mydomain.fr' => 'ssl://mydomain.fr:1025'
);

but it does not work.

Thank you.

Xuo.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,388
Re: Is it possible to define several imap/stmp ports ?
« Reply #6 on: March 23, 2020, 04:56:19 AM »
you cannot set smtp_server as an array. if none of the macros provided work for you then, i think, you could do something like:
Code: [Select]
if ($_SESSION['storage_host'] == 'ssl://imap.free.fr:123') {
  $config['smtp_server'] = 'ssl://smtp.free.fr:465';
}
elseif ($_SESSION['storage_host'] == 'ssl://mail.gandi.net:456' ) {
  $config['smtp_server'] = 'ssl://smtp.gandi.net:465';
}
else {
  $config['smtp_server'] = 'ssl://mydomain.fr:1025';
}

Quote
EDIT : removing  the "alias" field from the "users" database entry make the connection to succeed.
I suggest you review your database to ensure the the entire schema is connect for your version of roundcube. you'll probably also need to run /bin/indexcontacts.sh.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline xuo

  • Jr. Member
  • **
  • Posts: 16
Re: Is it possible to define several imap/stmp ports ?
« Reply #7 on: March 23, 2020, 04:48:40 PM »
Hi,

I couldn't make it work. I think the variable $_SESSION['storage_host'] is not recognized in the config file.
I think it shouldn't be too much difficult. It looks like we should just ge the $key variable from the file rcmail.php and pass it to rcube_smtp.php.
But as I don't know php, it will be difficult for me.
Anyway, If I can find a solution, I'll post it.
Thank you for your help.

About the database, I don't know how to check it is correct. I would expect RC to do it. I'll see what the indexcontacts.sh script does.

Regards.

xuo.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,388
Re: Is it possible to define several imap/stmp ports ?
« Reply #8 on: March 23, 2020, 04:52:46 PM »
My example might be a bit wrong. Try taking off the ssl:// part and the port number. Just use the host name on it's own.

As for the database the upgrade script does update the database schema.
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline xuo

  • Jr. Member
  • **
  • Posts: 16
Re: Is it possible to define several imap/stmp ports ?
« Reply #9 on: March 23, 2020, 05:01:11 PM »
Hi,

I'll try all this tomorrow.

Regards.

Xuo.

Offline xuo

  • Jr. Member
  • **
  • Posts: 16
Re: Is it possible to define several imap/stmp ports ?
« Reply #10 on: March 24, 2020, 03:56:16 PM »
Hi,

About the database :

Quote
@ordi4  /usr/share/roundcubemail-1.4.3 104 #  ./bin/update.sh
What version are you upgrading from? Type '?' if you don't know.
?
Executing database schema update.
NOTICE: Update dependencies by running `php composer.phar update --no-dev`
This instance of Roundcube is up-to-date.
Have fun!

@ordi4  /usr/share/roundcubemail-1.4.3 105 # php composer.phar update --no-dev
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Loading composer repositories with package information
Updating dependencies                                 
Package operations: 0 installs, 1 update, 0 removals
  - Updating pear/crypt_gpg (v1.6.3 => v1.6.4): Downloading (100%)         
Writing lock file
Generating autoload files


I think the database is correct now.

For the smtp part, I've tried :
if ($_SESSION['storage_host'] == 'imap.free.fr') {
    $config['smtp_server'] = 'ssl://smtp.free.fr:465';
}
elseif ($_SESSION['storage_host'] == 'mail.gandi.net') {
    $config['smtp_server'] = 'ssl://smtp.gandi.net:465';
}
else {
    $config['smtp_server'] = 'ssl://mydomain:1025';
}

But it still doesn't work.

Regards.

Xuo.

Offline JohnDoh

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2,388
Re: Is it possible to define several imap/stmp ports ?
« Reply #11 on: March 25, 2020, 03:50:11 AM »
I dont expect the update script to have done much in your case because you are already running the latest PHP code. I think you are looking for an easy solution and there isnt one. Your database and the code are years out of sync and I think the only way to fix that is to manually update the database and then make sure your follow the upgrading instructions going forward.

Quote
But it still doesn't work.

ok
Roundcube Plugins: Contextmenu, SpamAssassin Prefs, and more…

Offline xuo

  • Jr. Member
  • **
  • Posts: 16
Re: Is it possible to define several imap/stmp ports ?
« Reply #12 on: March 26, 2020, 02:14:00 PM »
Hi,

I've re-installed RC from scratch (code + sql database).
I didn't try to modify the config file, but directly installed the plugin ident_switch which allows to have different imap/smtp ports to use.
BUT it does not allow to have different username/password for imap and smtp. So I've hacked the php code (in a very ugly way) to make it work the way I wanted.
Anyway, thank you again for your help and all your suggestions.

Regards.

Xuo.

PS : during the installation, I've set the rc prefix database to 'rc_'. This was really not a good idea. So I've renamed all the tables of the rc database.