Created
February 4, 2015 12:08
-
-
Save nfelger/21b690099e0e68ad5f83 to your computer and use it in GitHub Desktop.
Get all domains an mbox has received email from
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
import mailbox | |
from collections import defaultdict | |
from flanker import mime | |
from flanker.addresslib import address | |
mbox_path = '...' | |
mbox = mailbox.mbox(mbox_path) | |
domains = defaultdict(int) | |
items = mbox.iteritems() | |
for msg in items: | |
raw_msg = msg[1].as_string() | |
parsed = mime.from_string(raw_msg) | |
from_header = parsed.headers['From'] | |
from_domain = address.parse(from_header).hostname | |
domains[from_domain] += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment