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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/contacts/hotmail.rb', line 13
def real_connect
data, resp, cookies, forward = get(URL)
old_url = URL
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
postdata = "PPSX=%s&PwdPad=%s&login=%s&passwd=%s&LoginOptions=2&PPFT=%s" % [
CGI.escape(data.split("><").grep(/PPSX/).first[/=\S+$/][2..-3]),
PWDPAD[0...(PWDPAD.length-@password.length)],
CGI.escape(login),
CGI.escape(password),
CGI.escape(data.split("><").grep(/PPFT/).first[/=\S+$/][2..-3])
]
form_url = data.split("><").grep(/form/).first.split[5][8..-2]
data, resp, cookies, forward = post(form_url, postdata, cookies)
if data.index("The e-mail address or password is incorrect")
raise AuthenticationError, "Username and password do not match"
elsif data != ""
raise AuthenticationError, "Required field must not be blank"
elsif cookies == ""
raise ConnectionError, PROTOCOL_ERROR
end
old_url = form_url
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
=begin
if data =~ %r{action="(.*?)"}
forward = $1
puts forward
napexp = CGI.escape(data.to_s[/id="NAPExp" value="(.*?)"/][19...-1])
nap = CGI.escape(data.to_s[/id="NAP" value="(.*?)"/][16...-1])
anon = CGI.escape(data.to_s[/id="ANON" value="(.*?)"/][17...-1])
anonexp = CGI.escape(data.to_s[/id="ANONExp" value="(.*?)"/][20...-1])
t = CGI.escape(data.to_s[/id="t" value="(.*?)"/][14...-1])
postdata = "NAPExp=%s&NAP=%s&ANON=%s&ANONExp=%s&t=%s" % [ napexp, nap, anon, anonexp, t ]
puts postdata
data, resp, cookies, forward, old_url = post(forward, postdata, cookies, old_url) + [forward]
end
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
=end
data, resp, cookies, forward = get("http://mail.live.com/mail", cookies)
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
if (not old_url.grep(/MessageAtLogin.aspx/).first.nil?)
viewState = data.split(/>\s*?</).grep(/__VIEWSTATE/).first[/value=\".+?\"/][7..-2]
eventValidation = data.split(/>\s*?</).grep(/__EVENTVALIDATION/).first[/value=\".+?\"/][7..-2]
continueValue = data.split(/>\s*?</).grep(/TakeMeToInbox/).first[/value=\".+?\"/][7..-2]
postdata = "%s=%s&%s=%s&%s=%s" % [
"__VIEWSTATE", CGI.escape(viewState),
"__EVENTVALIDATION", CGI.escape(eventValidation),
CGI.escape("TakeMeToInbox"), CGI.escape(continueValue)
]
data, resp, cookies, forward = post( old_url, postdata, cookies, old_url )
until forward.nil?
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
end
end
@domain = URI.parse(old_url).host
@cookies = cookies
rescue AuthenticationError => m
if @attempt == 1
retry
else
raise m
end
end
|