2009-08-16

managing e-mail addresses with bbdb

BBDB, the Insidious Big Brother Database is an Emacs addressbook application that works particularly well with e-mail. It's one of the classic emacs packages, written in 1991 by Jamie Zawinski.

Personally, I do not use BBDB as a general address book. Instead, I use it to harvest the e-mail addresses of the people that send me mail, so that the next time I'd like to send e-mail, I can auto-complete the names / e-mail addresses. If you're not using some emacs-based email client, BBDB might not be that useful in practice.

Note that other people are using BBDB for much more, see the Emacswiki-entry for some examples of that. Here, I just give some basics to get you started; please refer to the fine manual for all the details.

configuration

So, after you've installed bbdb (just follow the instructions; alternatively Ubuntu/Debian users can simply install the bbdb package), we can add the following to .emacs to set it up:

(setq bbdb-file "~/.emacs.d/bbdb")           ;; keep ~/ clean; set before loading
(require 'bbdb) 
(bbdb-initialize)
(setq 
    bbdb-offer-save 1                        ;; 1 means save-without-asking

    
    bbdb-use-pop-up t                        ;; allow popups for addresses
    bbdb-electric-p t                        ;; be disposable with SPC
    bbdb-popup-target-lines  1               ;; very small
    
    bbdb-dwim-net-address-allow-redundancy t ;; always use full name
    bbdb-quiet-about-name-mismatches 2       ;; show name-mismatches 2 secs

    bbdb-always-add-address t                ;; add new addresses to existing...
                                             ;; ...contacts automatically
    bbdb-canonicalize-redundant-nets-p t     ;; x@foo.bar.cx => x@bar.cx

    bbdb-completion-type nil                 ;; complete on anything

    bbdb-complete-name-allow-cycling t       ;; cycle through matches
                                             ;; this only works partially

    bbbd-message-caching-enabled t           ;; be fast
    bbdb-use-alternate-names t               ;; use AKA


    bbdb-elided-display t                    ;; single-line addresses

    ;; auto-create addresses from mail
    bbdb/mail-auto-create-p 'bbdb-ignore-some-messages-hook   
    bbdb-ignore-some-messages-alist ;; don't ask about fake addresses
    ;; NOTE: there can be only one entry per header (such as To, From)
    ;; http://flex.ee.uec.ac.jp/texi/bbdb/bbdb_11.html

    '(( "From" . "no.?reply\\|DAEMON\\|daemon\\|facebookmail\\|twitter")))
)

This will set up BBDB for you. I have commented the various settings; you can of course get more information for each of them by putting your cursor on them (in emacs) and issuing C-h v.

integration with e-mail clients

Another important part is the integration with e-mail - which is why I am using BBDB in the first place.

As I mentioned before, I am using the wonderful Wanderlust e-mail client for emacs, and you can easily integrate it with BBDB by putting the following in your .wl-file:

(require 'bbdb-wl)
(bbdb-wl-setup)

;; i don't want to store addresses from my mailing folders
(setq 
  bbdb-wl-folder-regexp    ;; get addresses only from these folders
  "^\.inbox$\\|^.sent")    ;; 


(define-key wl-draft-mode-map (kbd "<C-tab>") 'bbdb-complete-name)

For gnus, you'd use something like:

(add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)

(I am not using gnus myself, feel free to add you setup in the comments)

The BBDB-manual has the details for some other mail clients as well.

Use

So, we have everything set up now – but how does it work? Well, whenever you read e-mails, BBDB stores the various e-mail addresses. Whenever you write an e-mail, you can complete the names with M-x bbdb-complete-name, by default bound to M-TAB. This keybinding conflicts with many window managers, which already use M-TAB (Alt-TAB) for window switching. So, it's useful to rebind it to something else, for example C-TAB (I already did that for Wanderlust, in the example above).

I don't use BBDB too much directly, but you can manipulate the address; first display one with M-x bbdb-display-address, they you can edit a field by pressing 'e', 'd' for deleting the field or record, C-o for adding a new field and so on – see the whole list.

14 comments:

Evolve said...

Nice article. I had just posted a how-to for importing OSX addresses into bbbdb at /usr: Importing OSX addresses into BBDB

martinez said...

Zawinski, not Zawinksi ;)

J. Aaron Farr said...

Thanks for writing this. I've been meaning to better configure my use of bbdb but haven't gotten around to it yet. You saved me some time!

Robert said...

Sorry to ask a somewhat off-topic question. You say that you use the wonderful wanderlust email client. How did you choose it?

In particular, is there some reason you chose Wanderlust over Mew, which seems similar (and possibly better-maintained)?

I am trying to choose my own shiny new emacs mail reader...

djcb said...

@Robert: about wanderlust - what I needed was a mailer that can deal with my existing Maildirs, and change them in-place (ie., no separate spool files like gnus has).

AFAIK, Mew does not support that. And I am quite happy with it.

Note that WL is not really unmaintained, although things are a bit slow.

Ian Yang said...

Also can use dbus-call-method to send notification to notification-daemon.

ramestica said...

still banging my head here trying to use bbdb within wanderlust. I just checked out and installed wanderlust from cvs (assuming that the tarball I was using was too old), but I still cannot get it right.

In your config example you have

(define-key wl-draft-mode-map (kbd "") 'bbdb-complete-name)

however, emacs will complain at startup missing the definition for wl-draft-mode-map. I see that in one place where that map is installed is in wl-mule.el. But after installing wl-mule did not get to my installation directory. Do I need wl-mule.el? Why is it that wl-draft-mode-map is missing for me?

djcb said...

@ramestica: well, the example is supposed be part your .wl file, which should have the needed incantations.

I think what you're missing here is:
(require 'wl-draft)

Does it work if you put that before this define-key part?

ramestica said...

nope, it does not work. But if instead of require wl-draft I copy wl-mule.el from the source to my installation directory then emacs will start okay. I know that what I'm doing is like swinging my arms in darkness. Why is that wl-mule.el does not get installed? what is supposed to provide? I'm looking at this file just because it defines wl-draft-mode-map which was in the example I'm trying to use.
Thanks

ramestica said...

okay, installed the latest bbdb from cvs and added the following to wl-draft-mode-hook:

(local-set-key "\C-t" 'complete-bbdb)

this gives a fairly usable way for autocompleting addresses in the draft buffer.

ArneBab said...

Since your info here is darn useful (I just switched to wanderlust myself, prompted by your post — but stalling for quite some time till I really did the switch), are your code snippets available under the GPL?

djcb said...

@ArneBab: the snippets in emacs-fu posts (at least the ones I wrote myself) are the public domain.

external packages may have different licenses, but mine are usually GPLv3; simply check the header in that case.

Anonymous said...

I'm very amused by all the using Wanderlust comments. How the hell do you get it? Every download link at http://www.gohome.org/wl/#GET is either broken or unreachable. A really great app - I think not, CRAP.

djcb said...

@Anonymous: if you're on linux, the easiest is probably through some package your distribution provides. e.g 'wl' or 'wl-beta' on debian/ubuntu.