-
Notifications
You must be signed in to change notification settings - Fork 2
/
inbox2.psp
57 lines (50 loc) · 1.95 KB
/
inbox2.psp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<html>
<%@ /usr/bin/env python %>
<%
import mechanize
import re
from BeautifulSoup import BeautifulSoup
br = mechanize.Browser()
response = br.open("http://www.gmail.com")
loginForm = br.forms().next()
loginForm["Email"] = form['username']
loginForm["Passwd"] = form['passwd']
response = br.open(loginForm.click())
response2 = br.open("http://mail.google.com/mail/h/")
result = response2.read()
soup = BeautifulSoup(result)
frms = soup.findAll('form')
tempFrm = str(frms[1])
tempFrm = re.sub(r"<form.*>", "", tempFrm)
tempFrm = re.sub(r"<\/form>", "", tempFrm)
(soup.findAll('form'))[1].replaceWith(tempFrm)
soup2 = BeautifulSoup(str(soup))
trs = soup2.findAll('tr', {'bgcolor':'#ffffff'})
tempButtonLink = re.findall(r"\".*\"", str(soup2.base))
tempButtonLink2 = re.sub(r"\"", '', tempButtonLink[0])
buttonText = '''<form name="mailRead" value="form" action="getmail.psp" method="post"> <input type="hidden" name="username" value="''' + form['username'] + '''"> <input type="hidden" name="passwd" value="''' + form['passwd'] + '''"> <input type="hidden" name="url" value="'''
for tr in trs:
oldHtml = tr.contents[5]
href = re.findall(r"\"\?v=.*\"", str(oldHtml))
hrefLink = re.sub(r"\"", '', href[0])
buttonLink = tempButtonLink2+hrefLink
buttonUrl = buttonText+buttonLink
buttonUrl = buttonUrl + '''"> <input type="submit" value="Read Mail"> </form>'''
newHtml = re.sub(r"<a href.*>", buttonUrl, str(oldHtml))
tr.contents[5].replaceWith(newHtml)
trs2 = soup2.findAll('tr', {'bgcolor':'#E8EEF7'})
for tr in trs2:
oldHtml = tr.contents[5]
href = re.findall(r"\"\?v=.*\"", str(oldHtml))
hrefLink = re.sub(r"\"", '', href[0])
buttonLink = tempButtonLink2+hrefLink
buttonUrl = buttonText+buttonLink
buttonUrl = buttonUrl + '''"> <input type="submit" value="Read Mail"> </form>'''
newHtml = re.sub(r"<a href.*>", buttonUrl, str(oldHtml))
tr.contents[5].replaceWith(newHtml)
soup2.base.replaceWith(".")
result2 = soup2.prettify()
%>
<h1>Your GMail Inbox:</h1>
<%=result2%>
</html>