Create an address book from every message in your sent mail folder
July 28th, 2006 | Filed under Code snippets, Bash scriptsJust noticed that Thunderbird has a new message filtering criteria: “From: email address in my address book.”
That, coupled with Thunderbird’s ability to add the address of anyone you send a message to automatically to your address book, opens up the possibility of filtering mail from people that you’ve communicated with before into “Known” folder, and mail from folks you don’t into “Unknown” folder.
(I’ve been jonesing for something like this for awhile; a helpful Lifehacker commenter pointed out that it’s possible.)
So to get this system going, first I had to populate my address book with all the email addresses I’ve sent mail to before. This one-liner on my IMAP server’s sent-mail file, cobbled together with a lot of help from this Ask Metafilter thread, does the trick:
grep "^To: " mail/sent-mail | grep "@" | \
sed 's,.* <*\([^ ]*@[^ >]*\).*,\1,’ | \
sort | uniq -i | sed ’s/,.*$//’ > correspondents.txt
(Mind you, this Python version is a lot more elegant, but it kept timing out on me. I have a big sent-mail folder.)
From there, import correspondents.txt as a new address book and set up your filter in Thunderbird.
Awesome.
(Also only interesting to me: The ~10k messages I sent from my personal email address in the last 2 years were to less than 2000 recipients, for an average of about 5 messages per correspondent.)
$ wc -l correspondents.txt
1823 correspondents.txt