Last year, I brought you 19 days of new (to you) productivity tools for 2019. This year, I'm taking a different approach: building an environment that will allow you to be more productive in the new year, using tools you may or may not already be using.
Open source tools for contact management
In previous articles in this series, I explained how to synchronize your mail and calendars locally. Hopefully, that has sped up accessing your mail and calendar. Now I'll talk about contacts, which you can use to send mail and calendar invites.
I have collected a lot of email addresses over the course of my, well, life so far. And managing all that data can be a bit of a pain. There are web-based services, but they aren't as fast as a local copy.
A few days ago, I talked about vdirsyncer for managing calendars. Vdirsyncer also handles contacts using the CardDAV protocol. Vdirsyncer supports google_contacts and carddav to do contact synchronizations in addition to the filesystem store it uses for calendars, but the fileext setting will change, so you won't be trying to store contacts in calendar files.
I added a configuration block to the config file and mirrored my contacts from Google; extra steps are required to set it up. Extra steps are required to set it up. Once the Google setup is complete, the configuration is pretty simple:
a = "googlecard"
b = "localcard"
collections = ["from a", "from b"]
conflict_resolution = "a wins"
type = "google_contacts"
token_file = "~/.vdirsyncer/google_token"
client_id = "my_client_id"
client_secret = "my_client_secret"
type = "filesystem"
path = "~/.calendars/Addresses/"
fileext = ".vcf"
Now when I run vdirsyncer discover, it finds my Google contacts, and vdirsyncer sync copies them to my local machine. But again, that's only half the story. Now I want to read and use the contacts. Enter khard and abook.
Why two applications? Each has its own use case, and in this case, more is better. Khard does for addresses what khal does for calendar entries. You'll probably want to install the latest release via pip if your distribution ships an older version. Once khard is installed, you need to create ~/.config/khard/khard.conf because khard doesn't have a nifty configuration wizard the way khal does. Mine looks like this:
path = ~/.calendars/Addresses/default/
debug = no
default_action = list
editor = vim, -i, NONE
merge_editor = vimdiff
display = first_name
group_by_addressbook = no
reverse = no
show_nicknames = yes
show_uids = no
sort = last_name
localize_dates = yes
preferred_version = 3.0
search_in_source_files = yes
skip_unparsable = no
This defines the source address book (and gives it a friendly name), as well as what to display and what do use to edit contacts. Running khard list will list all the entries, and khard list <email@example.com> will search for a specific entry. If you want to add or edit an entry, the add and edit commands launch the configured editor with the same basic template, the only difference being that the add template will be blank.
Abook requires you to import and export VCF files but offers some nice features for lookups. To convert your files to the abook format, first install abook and create the ~/.abook default directory. Now tell abook to parse all the files and put them into the ~/.abook/addresses file:
apt install abook
ls ~/.calendars/Addresses/default/* | xargs cat | abook --convert --informat vcard --outformat abook > ~/.abook/addresses
Now run abook, and you'll have a very nice UI to browse, search, and edit the entries. Exporting them back to individual entries is a bit of a pain, so I do most of my edits with khard and have a cron job to import them into abook.
Abook can also search on the command line and has a lot of documentation about integrating it with mail clients. For example, you can use abook for lookups in the Notmuch email client alot by adding some information to the .config/alot/config file:
realname = Kevin Sonney
address = firstname.lastname@example.org
alias_regexp = kevin\+.+@sonney.com
gpg_key = 7BB612C9
sendmail_command = msmtp --account=Personal -t
# ~ expansion works
sent_box = maildir://~/Maildir/Sent
draft_box = maildir://~/Maildir/Drafts
type = abook
And there you have it: fast lookup of your contacts to go with your mail and calendars!