Friday, January 8, 2010

Using SquirrelMail or RoundCube server side rules on Snow Leopard Server

Apple Snow Leopard Server comes with a very limited Mail Sieve rule management within the wiki application.
If you are disappointed by Snow Leopard Servers cappabilities to manage sieve rules (Server Side Mail Rules), there are solutions available.

Prerequisites
Enable Server Side Rules in Mail Server
Start Server Admin
Mail > Settings > Advanced: Tick "PLAIN" on IMAP/POP and save it
Mail > Settings > Filters: Tick "Enable Server Side mail rules", save it and restart the mail service.

Squirrelmail
SquirrelMail is the default webmailer in SLS. You can use the plugin avelsieve to manage server side mail rules. Download avelsieve (I recommend version 1.9.9) and unpack in directory /usr/share/squirrelmail/plugins (so that directory avelsieve is within the plugins dir).
Note that you also need to download javascript_libs plugin, if you use a recent version (>=1.9.8) of avelsieve.
If you need the javascript_libs plugin, also unpack it in squirrelmail's plugins dir.

Then edit the file plugins/avelsieve/config/config.php (copy config_sample.php to config.php if not exisiting).
Change the authentication mechanism to:
$sieve_preferred_sasl_mech = 'PLAIN';

Edit file /usr/share/squirrelmail/config/config.php and register the plugin(s):
$plugins[0] = 'avelsieve';
$plugins[1] = 'javascript_libs'; // only if using a newer version of avelsieve. See avelsieve page

Access the Webmailer (http://<SLS_server_name>/webmail/ and check the filter connection.

Roundcube
Sorrily Apple decided to use the old-fashioned, ugly SquirrelMail webmailer and not RoundCube.
RoundCube is much nicer and also the "managesieve" plugin available for it is much better than avelsieve in SquirrelMail.
Luckily you can install RoundCube on your SLS without harming the default installation.
To install RoundCube on SLS, see here

Enable managesieve plugin
ManageSieve plugin comes with RoundCube.
To enable it, edit file roundcube/config/main.inc.php:
$rcmail_config['plugins'] = array('managesieve');

Then edit file plugins/managesieve/lib/Net/Sieve.php:
- comment line var $supportedAuthMethods=.... (comment with //)
- uncomment line var $supportedAuthMethods=array( 'PLAIN' , 'Login' );

Set timezone
You will get timezone errors in the roundcube/logs/errors log file.
To fix this, add the following to
/etc/php.ini:
enable and change date.timezone to a value you find in the php doc
Example:
date.timezone = Europe/Berlin

Test roundcube
Now test roundcube by accessing http://<SLS_server_name>/roundcube/
Login as a user you like to change server side rules for
Click on "Settings" in the upper right corner, then on Filter.
If you see the page and no error occurs, you are sucessfully connected to the sieve backend of IMAP!
You now can create your rules.

The Sieve configuration file
The sieve config file is stored in dir
/private/var/spool/imap/dovecot/sieve-scripts/<GUID_OF_USER>/

The good thing is, that every rule managing application (Apple web rule management, SquirrelMail, RoundCube) you use, store its own file. So one app is not overwriting the others config file.
This is of importance if you enable the apple built-in crippled rule management and store the rules, there. This creates an own file "wiki_server_rules.sieve" in your sieve script dir and enables it by the link dovecot.sieve -> wiki_server_rules.sieve

To re-enable your SquirrelMail/RoundCube rules, simply delete the dovecot.sieve symbolic link (as root user) and add a link to your file:
sudo bash
cd /private/var/spool/imap/dovecot/sieve-scripts/<GUID_OF_USER>/
rm dovecot.sieve
ln -s roundcube.sieve dovecot.sieve

Then restart the Mail service.

Hope this helps.