So I happen to like davical a lot, and when using mutt it would be nice to use auto-completion from the CardDav-Data in my Davical-Database by pressing ctrl+t when composing a mail in mutt.
That's why I wrote this little utility, called davical_addressbook. You need ruby and ruby-dbi and ruby-pg and configure the following parameters in the script:
db_server = 'db.example.com'
db = 'davical'
user = 'davical_addressbook_reader'
pw = '12345'
Once this is done, you need to configure the postgres user davical_addressbook_reader to have read-only access to either the whole database or only the specific tables that I used in my query. Now you can use the script like this:
./davical_fetch.rb <username> <search-string>
firstname.lastname@example.org Wolfgang Hennerbichler 0680 1234567
This is mutt-friendly format. Now you can configure your .muttrc like this:
set query_command="~/helper_software/davical_addressbook/davical_fetch.rb wogri '%s'"
I know this is not secure, because you can define the username by hand, one could of course take environment variables and such (which is by no means more secure, by the way).
Now, when you compose a new e-mail in mutt, just press ctrl+t when composing the e-mail address and you will be rewarded with a search result of the characters you typed so far. You can of course (ab)use this utility for any other tasks, like name lookup on incoming calls for your asterisk voip setup and such.
Download the little program here: davical_fetch.rb