Tuesday, October 5, 2010

Extracting e-mail addresses from Apple Mail

Ever wanted to extract every e-mail address you've ever sent or received to from Apple Mail? With a bit of *nix-fu, it's fairly straightfoward.

Just open up a terminal, and run the following 3 commands in order (the second two will take some time to execute).


cd ~/Library/Mail

find . -name *.emlx -print0 | xargs -0 perl -wne'while(/[\w\.]+@[\w\.]+/g){print "$&\n"}' * > ~/Desktop/extracted_emails.txt

sort ~/Desktop/extracted_emails.txt | uniq > ~/Desktop/sorted_emails.txt


You'll now have a file on your desktop with a sorted, de-duped list of e-mail addresses.

0 comments:

Post a Comment