RoundCube webmail on OS X Server

Part One: Installing RoundCube on OS X Server 10.6 (Snow Leopard)
These instructions are based on the following URLs:
http://trac.roundcube.net/wiki/Howto_Install
http://diymacserver.com/installing-the-mailserver/installing-roundcube-for-webmail/
http://roosbertl.blogspot.com/2010/01/using-avelsieve-or-managesieve-on-snow.html

I’ve tweaked them to be more comprehensive, and clear. Assuming your Mac OS X Server 10.6.x box is running well in all other ways, this should work just fine. To allow you and your users to access their email from anywhere you can install this PHP-based webmail app RoundCube. It’s a very user friendly and usable web-based mail interface with some Ajax goodness, allowing drag-and-drop of emails between IMAP folders, etc. Please note that to fully benefit from a webmail client your users should use the IMAP capabilities of your server.

You need to download the latest code from the RoundCube site at http://www.roundcube.net/.

Extract the archive into the Document root of your Apache installation, in our case /Library/WebServer/Documents/.

To be able to install new versions and to migrate easily we setup a symbolic link to the current RoundCube directory which we can change when a new version arrives.

sudo ln -s /Library/WebServer/Documents/roundcubemail-0.xxxx /Library/WebServer/Documents/roundcubemail

Step into the newly created directory and change the permissions on the temp and logs directory so that Apache can write into these directories with the following commands:

chown -R _www:_www temp
chown -R _www:_www logs

Next we need to create a database for Roundcube to use. The next steps assume that you’ve already configured a MySQL “root” user password, and MySQL is running. Open a shell, log into MySQL as your root user, then issue the following commands, being sure to change the placeholder “PASSWORD” to a real one that you’ve documented, because you’ll need it later:

CREATE DATABASE roundcubemail DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcube@localhost IDENTIFIED BY ‘PASSWORD’;
FLUSH PRIVILEGES;
quit

Okay, now that you’ve created the database, you need to populate it with the appropriate tables using the tool provided by RoundCube:

1. If you’re not there for some reason, move into /Library/WebServer/Documents/roundcubemail/ directory.

2. Now run the command “mysql -p -u roundcube roundcubemail <sql/mysql.initial.sql” within a shell, and enter the password of the roundcube MySQL user that you previously created and documented. If you’ve done this correctly, you should see the following in after logging into MySQL as “roundcube”, using the “roundcubemail” database, and issuing a SHOW TABLES command:

+-------------------------+
| Tables_in_roundcubemail |
+-------------------------+
| cache                   |
| contactgroupmembers     |
| contactgroups           |
| contacts                |
| identities              |
| messages                |
| session                 |
| users                   |
+-------------------------+

The next step is a lot simpler because RoundCube comes bundled with a nifty PHP-based installer.

Point your browser to http://yourhostname/roundcubemail/installer/ and follow the instructions.

In step 2 you are asked some questions, about the database and IMAP setups. The following might be your answers to the important questions.
Database setup:
localhost
roundcubemail
roundcube
PASSWORD (the same as used above)

IMAP Settings: ssl://localhost:993

The rest is up to your discretion.

If the installer was unable to create the config files you need to copy the contents located in the browser in the files db.inc.php and main.inc.php located in the directory config.

Part Two: Message filtering with RoundCube and sieve
The ManageSieve plugin comes with RoundCube. To enable it, edit the file roundcube/config/main.inc.php like this:

$rcmail_config[‘plugins’] = array(‘managesieve’);

Next edit the file plugins/managesieve/lib/Net/Sieve.php like this:

– comment line var $supportedAuthMethods=…. (comment with //)
– uncomment line var $supportedAuthMethods=array( ‘PLAIN’ , ‘Login’ );

The sieve configuration file for each user is stored in the directory hierarchy like this:

/private/var/spool/imap/dovecot/sieve-scripts/<GUID_OF_USER>/

The good thing is, that every rule managing application (Apple’s wiki-based rules, SquirrelMail, RoundCube) you use stores its own file. Why is this useful? Because the various systems avoid overwriting each others’ sieve configuration file. This is of importance if you enable the Apple’s built-in wiki-based rule management, which creates a file “wiki_server_rules.sieve” in your sieve script directory and enables it via the symbolic link “dovecot.sieve -> wiki_server_rules.sieve”.

To switch from Apple’s wiki-based rules to RoundCube rules, simply delete the dovecot.sieve symbolic link, then create a symbolic link to your file with the following steps:
sudo su
serveradmin stop mail
cd /private/var/spool/imap/dovecot/sieve-scripts/<GUID_OF_USER>/
rm dovecot.sieve
ln -s roundcube.sieve dovecot.sieve
serveradmin start mail
exit

Keep in mind that the above steps assume that your RoundCube filter set is called “roundcube”; if users have created a non-wiki filter set with another name, e.g. “roundcube-filters”, the command to create the symbolic link will need to be adjusted. In this example, the command would be “ln -s roundcube-filters.sieve dovecot.sieve” instead of the default above.

If you’ve done all this, you’re done with the configuration of RoundCube. If you have tested the setup and it works, remove the installer directory from the RoundCube installation, as it might be used by script kiddies to hack your installation.

I like to use a subdomains to divide up the specific tasks my web server does. For example, you can use https://webmail.yourdomain.tld to allow users to access their mail via RoundCube. Alternately, you should be able to go to https://yourdomain.tld/roundcubemail/ and log in without needing to create a subdomain and Apache virtual host config.

In case of any errors, check the log files. For RoundCube errors check the /Library/WebServer/Documents/roundcubemail/logs/errors file, and for general mail errors check the /var/log/mail.log file.