cardmagic-contacts 1.0.14 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/contacts/base.rb +1 -1
- data/lib/contacts/gmail.rb +2 -2
- data/lib/contacts/hotmail.rb +55 -109
- data/lib/contacts/plaxo.rb +2 -3
- metadata +1 -1
data/lib/contacts/base.rb
CHANGED
data/lib/contacts/gmail.rb
CHANGED
@@ -39,7 +39,7 @@ class Contacts
|
|
39
39
|
|
40
40
|
cookies = remove_cookie("GMAIL_LOGIN", cookies)
|
41
41
|
|
42
|
-
if data.index("Username and password do not match")
|
42
|
+
if data.index("Username and password do not match") || data.index("New to Gmail? It's free and easy")
|
43
43
|
raise AuthenticationError, "Username and password do not match"
|
44
44
|
elsif data.index("The username or password you entered is incorrect")
|
45
45
|
raise AuthenticationError, "Username and password do not match"
|
@@ -91,4 +91,4 @@ class Contacts
|
|
91
91
|
end
|
92
92
|
|
93
93
|
TYPES[:gmail] = Gmail
|
94
|
-
end
|
94
|
+
end
|
data/lib/contacts/hotmail.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class Contacts
|
2
2
|
class Hotmail < Base
|
3
|
-
URL = "
|
3
|
+
URL = "https://login.live.com/login.srf?id=2"
|
4
4
|
OLD_CONTACT_LIST_URL = "http://%s/cgi-bin/addresses"
|
5
5
|
NEW_CONTACT_LIST_URL = "http://%s/mail/GetContacts.aspx"
|
6
|
-
|
6
|
+
CONTACT_LIST_URL = "http://mpeople.live.com/default.aspx?pg=0"
|
7
7
|
COMPOSE_URL = "http://%s/cgi-bin/compose?"
|
8
8
|
PROTOCOL_ERROR = "Hotmail has changed its protocols, please upgrade this library first. If that does not work, report this error at http://rubyforge.org/forum/?group_id=2693"
|
9
9
|
PWDPAD = "IfYouAreReadingThisYouHaveTooMuchFreeTime"
|
@@ -11,7 +11,6 @@ class Contacts
|
|
11
11
|
|
12
12
|
def real_connect
|
13
13
|
data, resp, cookies, forward = get(URL)
|
14
|
-
|
15
14
|
old_url = URL
|
16
15
|
until forward.nil?
|
17
16
|
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
|
@@ -37,55 +36,16 @@ class Contacts
|
|
37
36
|
end
|
38
37
|
|
39
38
|
old_url = form_url
|
39
|
+
|
40
40
|
until forward.nil?
|
41
41
|
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
|
42
42
|
end
|
43
|
-
|
44
|
-
=begin
|
45
|
-
if data =~ %r{action="(.*?)"}
|
46
|
-
forward = $1
|
47
|
-
puts forward
|
48
|
-
napexp = CGI.escape(data.to_s[/id="NAPExp" value="(.*?)"/][19...-1])
|
49
|
-
nap = CGI.escape(data.to_s[/id="NAP" value="(.*?)"/][16...-1])
|
50
|
-
anon = CGI.escape(data.to_s[/id="ANON" value="(.*?)"/][17...-1])
|
51
|
-
anonexp = CGI.escape(data.to_s[/id="ANONExp" value="(.*?)"/][20...-1])
|
52
|
-
t = CGI.escape(data.to_s[/id="t" value="(.*?)"/][14...-1])
|
53
|
-
|
54
|
-
postdata = "NAPExp=%s&NAP=%s&ANON=%s&ANONExp=%s&t=%s" % [ napexp, nap, anon, anonexp, t ]
|
55
|
-
puts postdata
|
56
|
-
data, resp, cookies, forward, old_url = post(forward, postdata, cookies, old_url) + [forward]
|
57
|
-
end
|
58
|
-
|
59
|
-
until forward.nil?
|
60
|
-
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
|
61
|
-
end
|
62
|
-
=end
|
63
43
|
|
64
44
|
data, resp, cookies, forward = get("http://mail.live.com/mail", cookies)
|
65
45
|
until forward.nil?
|
66
46
|
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
|
67
47
|
end
|
68
|
-
|
69
|
-
# click on 'Contiune' if presented with the Hotmail Listened page
|
70
|
-
# look for the Submit button with a "TakeMeToInbox" name (this should work for other languages)
|
71
|
-
if (not old_url.grep(/MessageAtLogin.aspx/).first.nil?)
|
72
|
-
|
73
|
-
viewState = data.split(/>\s*?</).grep(/__VIEWSTATE/).first[/value=\".+?\"/][7..-2]
|
74
|
-
eventValidation = data.split(/>\s*?</).grep(/__EVENTVALIDATION/).first[/value=\".+?\"/][7..-2]
|
75
|
-
continueValue = data.split(/>\s*?</).grep(/TakeMeToInbox/).first[/value=\".+?\"/][7..-2]
|
76
|
-
|
77
|
-
# post back to the same url
|
78
|
-
postdata = "%s=%s&%s=%s&%s=%s" % [
|
79
|
-
"__VIEWSTATE", CGI.escape(viewState),
|
80
|
-
"__EVENTVALIDATION", CGI.escape(eventValidation),
|
81
|
-
CGI.escape("TakeMeToInbox"), CGI.escape(continueValue)
|
82
|
-
]
|
83
|
-
data, resp, cookies, forward = post( old_url, postdata, cookies, old_url )
|
84
|
-
until forward.nil?
|
85
|
-
data, resp, cookies, forward, old_url = get(forward, cookies, old_url) + [forward]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
48
|
+
|
89
49
|
@domain = URI.parse(old_url).host
|
90
50
|
@cookies = cookies
|
91
51
|
rescue AuthenticationError => m
|
@@ -97,7 +57,6 @@ class Contacts
|
|
97
57
|
end
|
98
58
|
|
99
59
|
def contacts(options = {})
|
100
|
-
return @contacts if @contacts
|
101
60
|
if connected?
|
102
61
|
url = URI.parse(contact_list_url)
|
103
62
|
data, resp, cookies, forward = get( contact_list_url, @cookies )
|
@@ -105,75 +64,62 @@ class Contacts
|
|
105
64
|
if resp.code_type != Net::HTTPOK
|
106
65
|
raise ConnectionError, self.class.const_get(:PROTOCOL_ERROR)
|
107
66
|
end
|
108
|
-
|
109
|
-
# we have to click on the Export Contacts button to get the csv:
|
110
|
-
# Search the content for __VIEWSTATE or __EVENTVALIDATION
|
111
|
-
viewState = data.split(/>\s*?</).grep(/__VIEWSTATE/).first[/value=\".+?\"/][7..-2]
|
112
|
-
eventValidation = data.split(/>\s*?</).grep(/__EVENTVALIDATION/).first[/value=\".+?\"/][7..-2]
|
113
|
-
exportValue = data.split(/>\s*?</).grep(/ctl02\$ExportButton/).first[/value=\".+?\"/][7..-2]
|
114
|
-
mt = cookies.split("; ").grep(/mt=/).first[3..-1]
|
115
67
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
68
|
+
@contacts = []
|
69
|
+
build_contacts = []
|
70
|
+
go = true
|
71
|
+
index = 0
|
72
|
+
|
73
|
+
while(go) do
|
74
|
+
go = false
|
75
|
+
url = URI.parse(get_contact_list_url(index))
|
76
|
+
http = open_http(url)
|
77
|
+
resp, data = http.get(get_contact_list_url(index), "Cookie" => @cookies)
|
78
|
+
|
79
|
+
email_match_text_beginning = Regexp.escape("http://m.mail.live.com/?rru=compose&to=")
|
80
|
+
email_match_text_end = Regexp.escape("&")
|
81
|
+
|
82
|
+
raw_html = resp.body.grep(/(?:e|dn)lk[0-9]+/)
|
83
|
+
raw_html.delete_at 0
|
84
|
+
raw_html.inject do |memo, row|
|
85
|
+
c_info = row.match(/(e|dn)lk([0-9])+/)
|
86
|
+
|
87
|
+
# Same contact, or different?
|
88
|
+
build_contacts << [] if memo != c_info[2]
|
89
|
+
|
90
|
+
# Grab info
|
91
|
+
case c_info[1]
|
92
|
+
when "e" # Email
|
93
|
+
build_contacts.last[1] = row.match(/#{email_match_text_beginning}(.*)#{email_match_text_end}/)[1]
|
94
|
+
when "dn" # Name
|
95
|
+
build_contacts.last[0] = row.match(/<a[^>]*>(.+)<\/a>/)[1]
|
96
|
+
end
|
97
|
+
|
98
|
+
# Set memo to contact id
|
99
|
+
c_info[2]
|
100
|
+
end
|
101
|
+
|
102
|
+
go = resp.body.include?("Next page")
|
103
|
+
index += 1
|
104
|
+
end
|
105
|
+
|
106
|
+
build_contacts.each do |contact|
|
107
|
+
unless contact[1].nil?
|
108
|
+
# Only return contacts with email addresses
|
109
|
+
contact[1] = CGI::unescape(contact[1])
|
110
|
+
@contacts << contact
|
111
|
+
end
|
112
|
+
end
|
113
|
+
return @contacts
|
136
114
|
end
|
137
115
|
end
|
138
|
-
|
139
|
-
|
140
|
-
private
|
141
116
|
|
142
|
-
def
|
143
|
-
|
117
|
+
def get_contact_list_url(index)
|
118
|
+
"http://mpeople.live.com/default.aspx?pg=#{index}"
|
144
119
|
end
|
145
120
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
postdata += "&curmbox=00000000-0000-0000-0000-000000000001"
|
150
|
-
|
151
|
-
a = data.split(/>\s*<input\s+/i).grep(/\s+name="a"/i)
|
152
|
-
return nil if a.empty?
|
153
|
-
|
154
|
-
a = a[0].match(/\s+value="([a-f0-9]+)"/i) or return nil
|
155
|
-
postdata += "&a=#{a[1]}"
|
156
|
-
|
157
|
-
data, resp, @cookies, forward = post(compose_url, postdata, @cookies)
|
158
|
-
e = data.split(/>\s*<input\s+/i).grep(/\s+name="to"/i)
|
159
|
-
return nil if e.empty?
|
160
|
-
|
161
|
-
e = e[0].match(/\s+value="([^"]+)"/i) or return nil
|
162
|
-
@contacts[contacts_slot][1] = e[1] if e[1].match(/@/)
|
163
|
-
end
|
164
|
-
|
165
|
-
def parse(data, options={})
|
166
|
-
data = data.split("\r\n")
|
167
|
-
data = CSV.parse(data.join("\r\n").gsub('"', '').gsub(';', ','), ';')
|
168
|
-
col_names = data.shift
|
169
|
-
|
170
|
-
@contacts = data.delete_if{|person|person[0].nil?}.map do |person|
|
171
|
-
person = person[0].split(",")
|
172
|
-
next unless (idx = person.index('SMTP'))
|
173
|
-
[[person[1], person[2], person[3]].delete_if{|i|i.empty?}.join(" "), person[idx - 1]] unless person[idx - 1].nil?
|
174
|
-
end.compact
|
175
|
-
end
|
121
|
+
private
|
122
|
+
|
123
|
+
TYPES[:hotmail] = Hotmail
|
176
124
|
end
|
177
|
-
|
178
|
-
TYPES[:hotmail] = Hotmail
|
179
125
|
end
|
data/lib/contacts/plaxo.rb
CHANGED
@@ -53,7 +53,7 @@ end # Contacts
|
|
53
53
|
|
54
54
|
|
55
55
|
# sample contacts responses
|
56
|
-
|
56
|
+
=begin
|
57
57
|
Bad email
|
58
58
|
=========
|
59
59
|
<?xml version="1.0" encoding="utf-8" ?>
|
@@ -119,5 +119,4 @@ Success
|
|
119
119
|
<editCounter>3</editCounter>
|
120
120
|
|
121
121
|
</ns1:GetContactsResponse>
|
122
|
-
|
123
|
-
'
|
122
|
+
=end
|