Created
April 23, 2013 14:56
-
-
Save georgebyte/5444246 to your computer and use it in GitHub Desktop.
Python: Gmail Parser
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 imaplib | |
import StringIO | |
import rfc822 | |
obj = imaplib.IMAP4_SSL("imap.gmail.com", "993") | |
obj.login("[email protected]", "pass") | |
print obj.list() | |
obj.select("[Gmail]/Vsa po&AWE-ta") | |
m = obj.search(None, "ALL")[1][0] | |
alli = m.split() | |
print "Vseh mailov: %i" % len(alli) | |
f = open("addresses.txt", "wb") | |
for i, num in enumerate(alli): | |
print "\rPobiram: %i" % i, | |
typ, data = obj.fetch(num, "(RFC822.HEADER)") | |
header = data[0][1] | |
mh = rfc822.Message(StringIO.StringIO(header)) | |
addrs = [x[0] or x[1] for x in mh.getaddrlist("From")+mh.getaddrlist("To")+mh.getaddrlist("Cc") if x[0] or x[1]] | |
f.write("%s\n" % "\t".join(addrs)) | |
print "\rPobrano" | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment