Jump to content
hozarares

GMail Bot Control Framework

Recommended Posts

Posted

#!/usr/bin/env python

# GMail Bot Control Framework

# hush hush time time

#

# Modified by RoCracker

#

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(\"<tr bgcolor=\\\"#ffffff\\\">\")

if len(page) == 1:

break

else:

page = page[1:]

for message in page:

message_from = message.split(\"<b>\")[1].split(\"</b>\")[0]

message_subject = message.split(\"</font></font>\")[1].split(\"</b>\")[0]

message_subject = message_subject.lstrip()

message_subject = message_subject.rstrip()

if message_subject.startswith(\"<b>\"):

message_subject = message_subject.split(\"<b>\")[1]

message_url = message.split(\"<a href=\\\"?\")[1].split(\"\\\"\")[0]

message_url = \"%s&%s\" % (base_url, message_url)

messages.append([message_from, message_subject, message_url])

start += 50

return messages

def retrieve_message(self, url):

page = urllib2.urlopen(url).read()

return page

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...