ExternalAbook

Lisp:external-abook.el (ExternalAbook) is an interface to work with Mutt external query tools.

Any address book tools written for Mutt, can therefore be used from within Emacs.

The following example will integrate the Mac OS X address book with Gnus.

To begin, install Contacts. Contacts is a program that provides a command line interface to the Mac OS X address book. You can also install Contacts via MacPorts.

Next, place external-abook.el in your load path, and then:

    (require 'external-abook)
    (setq external-abook-command "contacts -lf '%%e\t%%n' %s")
    (eval-after-load "message" 
      '(progn 
         (add-to-list 'message-mode-hook 
                      '(lambda ()
                         (define-key message-mode-map "\C-c\t" 'external-abook-try-expand)))))

Now in message mode, start typing a name, and then C-c TAB will complete that name from your address book.

Of course, ExternalAbook doesn’t have to be used with Ressbo, any Mutt address book tool will work.

I’ve found that this contacts command works better:

    (setq external-abook-command "contacts -lSf '%%e\t\"%%n\"' '%s'")

By adding quotes, I avoid an SMTP issue when a contact’s name has strange characters in it. The -S is to avoid extra whitespace at the end of the name. – ZacharyPinter

This turns out not to work if the external query command prints more than two fields on output, like goobook. I ended up using a little wrapper script:

  #!/bin/sh
  # Run goobook with given args 
  # then strip all but first two fields from output
  goobook "$@" | cut -f 1,2

DanPoirier

Dan’s solution works well, but smtp from mu4e-compose sometimes fails if the name part is not quoted and contains commas (Lastname, Firstname). Also, goobok outputs an extra blank line. Replacing cut with (g)awk solves both problems: goobook “$@” | gawk -F’\t’ ‘/.+/ {print $1 “\t” “\””$2 “\””}’

--KaiArzheimer