Created
March 30, 2015 01:17
-
-
Save vitorio/a6c63a10af8fc8968278 to your computer and use it in GitHub Desktop.
So, let's say you have an mbox full of mail and you want to get all the To: addresses out of it. And let's say you've seen a bunch of intimidating complicated examples like http://stackoverflow.com/questions/7166922/extracting-the-body-of-an-email-from-mbox-file-decoding-it-to-plain-text-regard or http://nbviewer.ipython.org/github/furukama/Mini…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# via http://stackoverflow.com/questions/14903664/determine-unique-from-email-addresses-in-maildir-folder | |
import mailbox | |
import email | |
mbox = mailbox.mbox('DADEOL/AOL Mail sorted/Saved.DADEOL Sent.mbox') | |
uniq_emails = set(email.utils.parseaddr(msg['to'])[1].lower() for msg in mbox) | |
for a in uniq_emails: | |
print a | |
print len(uniq_emails) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for that example! I made a few changes: