Import Roundcube sieve filters to Webtop

Hi all, I need your help to test a script I wrote. This script allow you to import Roundcube sieve filters to Webtop. It is not simple to find a solution to import all filters, but it can works pretty fine.

Some Roundcube filters are not implemented in Webtop. Sometimes I found a workaround. The only filter type that is not supported by the script is “Answer with message”. Eventually you can create an Automatic Response directly in Webtop.

I can’t test all type of configurations, your help is really appreciated.

REQUIREMENTS

  • Access at least one time with username without domain or impersonating (without @ and *root in username filed)
  • Access and activate users in Webtop: if you can’t access users one by one you can activate them via admin panel, under Users management.
  • Get Roundcube database password. It is in /etc/roundcubemail/config.inc.php file and you can retrieve it whit this command: grep db_dsnw /etc/roundcubemail/config.inc.php
    The output will be:
    $config['db_dsnw'] = 'mysql://roundcubemail:*dbroundcubepass*@localhost/roundcubemail';

SCRIPT CONFIGURATION

  • Import script into NethServer with the following command: wget https://raw.githubusercontent.com/federicoballarini/webtop5-scripts/master/rcube2webtop.php . You can save it in any directory.
  • Open the script with vim and insert database password by replacing text on line 14.

SCRIPT EXECUTION

  • You can execute the script with /usr/bin/php /var/www/html/rcube2webtop.php user domain.ext
    Change /var/www/html with the path where you’ve saved the script. You can replace user with all to import all users filters. Use main domain in case of multi-domain configurations.

SCRIPT OUTPUT

  • Actually the script shows the output but I think it will be better to save it into a log file.
  • In case of “Answer with text” it will be show the following text ERROR: ANSWER WITH TEXT NOT SUPPORTED .
  • In case of problems with rules it will show an alert as this: NOT IMPLEMENTED

POST-SCRIPT OPERATION

  • At the end of the scripts each user had to go into Webtop and activate filters, after a check. To enable them, you have to change configuration on the right and set “webtop5”. Then you have to press “Save and Close” to write sieve filters file.
    If you want to enable filters without user login, you can enter as user with impersonate (admin!user)
  • Check filters before activate them!

I wait some feedback to improve this script.
Thank you all!

4 Likes

Translate all the remarks in english, will be easier to people of the project to understand the way your script works

I think this should be avoided. Script could be invoked by shell, Cockpit, Webtop, and import filters from all users an related password should be a parameter as a single user and its password is.
This parameters could be filled by a form on server manager (maybe a webform with a checkbox for all users)

Consider to collect output in case of interactive use (webform), but put into a log file is important for help future troubleshooting.
If the import has been run from the same user who owns the mailbox, consider the option to send a user-oriented output email message with a readable log of what worked, what didn’t worked and last but not least the reminder to check imported filters and activate.
Maybe a link to a knowledge base/user guide with an howto for create Automatic Response

I am aware that most of the hints are not directly related to the scripts, hope that will help anyway.

3 Likes

Thank you for you hints.
I will modify and translate all comments of the code.

This script have to be launch from root user only 1 times per user. I think it will unnecessary to add a dedicated web page.

Surely I will implement log file.

EDIT: I opened issues here https://github.com/federicoballarini/webtop5-scripts/issues

1 Like

Thanks to @pike hints I updated the code with followings enhancements:

  • translated all comments and output to english
  • saved output into a log file (default is /var/log/rcube2webtop.log)

The output of the log should be similar to this:

[root@mail ~]# /usr/bin/php /var/www/html/rcube2webtop.php admin domain.ext
Starting import...

2019-11-17 21:42:32 ***** START USER: admin *****
2019-11-17 21:42:32 ######## START FILTER: 1 #########
2019-11-17 21:42:32 Filter name: Test
2019-11-17 21:42:32 Enabled: f
2019-11-17 21:42:32 Match: all
2019-11-17 21:42:32 Rules: [{"field":"subject","argument":"","operator":"contains","value":"22"}]
2019-11-17 21:42:32 Actions: [{"method":"fileinto","argument":"Drafts"},{"method":"addflag","argument":"seen"},{"method":"addflag","argument":"flagged"}]
2019-11-17 21:42:32 QUERY: INSERT INTO mail.in_filters (domain_id,user_id,enabled,"order",name,sieve_match,sieve_rules,sieve_actions) VALUES ('NethServer','admin','f','6','Test','all','[{"field":"subject","argument":"","operator":"contains","value":"22"}]','[{"method":"fileinto","argument":"Drafts"},{"method":"addflag","argument":"seen"},{"method":"addflag","argument":"flagged"}]');
2019-11-17 21:42:32 RESULT: OK
2019-11-17 21:42:32 ######## END FILTER: 1 #########
2019-11-17 21:42:32 ***** END USER: admin *****
2019-11-17 21:42:32 ***** CONVERSION ENDED: CHECK ERRORS AND THEN APPLY CHANGES IN WEBTOP USER PAGE *****

Import ended: check log file for errors: you can read it also under /var/log/rcube2webtop.log

The script auto-show the log at the end of the execution but you can read it also under log path.

2 Likes