Wednesday 15 July 2009

Extracting addresses from a Maildir folder

From time to time, one of our users wants to send an email to all the people who's addresses are in one of her mailboxes. Our IMAP setup uses Maildir folders as the back end, which have the very nice feature of each mail being a separate file.

With a little appropriate use of some linux command line tools, the following will give a list of the senders addresses that are found in the given Maildir folder:

grep Return-path ~username/Maildir/.mailboxname/cur/* | sed -e 's/^.*<//' | sed -e 's/>//' | sort -u > ~/email.addr

replace username with the user in question and mailboxname with the appropriate mailbox and you will have a list of addresses in email.addr