Created
August 8, 2011 18:38
-
-
Save orenmazor/1132389 to your computer and use it in GitHub Desktop.
lightweight gmail downloader
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
# quick hack to download a bunch of gmail emails for testing. this is the easiest way to do this the hardway. | |
from poplib import POP3_SSL, error_proto | |
from sys import argv | |
from time import time | |
from argparse import ArgumentParser | |
def gmaildump(username, password, quantity): | |
gmail = POP3_SSL("pop.gmail.com", 995) | |
# gmail.set_debuglevel(5) | |
gmail.user(username) | |
gmail.pass_(password) | |
gmail.getwelcome() | |
gmail.stat() | |
inbox = gmail.list()[1] | |
for message_index in range(int(quantity)): | |
#I don't really care about individual emails, so I don't track their names | |
f = open(str(time()), 'w') | |
f.write("\r\n".join(gmail.retr(str(message_index+1))[1])) | |
f.close() | |
if __name__ == '__main__': | |
#overkill, but pretty | |
argparser = ArgumentParser("Dump a bunch of gmail emails") | |
argparser.add_argument('username') | |
argparser.add_argument('password') | |
argparser.add_argument('quantity',type=int,help="The number of emails to download. Oldest first") | |
args = argparser.parse_args() | |
try: | |
gmaildump(args.username,args.password,args.quantity) | |
except error_proto as unfortunate: | |
print unfortunate.message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment