Synchronize contacts between Android and Thunderbird
As of today, most phones come with Android installed, which makes them "smart".
Unfortunately, it seems that being smart means that simple operations are no longer possible.
Everything needs to be connected, but to be connected one needs a permanent connection to the internet, send data to unknown servers, hope that it does not get saved in unknown locations or misused, and then send it back to our PC. And of course, it needs some app, and better be it compatible with our computer (or phone), as it uses some closed protocol. If unlucky, it requires some account, unnecessary permissions, and who knows what else.
Once upon a time I could connect my phone to my PC with a cable, and synchronize all contacts in a matter of seconds. Those were different times, most programs did not require or even acknowledged something like the existence of the internet. So if they were also a proprietary blob, it would have been very improbable for them to leak any information.
Granted, it might not have worked on all phones, but it did its job pretty well. As of today, something like that is not possible on Android.
It is not possible to access the data from any applications, contacts included. It is not possible to synchronize the content of the "Contacts" app, with something on the file system. It is (AFAIK), not possible to trigger the export and import action through other programs.
So one needs to export, merge and import by hand all the time, or synchronize with some external provider.
Most people might not care, but I saved a lot of personal information in my contacts. Things like birthdays, phone numbers, email addresses, postal addresses, maybe a picture, links to different social accounts, some notes sometimes even something like their IBAN, social number, other private pieces of information, and so on.
I would not like most of my personal data to be given away without my consent, especially for no reason, and naturally, I try to do the same with the data of other people.
So using an external provider has never been an option for me, but fortunately, I found how to sync all the contacts without making them leave my home.
Thunderbird
Thunderbird has its own address book, but it lacks many useful functionalities. Synchronization is one of them. The add-on CardBook has everything one might want for managing contacts, even synchronizing with .vcf
files on the file system, or from a server.
Radicale
Radicale is the central piece to make everything work, as it works as a server, which makes synchronization possible.
My current configuration is
# .config/radicale/config
[storage]
filesystem_folder = <where to store data>
[server]
hosts = 0.0.0.0:5232, [::]:5232
max_connections = 5
# 100 Megabyte
max_content_length = 100000000
# 30 seconds
timeout = 30
[auth]
type = htpasswd
htpasswd_filename = ~/.config/radicale/pass.local
# encryption method used in the htpasswd file
htpasswd_encryption = plain
and the pass.local
file:
<username>:<password>
To start the server, simply type
python3 -m radicale
Once Radicale is running, it is possible to connect to it and synchronize all contacts.
On Android, DAVx⁵ is probably the best program for synchronizing contacts and calendars.
As long as my phone can contact the PC (for example because they are connected to the same network), they can synchronize its content. Sometimes I wish using a cable would still be a thing, but I’m happy enough with this approach.
Unfortunately, if the name of the PC does not get resolved, it’s not simply possible to change DAVx⁵ the name of the host with its IP address "on the fly". So synchronizing might not always work, depending on the network.
Raspberry Pi, vdirsyncer
, and khard
My current setup does actually look a little different.
At home I have, for various reasons, a PC running nearly all the time (a Raspberry Pi).
Thanks to it
-
I can synchronize calendars and contacts without having both my computer and my phone on at the same time
-
I know that the data does not leave my personal network, and/or control on what devices it lands
I also wanted to access and manipulate my contacts outside of the mail client. While vCard files are simple text files, it is nice to have something that would verify if the data has the right structure.
khard works well and is simple to configure. This program is completely optional, as it does not participate in the synchronization process.
My current configuration looks like the following
# ~/.config/khard/khard.conf
[addressbooks]
[[contacts]]
path = ~/comunication/contacts
[general]
debug = no
default_action = list
editor = editor
[contact table]
display = last_name
group_by_addressbook = no
reverse = no
show_nicknames = no
show_uids = yes
sort = last_name
localize_dates = yes
[vcard]
private_objects = Jabber, Skype, Twitter, GitHub, Facebook, Linkedin
preferred_version = 4.0
And all my contacts are saved inside ~/communication/contacts
The CardBook addon permits to synchronize to a local directory, so I pointed it to ~/communication/contacts
.
What’s left is thus synchronizing the local directory with Radicale, which runs on the Raspberry Pi.
vdirsync does this job neatly and is also relatively simple to use.
My configuration looks like
# ~/.config/vdirsyncer/config
[general]
status_path = "~/.vdirsyncer/status/"
## Contacts
[pair my_contacts]
a = "my_contacts_local"
b = "my_contacts_remote"
# folders where contacts are actually stored
collections = ["contacts"]
[storage my_contacts_local]
type = "filesystem"
path = "~/comunication"
fileext = ".vcf"
[storage my_contacts_remote]
type = "carddav"
url = <url>:5232
username = <username>
password = <password>
For synchronizing the computer I simply execute
vdirsyncer discover && vdirsyncer sync;
Putting it under revision control
The WebDAV protocol already has a versioning scheme and capabilities for handling (some) conflicts.
Unfortunately, it does not always do the intended action. This is one of the reasons I put ~/communication/contacts
under revisions control. It gives me two features at once
-
a backup mechanism (in case, for example, I delete by accident a contact, or edit it incorrectly)
-
a potentially manual merge mechanism
Splitting an existing vCard file
When exporting contacts from some programs, the Android contact application too, they will generate a single .vcf
file with all contacts.
Having only one giant file makes it more difficult to manage changes.
Thus I’ve forked split-vcf-file and updated to split vcard. It converts a single .vcf
/.vcard
file to one vCard per contact.
If you have questions, comments, or found typos, the notes are not clear, or there are some errors; then just contact me.