blib/lib/WWW/Contact/Hotmail.pm

filter: Statementstmt 20.8% 20 / 96 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 5 / 8 Podpod 0.0% 0 / 3 totaltotal 16.4% 25 / 152 CC 26 SCAR 50.2
CC
26
Cov
14%
get_contacts
272.0
get_contacts_from_html
72.0
get_contacts_page_from_html
20.0
CRAP 151.9
↑ Summary blib/lib/WWW/Contact/GoogleContactsAPI.pm »
1 package WWW::Contact::Hotmail;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 extends 'WWW::Contact::Base';
5  
6 1 ▶use HTTP::Request::Common qw/POST/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use HTML::TokeParser::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTML::Entities ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.46';
11 1 our $AUTHORITY = 'cpan:FAYLAND';
12  
13 sub get_contacts {
14 0 ▶ my ($self, $email, $password) = @_;
Subroutine get_contacts: not called CC=16 SCAR=56.1
Pod undocumented
15  
16 # reset
17 0 $self->errstr(undef);
18 0 $self->debug(1);
19 0 my @contacts;
20
21 0 my ( $username, $domain ) = split('@', $email);
22
23 0 my $ua = $self->ua;
24 0 $self->debug("start get_contacts from Hotmail");
25
26 # to form
27 0 ▶ $self->get('http://www.hotmail.com/') || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get("http://www.hotmail.com/") or return 0 0 0
28  
29 0 my $content = $ua->content;
30 # name="PPFT" id="i0327" value="Bw4Y3kJtiK6yV7ABYe!x*UuPc4ojFA3Hd9L5p5Y3YI8jpFmz3zE1oUjkvr8gGJhvdbe4KJMCYYBY3!Rvw6gnzeg2*o8UXoFzVNuEbpEyDviKY0n6INA07ZCrpC3hCNymZcj4dywAIUcIDroGGxGLX1IEUctXOCQY!GlHcjEvondo6cSF9!!tjN*6qu!X"/>';
31 0 my ($PPFT) = ( $content =~ /name\=\"PPFT\".*?value\=\"(.*?)\"/ );
32 # srf_uPost=\'https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=10&ct=1225096129&rver=4.5.2130.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&id=64855&bk=1225096129\'
33 0 my ($post_url) = ( $content =~ /srf_uPost\=\'([^\']+)\'/ );
34
35 # from http://login.live.com/WLLogin_JS.srf?x=6.0.11557.0&lc=1033
36 # g_DO["compaq.net"]="https://msnia.login.live.com/ppsecure/post.srf";g_DO["hotmail.co.jp"]="https://login.live.com/ppsecure/post.srf";g_DO["hotmail.co.uk"]="https://login.live.com/ppsecure/post.srf";g_DO["hotmail.com"]="https://login.live.com/ppsecure/post.srf";g_DO["hotmail.de"]="https://login.live.com/ppsecure/post.srf";g_DO["hotmail.fr"]="https://login.live.com/ppsecure/post.srf";g_DO["hotmail.it"]="https://login.live.com/ppsecure/post.srf";g_DO["messengeruser.com"]="https://login.live.com/ppsecure/post.srf";g_DO["msn.com"]="https://msnia.login.live.com/ppsecure/post.srf";g_DO["passport.com"]="https://login.live.com/ppsecure/post.srf";g_DO["webtv.net"]="https://login.live.com/ppsecure/post.srf";
37 0 ▶ if ( $domain eq 'compaq.net' or $domain eq 'msn.com' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($domain eq "compaq.net" or $domain eq "msn.com") 0 0 0
Condition0%0/3
$domain eq "compaq.net" or $domain eq "msn.com"
l!l&&r!l&&!r
000
MC/DC0%0/2
$domain eq "compaq.net" or $domain eq "msn.com"
$domain eq "compaq.net" $domain eq "msn.com"
Truth table0%0/3
A or B
A= $domain eq "compaq.net"B= $domain eq "msn.com"
ABresult
1X1
011
000
38 # var g_QS="wa=wsignin1.0&rpsnv=11&ct=1266924668&rver=6.0.5285.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1033&id=64855&mkt=en-us&bk=1266924668";
39 0 my ($post_param) = ($content =~ /g_QS\s*\=\s*[\"\']([^\'\"]+)[\"\']/);
40 0 $post_url = 'https://msnia.login.live.com/ppsecure/post.srf?' . $post_param;
41 }
42
43 # switch(g_iActiveCredtype){case 1:if(g_fLWASilentAuth==true)s.type.value=30;else s.type.value=11;break;case 2:s.type.value=12;if(s.CS.value==""){if(!SubmitCardSpace())return false;}break;case 4:s.type.value=14;if(g_fEIDSupported&&typeof g_EIDScriptDL!="undefined"){if(!EIDSubmit(s))return false;}break;case 3:s.type.value=13;
44 0 my $type = 11;
45 # XXX? It's a bit complicated. need FIX later.
46
47 # try me, STUPID Microsoft always wants to get rid of US!
48 0 $ua->request(POST $post_url, [
49 idsbho => 1,
50 PwdPad => 'IfYouAreReadingThisYouHaveTooMuch',
51 LoginOptions => 3,
52 CS => undef,
53 FedState => undef,
54 PPSX => 'PassportR',
55 type => $type,
56 login => $email,
57 passwd => $password,
58 NewUser => 1,
59 PPFT => $PPFT,
60 i1 => 0,
61 i2 => 0,
62 ]);
63
64 # var srf_sErr=\'The e-mail address or password is incorrect. Please try again.\';
65 0 my ( $has_error ) = ( $ua->content =~ /srf_sErr\=\'([^\']+)\'/ );
66 0 ▶ if ( $has_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_error) 0 0 0
67 0 $self->errstr('Wrong Username or Password');
68 0 return;
69 }
70
71 0 $ua->cookie_jar->clear( '.live.com', '/', 'WLSSC' );
72  
73 # <html><head><script type="text/javascript">function rd(){window.location.replace("http://mail.live.com/default.aspx?wa=wsignin1.0");}function OnBack(){}</script></head><body onload="javascript:rd();"></body></html>
74 0 my ( $url ) = ( $ua->content =~ /replace\(\"([^\"]+)\"/ );
75 0 ▶ if ( $url ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url) 0 0 0
76 0 ▶ $self->get( $url ) || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get($url) or return 0 0 0
77 }
78
79 # You spoke, Hotmail listened
80 0 ▶ if ( $ua->content =~ /MessageAtLoginForm/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ua->content =~ /MessageAtLoginForm/) 0 0 0
81 0 ▶ $self->submit_form(
Branch: 1 branch
BranchTrueFalseTotal
$self->submit_form("form_name", "MessageAtLoginForm") or return 0 0 0
82 form_name => 'MessageAtLoginForm',
83 ) || return;
84 }
85  
86 # TodayDefault, Our latest improvements
87 # <base href="http&#58;&#47;&#47;co118w.col118.mail.live.com&#47;mail&#47;TodayLight.aspx&#63;layout&#61;TodayDefault&#38;rru&#61;&#38;n&#61;1976853626" />
88 0 my ( undef, undef, $maildomain ) = ( $ua->content =~ /base\s+href\=\"(.*?)(&\#47\;&\#47\;|\/\/)((.*?)\.mail\.live\.com)/ );
89 0 my ( $uid ) = ( $ua->content =~ /n\&\#61\;(\d+)/ ); # n&#61;
90 0 ▶ unless ( $uid ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uid) 0 0 0
91 0 $self->errstr('Wrong Username or Password');
92 0 return;
93 }
94  
95 0 ▶ $self->get("http://$maildomain/mail/ContactMainLight.aspx?n=$uid") || return;
Branch: 1 branch
BranchTrueFalseTotal
$self->get("http://$maildomain/mail/ContactMainLight.aspx?n=$uid") or return 0 0 0
96  
97 0 @contacts = $self->get_contacts_from_html( $ua->content );
98 0 ▶ if ( scalar @contacts > 24 ) { # more pages, scalar @contacts == 25
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @contacts > 24) 0 0 0
99 0 my $page = $self->get_contacts_page_from_html($ua->content);
100 0 ▶ if ( $page > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page > 1) 0 0 0
101 0 foreach my $p (2..$page) {
102 0 ▶ $self->get("http://$maildomain/mail/ContactMainLight.aspx?n=$uid&Page=$p") || next;
Branch: 1 branch
BranchTrueFalseTotal
$self->get("http://$maildomain/mail/ContactMainLight.aspx?n=$uid&Page=$p") or next 0 0 0
103 0 push @contacts, $self->get_contacts_from_html($ua->content);
104 }
105 }
106 }
107
108 # remove email itself
109 0 @contacts = grep { $_->{email} ne $email } @contacts;
110  
111
112 0 ▶ return wantarray ? @contacts : \@contacts;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
113 }
114  
115 sub get_contacts_from_html {
116 0 ▶ my ($self, $content) = @_;
Subroutine get_contacts_from_html: not called CC=8 SCAR=42.8
Pod undocumented
117
118 0 my @contacts;
119
120 # cxp_ic_control_data
121 0 my ( $data ) = ( $content =~ /cxp_ic_control_data(.*?)\}\;/s );
122 0 ▶ if ($data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) { } 0 0 0
123 0 my @lines = split(/\n/, $data);
124 0 foreach my $line ( @lines ) {
125 # ICc0:['0ea61975fb7fb339','1',['sm','si','ct'],'fayland lam','55ff0c7e-2c36-41cc-aa12-fb1db452f171','1055559157186278201','fayland\x40gmail.com','fayland\x40gmail.com','','1',[['Send e-mail','','','submitToCompose\x28\x2755ff0c7e-2c36-41cc-aa12-fb1db452f171\x27, \x27EditMessageLight.aspx\x3fn\x3d1423059530\x27\x29'],['Edit contact info','ContactEditLight.aspx\x3fContactID\x3d55ff0c7e-2c36-41cc-aa12-fb1db452f171\x26n\x3d1980367392','','','_self']]],
126 0 my ( $email ) = ( $line =~ /\'([^\']+\\x40(.*?))\'/ );
127 0 ▶ next unless $email;
Branch: 1 branch
BranchTrueFalseTotal
unless $email 0 0 0
128 0 $email =~ s/\\x40/\@/;
129 0 my ( $name ) = ( $line =~ /\]\,\s*\'([^\']+)\'/ );
130 # Funky encoding of some non-alphanumberic chars in Hotmail names fix by OALDERS (RT 46280)
131 0 ▶ if ( $name =~ /\\x/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\\x/) 0 0 0
132 0 $name =~ s{\\x([A-Fa-f0-9]{2})}{chr(hex($1))}egxms;
133 0 $name = HTML::Entities::decode_entities($name);
134 }
135 0 push @contacts, {
136 email => $email,
137 name => $name,
138 };
139 }
140 } else {
141 # ic_control_data
142 0 ( $data ) = ( $content =~ /ic_control_data(.*?)\}\;/s );
143 0 my @lines = split(/\n/, $data);
144 0 foreach my $line ( @lines ) {
145 # "ic2":["","1",["se","vd"],"33","0832c2b8-aeba-4c9c-a359-5dfff5664610","0","333\u004022.com","cid\u003a0",[],"","","1",[],"","","",""
146 0 my ( $email ) = ( $line =~ /[\'\"]([^\'\"]+\\u0040(.*?))[\'\"]/ );
147 0 ▶ next unless $email;
Branch: 1 branch
BranchTrueFalseTotal
unless $email 0 0 0
148 0 $email =~ s/\\u0040/\@/;
149 0 my ( $name ) = ( $line =~ /\]\,\s*[\'\"]([^\'\"]+)[\'\"]/ );
150 # Funky encoding of some non-alphanumberic chars in Hotmail names fix by OALDERS (RT 46280)
151 0 ▶ if ( $name =~ /\\u/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /\\u/) 0 0 0
152 0 $name =~ s/\\u(....)/ pack 'U*', hex($1) /eg;
153 }
154 0 push @contacts, {
155 email => $email,
156 name => $name,
157 };
158 }
159 }
160  
161 0 return @contacts;
162 }
163  
164 sub get_contacts_page_from_html {
165 0 ▶ my ($self, $content) = @_;
Subroutine get_contacts_page_from_html: not called CC=4 SCAR=30.0
Pod undocumented
166  
167 0 my $page = 1;
168 0 foreach my $line (split /\n/, $content) {
169 #<li ><a href="ContactMainLight.aspx&#63;ContactsSortBy&#61;FileAs&#38;Page&#61;2&#38;n&#61;1033539816" title="Next page"
170 0 ▶ if ($line =~ /ContactMainLight.aspx&#.*;Page&#61;(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /ContactMainLight.aspx&#.*;Page&#61;(\d+)/) 0 0 0
171 0 ▶ if ($page < $1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($page < $1) 0 0 0
172 0 $page = $1;
173 }
174 }
175 }
176 0 return $page;
177 }
178  
179 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
180 1 __PACKAGE__->meta->make_immutable;
181  
182 1 1;
183 __END__
184  
185 =head1 NAME
186  
187 WWW::Contact::Hotmail - Get contacts/addressbook from Hotmail/Live Mail
188  
189 =head1 SYNOPSIS
190  
191 use WWW::Contact;
192 use Data::Dumper;
193
194 my $wc = WWW::Contact->new();
195 my @contacts = $wc->get_contacts('itsa@hotmail.com', 'password');
196 my $errstr = $wc->errstr;
197 if ($errstr) {
198 die $errstr;
199 } else {
200 print Dumper(\@contacts);
201 }
202  
203 =head1 DESCRIPTION
204  
205 Get contacts from Hotmail/Live Mail L<http://www.hotmail.com/>. Extends L<WWW::Contact::Base>
206  
207 =head1 WARNING
208  
209 Microsoft is always changing the web interface to get rid of something like us. So it might be broken soon. use it at your own risk!
210  
211 =head1 SEE ALSO
212  
213 L<WWW::Contact>, L<WWW::Mechanize>, L<HTML::TokeParser::Simple>
214  
215 =head1 AUTHOR
216  
217 Fayland Lam, C<< <fayland at gmail.com> >>
218  
219 =head1 COPYRIGHT & LICENSE
220  
221 Copyright 2008 Fayland Lam, all rights reserved.
222  
223 This program is free software; you can redistribute it and/or modify it
224 under the same terms as Perl itself.
225  
226 =cut
↑ Summary blib/lib/WWW/Contact/GoogleContactsAPI.pm »