Inspired by an e-mail-based customer relationship management system briefly described by Daniel Charles of digital ketchup at Shoeless Joe’s last Friday, I decided to hack together a system that would allow me to see the notes from my contact database (aptly named the Big Brother Database, or BBDB) when I write e-mail using the Gnus mail client in Emacs.
The first thing I needed to build, of course, was something that
removed my notes from outgoing messages. People really don’t need to
see the kinds of notes I keep on them. ;) Well, they’re fairly
innocuous notes: how we met and what they’re interested in, usually,
although sometimes I’ll have notes on people’s food preferences or
shoe sizes. I’ve recently started keeping track of the subjects of
e-mail I send them, too.
(defun sacha/gnus-remove-notes ()
"Remove everything from --- NOTES --- to the signature."
(when (re-search-forward "^--- NOTES ---" nil t)
(let ((start (match-beginning 0))
(end (and (re-search-forward "^--- END NOTES ---") (match-end 0))))
(delete-region start end))))
(add-hook 'message-send-hook 'sacha/gnus-remove-notes)
Then it was easy to write another function that composed individual
messages to all the people currently displayed in the BBDB buffer,
adding notes to each message.
(defun sacha/gnus-send-message-to-all (subject)
"Compose message to everyone, with notes."
(interactive "MSubject: ")
(let ((records bbdb-records))
(when (bbdb-record-net (caar records))
(bbdb-send-mail (caar records) subject)
(when (bbdb-record-notes (caar records))
(insert "\n--- NOTES ---\n"
(bbdb-record-notes (caar records))
"\n--- END NOTES ---\n"))))
(setq records (cdr records)))))
I use BBDB to display only the people I want to e-mail, then I call
M-x sacha/gnus-send-message-to-all and specify a message subject. This
creates a gazillion message buffers which I can then edit. If I feel
particularly paranoid, I can remove the notes section myself with C-c
C-z (message-kill-to-signature), but sacha/gnus-remove-notes does it
as long as it’s in message-send-hook.
This code works particularly well with these other customizations:
It supersedes More Emacs fun: Composing mail to everyone with notes.
On Technorati: emacs, bbdb, gnus, crm, networking, pimpmyemacs