Skip to content

Instantly share code, notes, and snippets.

@vitorio
Created March 30, 2015 01:17
Show Gist options
  • Save vitorio/a6c63a10af8fc8968278 to your computer and use it in GitHub Desktop.
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…
# 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)
@vitorio
Copy link
Author

vitorio commented Jan 30, 2022

@theojepsen glad it was useful! Thanks for providing an additional one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment