GMail Bot Control Framework ( gmail.py )
Code:#!/usr/bin/env python # # Studio Bebop Presents # GMail Bot Control Framework # By James Penguin (jamespenguin@gmail.com) # import urllib2, ClientForm, os opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) opener.addheaders = [(\'User-agent\', \'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)\')] urllib2.install_opener(opener) class GMail: def __init__(self, username, password): self.username = username self.password = password def login(self): url = \"http://gmail.com\" page = urllib2.urlopen(url) forms = ClientForm.ParseResponse(page, backwards_compat=False) form = forms[0] form[\"Email\"] = self.username form[\"Passwd\"] = self.password req = form.click() res = urllib2.urlopen(req).read() if \"refresh\" in res: return True return False def retrieve_unread_messages(self): \"\"\" Stops after encountering an entire page of read messages. \"\"\" url = \"http://mail.google.com/mail/?ui=html&zy=e\" page = urllib2.urlopen(url).read() url = page.split(\"url='\")[1].split(\"'\\\"\")[0] base_url = url.replace(\"&\", \"&\") messages = [] start = 0 while True: if not start: url = base_url else: url = base_url + \"&st=%d\" % start page = urllib2.urlopen(url).read() page = page.split(\"\") if len(page) == 1: break else: page = page[1:] for message in page: message_from = message.split(\"\")[1].split(\"\")[0] message_subject = message.split(\"\")[1].split(\"\")[0] message_subject = message_subject.lstrip() message_subject = message_subject.rstrip() if message_subject.startswith(\"\"): message_subject = message_subject.split(\"\")[1] message_url = message.split(\"
©2011, copyright BLACK BURN
0 comments:
Post a Comment