Skip to content

Instantly share code, notes, and snippets.

@georgebyte
Created April 23, 2013 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save georgebyte/5444246 to your computer and use it in GitHub Desktop.
Save georgebyte/5444246 to your computer and use it in GitHub Desktop.
Python: Gmail Parser
import imaplib
import StringIO
import rfc822
obj = imaplib.IMAP4_SSL("imap.gmail.com", "993")
obj.login("xxx@gmail.com", "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