lbdb and mutt
I recently added an outgoing mail filter to capture the email addresses of people I write email to. This saves me time on adding them to my address book manually.
I ran into Mark’s Mutt Fan and Tip page and was pleased by the description of lbdb. I then found a way to write an outgoing filter to capture email addresses as I send mail… I wasn’t really interested in lbdb holding the forged SPAM addresses.
The first script will pass emails to lbdb and sendmail.
$ cat bin/mysendmail
#!/bin/bash
tee >(lbdb-fetchaddr -a)|/usr/lib/sendmail -oem -oi $@
aside: I never knew about the >() and <(), but ever since I read the above article, I've been using it a lot with git.
For example: vimdiff <(git-cat -r old-revision somefile) somefile.
This script corrects for the fact that lbdbq shows entries in the reverse order… I want the most recent to be on top.
$ cat bin/mylbdbq
#!/bin/bash
(lbdbq "$@" | tee >(head -n 1 >&2) 2>/dev/null | grep -v ^lbdbq:.*matches | tac) 2>&1
BTW, if there is a better way to reverse the order of lines 2..N in bash, please let me know. I realize the above is ugly.
Finally, this is the mutt configuration.
$ grep -e mysendmail -e mylbdbq .muttrc
set sendmail="~/bin/mysendmail"
set query_command="~/bin/mylbdbq %s"
Now you have to write some email and populate your .lbdb/m_inmail.list
file.
Finally when your lbdb is non-empty you can use ctrl-t
on the address entry line to complete from lbdb.
Pressing TAB
will complete from the mutt_aliases file as before.