Synchronising IMAP, ownCloud, Roundcube and Z-Push

In this post I describe how to link together IMAP email, ownCloud calendar and contacts, Roundcube contacts, and set up access to all of them via any mobile device that supports ActiveSync. They don’t all need to be on the same server, but you will need to use the same username and password for IMAP and ownCloud.

I’m assuming that you already have an IMAP server, Roundcube install and ownCloud install set up and working. There are plenty of good online guides out there covering the installation of each component. This article aims to describe how to combine all of them together, as that was the step where I wasn’t able to find a decent set of instructions.

Roundcube contacts ⇔ ownCloud contacts

First, we’re going to link your ownCloud contacts to Roundcube using CardDAV. The instructions below assume that your Roundcube installation lives in /usr/local/share/roundcube/, that you’re using MySQL for the backend, that your MySQL user is called roundcubeuser and your database is called roundcubedb. Replace these as appropriate using the values from your Roundcube’s config/config.inc.php file.

  1. cd /usr/local/share/roundcube/plugins/
  2. git clone https://github.com/blind-coder/rcmcarddav.git
  3. mv rcmcarddav carddav
  4. cd carddav/dbinit/
  5. mysql -u roundcubeuser -p roundcubedb < mysql.sql (enter the MySQL password when prompted).
  6. cd ..
  7. cp config.inc.php.dist config.inc.php
  8. curl -sS https://getcomposer.org/installer | php
  9. php composer.phar install

Now you need to edit the main Roundcube config file, config/config.inc.php. You’ll need to find the $config['plugins'] array and add 'carddav' to it. I also recommend editing plugins/carddav/config.inc.php and setting $prefs['_GLOBAL']['pwstore_scheme'] = 'encrypted'; so that your ownCloud password isn’t stored in a format that can easily be recovered. Now you should be able to log in to Roundcube as usual, go to Settings → CardDAV and enter the settings for your ownCloud install. The URL will look something like https://example.com:443/owncloud/remote.php/carddav/addressbooks/username/contacts/ – you can find the exact address by logging into your ownCloud account, selecting Contacts in the top left, clicking the cog in the bottom left, and clicking on the CardDAV link icon (it looks like two links from a chain). Congratulations! Your contacts are now shared between Roundcube and ownCloud and any existing ownCloud contacts should now be visible in Roundcube.

Mobile device ⇔ IMAP & ownCloud

Now we will set up ActiveSync using Z-Push. This part is more involved. The instructions assume that you’re using Debian or Ubuntu, if not then you may need to adjust the paths, package names and usernames appropriately.

  1. cd /usr/local/share
  2. git clone https://github.com/fmbiete/Z-Push-contrib.git
  3. mv Z-Push-contrib z-push
  4. mkdir /var/lib/z-push
  5. chown www-data /var/lib/z-push
  6. apt-get install php5-xsl libawl-php
  7. Edit the Z-Push config files as described on https://github.com/fmbiete/Z-Push-contrib/wiki/Example-Configuration. The values below may be helpful.

The default ownCloud URLs for CalDAV are as follows:
define('CALDAV_PATH', '/owncloud/remote.php/caldav/calendars/%u/');
define('CALDAV_PERSONAL', 'personal');
The default ownCloud URLs for CardDAV are as follows:
define('CARDDAV_PATH', '/owncloud/remote.php/carddav/addressbooks/%u/');
define('CARDDAV_DEFAULT_PATH', '/owncloud/remote.php/carddav/addressbooks/%u/contacts/');
Comment out the CARDDAV_GAL_PATH line.

Edit your Apache config to include the following:

<IfModule mod_alias.c>
Alias /Microsoft-Server-ActiveSync /usr/local/share/z-push/index.php
</IfModule>
<IfModule mod_php5.c>
php_admin_value include_path .:/usr/share/php:/usr/share/pear:/usr/share/awl/inc:
</IfModule>

If you’re not using mod_php5 then you’ll need to add /usr/share/awl/inc to PHP’s include_path by another means such as editing php.ini. Finally, run apache2ctl configtest to check that there aren’t any errors, and then service apache2 reload to load the new config. You can test it by going to https://example.com/Microsoft-Server-ActiveSync in your browser. You should be prompted to enter your username and password. If these are entered correctly you should see a message saying GET not supported.

Assuming that worked, you’re now ready for the final piece of the puzzle: connecting your mobile device. The following instructions are for iOS devices, but similar steps will work on Android devices and Windows Phones.

  1. Open Settings.
  2. Select Mail, Contacts, Calendars.
  3. Select Add Account.
  4. Choose Exchange for the type.
  5. Enter your email address, password and account description.
  6. If you get a message saying “Cannot Verify Server Identity”, hit Cancel.
  7. Enter your server’s name in the Server field (e.g. example.com).
  8. Ignore the domain and re-enter your username and password.
  9. Press Next.
  10. Leave all the options (Mail, Contacts, Calendars, Reminders, Notes) selected and press Save.

To do: autodiscover

I spent a while trying to set up autodiscover, but kept running into the behaviour described in https://github.com/fmbiete/Z-Push-contrib/issues/165. Unfortunately that bug report references a configuration variable that is no longer used, so the workaround they describe doesn’t help anymore. When I work out how to fix the error I will update this article.

Sources:
https://github.com/blind-coder/rcmcarddav/blob/master/INSTALL
https://z-push.org/svn/z-push/trunk/src/INSTALL
https://github.com/fmbiete/Z-Push-contrib/wiki/Example-Configuration

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.