Owncloud and pycarddav

The last night I spent three hours cutting my contacts out of the cold, harsh claws of the google empire. And what kind of tiring cutting it was.

During the last years the Gmail integration into Android has improved more and more. Especially the contact synchronization feature was the main reason to create a Gmail account. It still troubled me to hand all those information to “the kraken”, but the synchronization outweighs the benefits.

Owncloud has also slightly improved over the years and now also offers the synchronization. Reason enough for me to switch and break free from the last connection and cut out the last bit of my data from the data-silos.

Exporting the contacts from Gmail is simple. But the export format neither supports the contact categories nor the images assigned to any contact. At least the issue with the images might be due the format (vcard) and not (entirely) the fault of google. Getting it into Owncloud is rather simple as well.

Just importing it into the address-book will work. So the final sorting was about adding the contact images back in and re-creating the categories.

So on the client side some interface is needed to query the data from the Owncloud address book. Since Owncloud provides a CardDAV API, pyCardDAV helps out and makes the stored contact information locally available.

Setup

This setup follows the setup through the source packages. I had problems with the deb packages to install. They failed and created unresolved dependencies.

Requirements

Install the following packages. This comes from here, but one additional packages has been added in order to make the python script install correctly.

$ sudo aptitude install python python-urwid python-xdg python-argparse python-lxml \
  libsqlite0 python-crypto python-dateutil python-gevent python-greenlet \
  python-oauthlib python-requests python-sqlite python-urwid python-vobject \
  python-argparse python-setuptools

pyCardDAV

$ wget http://lostpackets.de/pycarddav/downloads/pyCardDAV-0.7.0.tar.gz
$ tar -xzf pyCardDAV-0.7.0.tar.gz
$ cd pyCardDAV-0.7.0
$ sudo python setup.py install

Configuration

$ CONFIGDIR=~/.config/pycard
$ mkdir -p $CONFIGDIR && chmod 700 $CONFIGDIR
$ cp pycard.conf.sample $CONFIGDIR/pycard.conf
[Account work]
# DAV credentials. Please note that the password is written in plain
# text here. If the password is missing, it will be claimed at
# synchronization time.
user: <owncloud-user>
passwd: *********

# The path to the CardDAV resource.
resource: https://<serverpath>/remote.php/carddav/addressbooks/<owncloud-user>/<addressbook-name>

# If verify is set to False, no SSL Certificate checks are done at all. Please
# be aware of the security implications. The default value is True You can also
# set verify to a path to your CAcert file
#verify: True
verify: false

[sqlite]
# The location of the local SQLite contacts database.
# Defaults to $XDG_DATA_HOME/pycard/abook.db
#path: ~/.pycard/abook.db

[query]
# select where to search when querying, possible values are:
# vcard, name, fname or allnames (which includes both the name and the full
# name). Default is vcard, which search in all the fields but is slower.
where: vcard

[default]
debug: False
  • [Account <name>]

    Name of the account - can be whatever. You can also define multiple accounts in the config file. See the original example file for details.

  • user/passwd

    The user and password to use for the Owncloud access. Keep in mind that this is plain text here. Leaving the password blank will trigger a request when syncing. Since the syncing only happens when running pycardsyner manually (or via cron), this is totally fine.

  • resouce

    The access path to the CardDAV in owncloud. The correct path is inside the address-book in the Owncloud-instance and can be copied from there.

  • verify

    This is _true_ by default. I did not figure out the SSL import yet, so I set this to _false_ to get it working initially.

  • [sqlite]

    You need this entry even if it is nothing really configured there. Otherwise no data will be locally stored.

Testing

Before the initial run, we need to get the database filled with the contacts from the Owncloud address-book. Run pycardsyncer. Depending on the number of contacts this can take a couple of minutes.

$ pycardsyncer
$ CardDAV password (account work):

Running now the final query, this should provide some results:

$ pc_query Test
searching for Test...

Name: Testuser
TEL (HOME): +47 987654321
EMAIL (WORK): someone@example.com

Done.

Mutt

Finally the mutt integration left. Previously I have used Goobook, now the key-binding for the query in the mutt configuration needs to be changed to execute a different query.

# muttrc
...
# Use TAB for goobook autocomplete
#set query_command="goobook query '%s'"
# Use TAB for PyCardDAV autocomplete
set query_command="/usr/local/bin/pc_query -m '%s'"
bind editor <Tab> complete-query
...

Phone

On the phone side the freeware app CardDAV-Sync creates an input for syncing the contacts easily.

The setup is that simple that I spare the detail setup. You only need the login credentials and the CardDAV url (used about as resource in the pyCardDAV configuration file). For details check here.

Sources