| 1 | package WWW::Contact::AOL; | ||
| 2 | |||
| 3 | use Moose; | ||
| 4 | extends 'WWW::Contact::Base'; | ||
| 5 | |||
| 6 | our $VERSION = '0.47'; | ||
| 7 | our $AUTHORITY = 'cpan:FAYLAND'; | ||
| 8 | |||
| 9 | sub get_contacts { | ||
| 10 | my ($self, $email, $password) = @_; | ||
| 11 | |||
| 12 | # reset | ||
| 13 | $self->errstr(undef); | ||
| 14 | my @contacts; | ||
| 15 | |||
| 16 | my ( $username ) = split('@', $email); | ||
| 17 | |||
| 18 | my $ua = $self->ua; | ||
| 19 | $self->debug("start get_contacts from AOL mail"); | ||
| 20 | |||
| 21 | # to form | ||
| 22 | $self->get('https://my.screenname.aol.com/_cqr/login/login.psp?mcState=initialized&uitype=mini&sitedomain=registration.aol.com&authLev=1&seamless=novl&lang=en&locale=us') || return; | ||
| 23 | $self->submit_form( | ||
| 24 | form_name => 'AOLLoginForm', | ||
| 25 | fields => { | ||
| 26 | loginId => $username, | ||
| 27 | password => $password, | ||
| 28 | }, | ||
| 29 | ) || return; | ||
| 30 | my $content = $ua->content(); | ||
| 31 | if ($content =~ /name\=\"loginId\"/) { | ||
| 32 | $self->errstr('Wrong Username or Password'); | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | |||
| 36 | $self->debug('Login OK'); | ||
| 37 | #snsRedir("https://account.login.aol.com/opr/_cqr/data/update.psp?sitedomain=registration.aol.com&authLev=1&lang=en&locale=us&acctfixsid=oar-artifact&uitype=mini&mcAuth=%2FBcAG06o0D0AAK9OARkfR06o0HkI3xp9FQJ8VlIAAA%3D%3D"); | ||
| 38 | my ($url) = ( $content =~ /snsRedir\([\"\"]([^\'\"]+)[\"\"]/ ); | ||
| 39 | |||
| 40 | $ua->get($url); # usually we don't care the Response status here | ||
| 41 | |||
| 42 | # but we have to skip data update form | ||
| 43 | # skip the data update | ||
| 44 | if ($ua->content =~ /oprFormV2/) { | ||
| 45 | eval { $ua->submit_form( form_name => 'oprFormV2' , fields => { action => 'dataUpdateSkip' } ); }; | ||
| 46 | } | ||
| 47 | |||
| 48 | $self->get('http://mail.aol.com/'); | ||
| 49 | |||
| 50 | # http://my.screenname.aol.com/_cqr/login/login.psp?sitedomain=sns.mail.aol.com&lang=en&locale=us&authLev=0&uitype=mini&siteState=ver%3a4%7crt%3aSTANDARD%7cat%3aSNS%7cld%3amail.aol.com%7crp%3aLite%252fToday.aspx%7cuv%3aAOL%7clc%3aen-us%7cmt%3aAOL%7csnt%3aScreenName%7csid%3a721f5d19-a18f-4f11-bf35-500d91ddf6d6&seamless=novl&loginId=&_sns_width_=174&_sns_height_=196&_sns_fg_color_=373737&_sns_err_color_=C81A1A&_sns_link_color_=0066CC&_sns_bg_color_=FFFFFF&redirType=js | ||
| 51 | $content = $ua->{content}; | ||
| 52 | if ( $content =~ /(http\:\/\/my.screenname.aol.com\/_cqr\/login\/login.psp([^\'\"]+))/s ) { | ||
| 53 | $self->get($1) || return; | ||
| 54 | $content = $ua->{content}; | ||
| 55 | } | ||
| 56 | if ( $content =~ /checkErrorAndSubmitForm/ and $content =~ /\'(http\:\/\/(.*?))\'/ ) { | ||
| 57 | $self->get($1) || return; | ||
| 58 | } | ||
| 59 | |||
| 60 | my ($gSuccessPath, $aol_v) = ( $ua->content() =~ /\.com\/([^\/]+)\/(aol[^\/]*)\/en\-us/ ); | ||
| 61 | $self->get( "http://mail.aol.com/$gSuccessPath/$aol_v/en-us/Lite/Today.aspx?src=bandwidth" ) || return; | ||
| 62 | |||
| 63 | my ($uid) = ($ua->content() =~ /user\=([^\'\&]+)[\'\&]/); | ||
| 64 | unless ($uid) { | ||
| 65 | $self->errstr('Wrong Password'); | ||
| 66 | return; | ||
| 67 | } | ||
| 68 | |||
| 69 | # http://mail.aol.com/39598/aol/en-us/Lite/addresslist-print.aspx?command=all&sort=FirstLastNick&sortDir=Ascending&nameFormat=FirstLastNick&user=lP9ZCc0KdY | ||
| 70 | $ua->get( | ||
| 71 | "http://mail.aol.com/$gSuccessPath/$aol_v/en-us/Lite/addresslist-print.aspx?command=all&sort=FirstLastNick&sortDir=Ascending&nameFormat=FirstLastNick&user=$uid" | ||
| 72 | ) || return; | ||
| 73 | |||
| 74 | $content = $ua->content(); | ||
| 75 | @contacts = $self->get_contacts_from_html($content); | ||
| 76 | @contacts = grep { lc($_->{email}) ne lc($email) } @contacts; # skip himself | ||
| 77 | |||
| 78 | # we don't care if it works or not, to avoid | ||
| 79 | # Error GETing | ||
| 80 | eval { | ||
| 81 | $ua->get( | ||
| 82 | "http://mail.aol.com/$gSuccessPath/$aol_v/en-us/common/Logout.aspx" | ||
| 83 | ); | ||
| 84 | }; | ||
| 85 | |||
| 86 | return wantarray ? @contacts : \@contacts; | ||
| 87 | } | ||
| 88 | |||
| 89 | sub get_contacts_from_html { | ||
| 90 | my ($self, $content) = @_; | ||
| 91 | |||
| 92 | my @contacts; | ||
| 93 | my @contents = split( | ||
| 94 | '<tr><td colspan="4"><hr class="contactSeparator"></td></tr>', | ||
| 95 | $content ); | ||
| 96 | foreach my $c (@contents) { | ||
| 97 | my ( $firstname, $last_name, $name ) | ||
| 98 | = ( $c =~ /fullName\"\>(\S*)\s*(\S*)\s*\<i\>\((.*?)\)/ ); | ||
| 99 | my ($email1) = ( | ||
| 100 | $c =~ /\<span\>Email 1\:\<\/span\>\s*\<span\>([^<^>]*)\<\/span\>/ | ||
| 101 | ); | ||
| 102 | my ($email2) = ( | ||
| 103 | $c =~ /\<span\>Email 2\:\<\/span\>\s*\<span\>([^<^>]*)\<\/span\>/ | ||
| 104 | ); | ||
| 105 | my $email = $email1 || $email2; | ||
| 106 | unless ($email) { | ||
| 107 | my ($screen_name) = ( $c | ||
| 108 | =~ /\<span\>Screen Name\:\<\/span\>\s*\<span\>([^<^>]*)\<\/span\>/ | ||
| 109 | ); | ||
| 110 | $email = $screen_name . '@aol.com' if ($screen_name); | ||
| 111 | } | ||
| 112 | next unless ($email); | ||
| 113 | |||
| 114 | push @contacts, { | ||
| 115 | name => $name, | ||
| 116 | email => $email | ||
| 117 | }; | ||
| 118 | } | ||
| 119 | |||
| 120 | return @contacts; | ||
| 121 | } | ||
| 122 | |||
| 123 | no Moose; | ||
| 124 | __PACKAGE__->meta->make_immutable; | ||
| 125 | |||
| 126 | 1; | ||
| 127 | __END__ | ||
| 128 | |||
| 129 | =head1 NAME | ||
| 130 | |||
| 131 | WWW::Contact::AOL - Get contacts/addressbook from AOL Mail | ||
| 132 | |||
| 133 | =head1 SYNOPSIS | ||
| 134 | |||
| 135 | use WWW::Contact; | ||
| 136 | use Data::Dumper; | ||
| 137 | |||
| 138 | my $wc = WWW::Contact->new(); | ||
| 139 | my @contacts = $wc->get_contacts('itsa@aol.com', 'password'); | ||
| 140 | my $errstr = $wc->errstr; | ||
| 141 | if ($errstr) { | ||
| 142 | die $errstr; | ||
| 143 | } else { | ||
| 144 | print Dumper(\@contacts); | ||
| 145 | } | ||
| 146 | |||
| 147 | =head1 DESCRIPTION | ||
| 148 | |||
| 149 | get contacts from AOL Mail. extends L<WWW::Contact::Base> | ||
| 150 | |||
| 151 | =head1 SEE ALSO | ||
| 152 | |||
| 153 | L<WWW::Contact>, L<WWW::Mechanize> | ||
| 154 | |||
| 155 | =head1 AUTHOR | ||
| 156 | |||
| 157 | Fayland Lam, C<< <fayland at gmail.com> >> | ||
| 158 | |||
| 159 | =head1 COPYRIGHT & LICENSE | ||
| 160 | |||
| 161 | Copyright 2008 Fayland Lam, all rights reserved. | ||
| 162 | |||
| 163 | This program is free software; you can redistribute it and/or modify it | ||
| 164 | under the same terms as Perl itself. | ||
| 165 | |||
| 166 | =cut |