Roundcube contacts sync using Z-Push

In this article I describe how to configure Z-Push to use a Roundcube contacts database to allow synchronisation of contacts on a smartphone or tablet using ActiveSync.

We host email for a number of our clients and provide several methods of access, including the popular webmail frontend Roundcube. As well as all of the email features you would expect, Roundcube includes a full featured address book. This was all well and good when we started providing email hosting, but with the increase in smart mobile devices in recent years, the inability to use the Roundcube address book outside of the Roundcube webmail frontend has been an increasingly significant limitation.

We also use Zarafa, another open source webmail system, which incorporates many more advanced groupware features. It includes a component called Z-Push, which is an open source implementation of Microsoft's ActiveSync protocol. ActiveSync is the means by which most smart devices (Apple iOS, Google Android and Microsoft Windows Phone) synchronise mail, contacts, calendars, etc.

Z-Push is closely tied to Zarafa, but can also be configured to use an alternative backend such as a standard IMAP server. When configured in this way it does not offer all the same features as Zarafa, but it is still useful. We've wanted to offer Roundcube contact sync via ActiveSync for a while, but writing an entire new backend for Z-Push was just too big a task to fit in around our working schedule — we are only a small team!

Yesterday I revisited this problem and discovered that there is now a Z-Push backend for Roundcube. It was written by Alex Charrett and can be found on his website. I decided to give it a try but quickly ran into a problem: the authentication system he has written assumes that your users and their (hashed) passwords are stored in a MySQL database. This is not the case for our setup. However, it turned out to be fairly simple to work around. I rewrote the login function to authenticate using IMAP instead. This has the downside of requiring that PHP includes the IMAP module (package php5-imap on Ubuntu/Debian), but the advantage that it should work on any Roundcube setup, as Roundcube uses IMAP to access the users' mail.

To use our version of the Roundcube backend for Z-Push, follow these steps:

  1. Set up Z-Push as normal.
  2. Download the Roundcube backend code from GitHub.
  3. Copy the file roundcubecontacts.php into the backend folder.
  4. Open the Z-Push config.php file in a text editor.
  5. Set BACKEND_PROVIDER to BackendRoundcubeContacts.
  6. Add define('ROUNDCUBE_CONTACT_DB_NAME','database');
  7. Add define('ROUNDCUBE_CONTACT_DB_USER','user');
  8. Add define('ROUNDCUBE_CONTACT_DB_PASS','password');
  9. Add define('ROUNDCUBE_CONTACT_DB_HOST','host');
  10. Save the file.

Current limitations: The IMAP login is currently hardcoded to connect to localhost via SSL. We will change this to a config option in future. Ideally, we would like to unify email sync and contact sync into one Z-Push backend. At the moment, it is necessary to synchronise email using an IMAP account and contacts using a separate ActiveSync account. Z-Push includes an IMAP backend so incorporating it into this Roundcube backend should be straightforward.

Comments

Hey Pete Donnell

As for step #6,#7, I wonder what the password is for? I understand it's not a MySQL username or password, then which ones should I use?

Thank you

I am encountering some issues trying to get this to work. Here is the output from the log:

18/03/2015 13:48:54 [ 2932] [WARN] [myuser@mydomain.com] /usr/share/z-push/backend/roundcubecontacts.php:68 Use of undefined constant ROUNDCUBE_AUTH_DB_HOST - assumed 'ROUNDCUBE_AUTH_DB_HOST' (8)
18/03/2015 13:48:54 [ 2932] [WARN] [myuser@mydomain.com] /usr/share/z-push/backend/roundcubecontacts.php:68 Use of undefined constant ROUNDCUBE_AUTH_DB_USER - assumed 'ROUNDCUBE_AUTH_DB_USER' (8)
18/03/2015 13:48:54 [ 2932] [WARN] [myuser@mydomain.com] /usr/share/z-push/backend/roundcubecontacts.php:68 Use of undefined constant ROUNDCUBE_AUTH_DB_PASS - assumed 'ROUNDCUBE_AUTH_DB_PASS' (8)
18/03/2015 13:48:54 [ 2932] [WARN] [myuser@mydomain.com] /usr/share/z-push/backend/roundcubecontacts.php:68 mysql_connect(): Unknown MySQL server host 'ROUNDCUBE_AUTH_DB_HOST' (1) (2)
18/03/2015 13:48:54 [ 2932] [WARN] [myuser@mydomain.com] /usr/share/z-push/backend/roundcubecontacts.php:69 Use of undefined constant ROUNDCUBE_AUTH_DB_NAME - assumed 'ROUNDCUBE_AUTH_DB_NAME' (8)
18/03/2015 13:48:54 [ 2932] [WARN] [myuser@mydomain.com] /usr/share/z-push/backend/roundcubecontacts.php:69 mysql_select_db() expects parameter 2 to be resource, boolean given (2)
18/03/2015 13:48:54 [ 2932] [ERROR] [myuser@mydomain.com] Unable to open auth database

Here is the part I modified in the config.php
define('ROUNDCUBE_CONTACT_DB_NAME','roundcube'); //my db name is "roundcube"
define('ROUNDCUBE_CONTACT_DB_USER','roundcube'); // the db user name is also "roundcube"
define('ROUNDCUBE_CONTACT_DB_PASS','mysupersecretpasswordformysql');
define('ROUNDCUBE_CONTACT_DB_HOST','127.0.0.1'); // I have also tried localhost to no avail
define('BACKEND_PROVIDER', 'BackendRoundcubeContacts');

Also, to show that I am in fact using mysql with roundcube as the DB and username:
[root@myserver.local z-push]# mysql -u roundcube -p roundcube
Enter password:
Your MySQL connection id is 280
Server version: 5.5.42 MySQL Community Server (GPL) by Remi

mysql> use roundcube;
Database changed
mysql> show tables;
+---------------------+
| Tables_in_roundcube |
+---------------------+
| cache |
...

Thanks for the hard work on this!

Hi Steve,

Sorry it’s taken me so long to reply to your comment. In case you’re still looking for the answer to your problem, it’s that you need to set two lots of constants: ROUNDCUBE_AUTH_DB_* and ROUNDCUBE_CONTACT_DB_*. When I get the chance to go through the code properly and tidy it up I'll get rid of this requirement, as the AUTH constants are no longer required since our version uses IMAP for authentication...

Add new comment

(If you're a human, don't change the following field)
Your first name.
(If you're a human, don't change the following field)
Your first name.

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.