line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Hotmail; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
763
|
use Carp qw(croak); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
60
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'WWW::Mechanize'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1291
|
|
5
|
1
|
|
|
1
|
|
624251
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1325
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $croak_on_error = 0; |
12
|
|
|
|
|
|
|
our $errstr = ''; |
13
|
|
|
|
|
|
|
our $errhtml = ''; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
1
|
|
|
1
|
1
|
439
|
my $class = shift; |
17
|
|
|
|
|
|
|
# avoid complaints from M$ by using IE 6.0 |
18
|
1
|
|
|
|
|
9
|
my $self = $class->SUPER::new(agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); |
19
|
1
|
|
|
|
|
24764
|
$self->cookie_jar({}); |
20
|
1
|
|
|
|
|
266
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub login { |
24
|
0
|
|
|
0
|
1
|
|
my ($self,$email,$pass) = @_; |
25
|
0
|
0
|
|
|
|
|
unless ($email =~ m/\@([^.]+)\.(.+)/) { |
26
|
0
|
|
|
|
|
|
$errstr = 'You must supply full email addres as the username'; |
27
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
28
|
0
|
|
|
|
|
|
$self->error2html(); |
29
|
0
|
|
|
|
|
|
return undef; |
30
|
|
|
|
|
|
|
} |
31
|
0
|
|
|
|
|
|
my $domain = lc("$1_$2"); |
32
|
0
|
|
|
|
|
|
my $resp = $self->get('http://www.hotmail.com/'); |
33
|
0
|
0
|
|
|
|
|
$resp->is_success || do { |
34
|
0
|
|
|
|
|
|
$errstr = $resp->as_string(); |
35
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
36
|
0
|
|
|
|
|
|
$errhtml = $resp->error_as_HTML; |
37
|
0
|
|
|
|
|
|
return undef; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
# bypass the js detection page |
40
|
0
|
0
|
|
|
|
|
if ($self->{content} =~ m//i) { |
41
|
0
|
|
|
|
|
|
$self->form_name($1); |
42
|
0
|
|
|
|
|
|
$self->submit(); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$self->form_name('f1'); |
46
|
|
|
|
|
|
|
# this SHOULD cover charter.com, compaq.net, hotmail.com, msn.com, passport.com, and webtv.net |
47
|
|
|
|
|
|
|
# all this java regex crap is needed just for this feature. Maybe this can be done better? |
48
|
0
|
0
|
|
|
|
|
if ($self->{content} =~ m#name="f1".*action="([^"]+)"#i) { |
49
|
|
|
|
|
|
|
#if ($self->{content} =~ m#name="$domain" action="([^"]+)"#) { |
50
|
|
|
|
|
|
|
# current_form returns a HTML::Form obj |
51
|
0
|
|
|
|
|
|
$self->current_form()->action($1); |
52
|
|
|
|
|
|
|
} else { |
53
|
0
|
|
|
|
|
|
$errstr = 'hotmail format changed or email domain not used with Hotmail'; |
54
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
55
|
0
|
|
|
|
|
|
$self->error2html(); |
56
|
0
|
|
|
|
|
|
return undef; |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
$self->field(login => $email); |
59
|
0
|
|
|
|
|
|
$self->field(passwd => $pass); |
60
|
0
|
|
|
|
|
|
$resp = $self->submit(); |
61
|
0
|
0
|
|
|
|
|
$resp->is_success || do { |
62
|
0
|
|
|
|
|
|
$errstr = $resp->as_string; |
63
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
64
|
0
|
|
|
|
|
|
$errhtml = $resp->error_as_HTML; |
65
|
0
|
|
|
|
|
|
return undef; |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
#$self->{content} =~ /URL=(.+)"/ or do { |
68
|
0
|
0
|
|
|
|
|
$self->{content} =~ /replace\(\"(.+?)\"\)/ or do { |
69
|
0
|
|
|
|
|
|
$errstr = 'Hotmail format changed!'; |
70
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
71
|
0
|
|
|
|
|
|
$self->error2html(); |
72
|
0
|
|
|
|
|
|
return undef; |
73
|
|
|
|
|
|
|
}; |
74
|
0
|
|
|
|
|
|
$self->get($1); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# look for the base url for the mailbox |
77
|
0
|
0
|
|
|
|
|
if ($self->{content} =~ m/_UM\s*=\s*"([^"]+)";?/) { |
|
|
0
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->{_WWWHotmail_base} = $1; |
79
|
|
|
|
|
|
|
} elsif ($self->{content} =~ m!http://login\.passport\.net/uilogin\.srf!) { |
80
|
0
|
|
|
|
|
|
$errstr = 'Couldn\'t log in to Hotmail, username or password incorrect'; |
81
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
82
|
0
|
|
|
|
|
|
$self->error2html(); |
83
|
0
|
|
|
|
|
|
return undef; |
84
|
|
|
|
|
|
|
} else { |
85
|
0
|
|
|
|
|
|
$errstr = 'Couldn\'t log in to Hotmail'; |
86
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
87
|
0
|
|
|
|
|
|
$self->error2html(); |
88
|
0
|
|
|
|
|
|
return undef; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
$self->{_WWWHotmail_logged_in} = 1; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
return 1; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub messages { |
97
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
98
|
0
|
0
|
|
|
|
|
unless (defined($self->{_WWWHotmail_logged_in})) { |
99
|
0
|
|
|
|
|
|
$errstr = 'Not logged in!'; |
100
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
101
|
0
|
|
|
|
|
|
$self->error2html(); |
102
|
0
|
|
|
|
|
|
return (); |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
|
my $last_page = 1; |
105
|
0
|
|
|
|
|
|
my $i = 1; |
106
|
0
|
|
|
|
|
|
$self->{_WWWHotmail_msgs} = (); |
107
|
|
|
|
|
|
|
# traverse all pages |
108
|
0
|
|
|
|
|
|
while ($i <= $last_page) { |
109
|
|
|
|
|
|
|
# sorting avoids getting the same message twice |
110
|
0
|
|
|
|
|
|
$self->get('/cgi-bin/HoTMaiL?'.$self->{_WWWHotmail_base}."&page=$i&Sort=rDate"); |
111
|
|
|
|
|
|
|
# this finds the ->| link (last page) |
112
|
0
|
0
|
0
|
|
|
|
if ($i == 1 && $self->{content} =~ m/'page=(\d+)'/i) { |
113
|
0
|
|
|
|
|
|
$last_page = $1; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
# replace javascript junk |
116
|
|
|
|
|
|
|
# and adapt it to grab 'from' AND 'subjects' |
117
|
|
|
|
|
|
|
# TODO this can be done better |
118
|
0
|
|
|
|
|
|
my $content = $self->content(); |
119
|
0
|
|
|
|
|
|
$content =~ s/\r|\n| //g; |
120
|
0
|
|
|
|
|
|
$content =~ s/javascript\:G\('([^']+)'\)">([^<]+)<\/a><\/td> | ([^<]+)<\/td>/$1">$2|$3<\/a>/gi; |
121
|
0
|
|
|
|
|
|
$self->update_html($content); |
122
|
0
|
|
|
|
|
|
push(@{$self->{_WWWHotmail_msgs}}, map { |
|
0
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
my $x = WWW::Hotmail::Message->new; |
124
|
0
|
|
|
|
|
|
$x->{_WWW_Hotmail_msg} = $_; |
125
|
0
|
|
|
|
|
|
$x->{_WWW_Hotmail_parent} = $self; |
126
|
0
|
|
|
|
|
|
$x; |
127
|
0
|
|
|
|
|
|
} grep { $_->url() =~ /getmsg/ } @{$self->links}); |
|
0
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
$i++; |
129
|
|
|
|
|
|
|
} |
130
|
0
|
|
|
|
|
|
return @{$self->{_WWWHotmail_msgs}}; |
|
0
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub compose { |
134
|
0
|
|
|
0
|
1
|
|
my ($self,%args) = @_; |
135
|
0
|
|
|
|
|
|
my @argkeys = ('to','cc','bcc','subject','body'); |
136
|
0
|
|
|
|
|
|
$self->get('/cgi-bin/compose?'.$self->{_WWWHotmail_base}); |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$self->form_name('composeform'); |
139
|
|
|
|
|
|
|
# fill in the form fields |
140
|
0
|
|
|
|
|
|
for(@argkeys) { |
141
|
|
|
|
|
|
|
# flatten arrays |
142
|
0
|
0
|
|
|
|
|
if (ref($args{$_}) eq 'ARRAY') { |
143
|
0
|
|
|
|
|
|
$args{$_} = join(',',@{$args{$_}}); |
|
0
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} |
145
|
0
|
|
|
|
|
|
$self->field($_ => delete $args{$_}); |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
# warn them of mistakes |
148
|
0
|
|
|
|
|
|
for my $bad (keys %args) { |
149
|
0
|
|
|
|
|
|
warn "unknown key '$bad' passed to compose"; |
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
|
$self->field(_HMaction => 'Send'); |
152
|
0
|
|
|
|
|
|
$self->submit(); |
153
|
0
|
0
|
|
|
|
|
unless($self->content() =~ m/Your message has been sent to/) { |
154
|
0
|
|
|
|
|
|
$errstr = 'Your message failed to send'; |
155
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
156
|
0
|
|
|
|
|
|
$self->error2html(); |
157
|
0
|
|
|
|
|
|
$self->form_name('composeform'); |
158
|
0
|
|
|
|
|
|
$self->field(_HMaction => 'Cancel'); |
159
|
0
|
|
|
|
|
|
$self->submit(); |
160
|
0
|
|
|
|
|
|
return undef; |
161
|
|
|
|
|
|
|
} |
162
|
0
|
|
|
|
|
|
return 1; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub error2html { |
166
|
0
|
0
|
|
0
|
0
|
|
shift if (ref($_[0])); |
167
|
0
|
|
0
|
|
|
|
my $body = shift || $errstr; |
168
|
0
|
|
|
|
|
|
$errhtml = <
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Error |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Error |
173
|
|
|
|
|
|
|
$body |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
EOM |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
package WWW::Hotmail::Message; |
180
|
|
|
|
|
|
|
@WWW::Hotmail::Message::ISA = qw(WWW::Hotmail); |
181
|
|
|
|
|
|
|
|
182
|
1
|
|
|
1
|
|
1133
|
use Mail::Audit; |
|
1
|
|
|
|
|
36203
|
|
|
1
|
|
|
|
|
15
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# TODO this can also be done better |
185
|
0
|
|
|
0
|
|
|
sub from { (split(/\|/, shift->{_WWW_Hotmail_msg}->text()))[0] } |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
0
|
|
|
sub subject { (split(/\|/, shift->{_WWW_Hotmail_msg}->text()))[1] } |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
0
|
|
|
sub _link { shift->{_WWW_Hotmail_msg} } |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub retrieve { |
192
|
0
|
|
|
0
|
|
|
my $self = shift; |
193
|
0
|
|
|
|
|
|
my $resp = $self->{_WWW_Hotmail_parent}->get($self->_link()->url().'&raw=0'); |
194
|
0
|
0
|
|
|
|
|
$resp->is_success || do { |
195
|
0
|
|
|
|
|
|
$errstr = $resp->as_string; |
196
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
197
|
0
|
|
|
|
|
|
$errhtml = $resp->error_as_HTML; |
198
|
0
|
|
|
|
|
|
return undef; |
199
|
|
|
|
|
|
|
}; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# fix Hotmail's conversions |
202
|
0
|
|
|
|
|
|
my $content = $self->{_WWW_Hotmail_parent}->content(); |
203
|
0
|
|
|
|
|
|
$content =~ s/</
|
204
|
0
|
|
|
|
|
|
$content =~ s/>/>/gi; |
205
|
0
|
|
|
|
|
|
$content =~ s/"/"/gi; |
206
|
0
|
|
|
|
|
|
$content =~ s/&/&/gi; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# clip the top and bottom |
209
|
0
|
|
|
|
|
|
my @mail = split(/\n/,$content); |
210
|
0
|
|
|
|
|
|
shift @mail; |
211
|
0
|
|
|
|
|
|
pop @mail until $mail[-1] =~ m||; |
212
|
0
|
|
|
|
|
|
pop @mail; |
213
|
|
|
|
|
|
|
# repair line endings |
214
|
0
|
|
|
|
|
|
@mail = map { $_."\n" } @mail; |
|
0
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $msg = Mail::Audit->new(data => \@mail); |
216
|
|
|
|
|
|
|
# set this option for them |
217
|
0
|
|
|
|
|
|
$msg->noexit(1); |
218
|
0
|
|
|
|
|
|
return $msg; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub delete { |
222
|
0
|
|
|
0
|
|
|
my $self = shift; |
223
|
0
|
|
|
|
|
|
my $resp = $self->{_WWW_Hotmail_parent}->get($self->_link()->url()); |
224
|
0
|
0
|
|
|
|
|
$resp->is_success || do { |
225
|
0
|
|
|
|
|
|
$errstr = $resp->as_string; |
226
|
0
|
0
|
|
|
|
|
croak $errstr if $croak_on_error; |
227
|
0
|
|
|
|
|
|
$errhtml = $resp->error_as_HTML; |
228
|
0
|
|
|
|
|
|
return undef; |
229
|
|
|
|
|
|
|
}; |
230
|
|
|
|
|
|
|
# fix java junk |
231
|
0
|
|
|
|
|
|
my $content = $self->{_WWW_Hotmail_parent}->content(); |
232
|
0
|
|
|
|
|
|
$content =~ s/href="#" onclick="/href="/gis; |
233
|
0
|
|
|
|
|
|
$content =~ s/G\('([^']+)'\);return false;/$1/gis; |
234
|
0
|
|
|
|
|
|
$self->{_WWW_Hotmail_parent}->update_html($content); |
235
|
|
|
|
|
|
|
# loop through links and find the delete link |
236
|
0
|
|
|
|
|
|
for (@{$self->{_WWW_Hotmail_parent}->links()}) { |
|
0
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# the delete link |
238
|
0
|
0
|
0
|
|
|
|
if ($_->[0] && $_->[0] =~ m/action=move&tobox=F000000004/i) { |
239
|
0
|
|
|
|
|
|
$self->{_WWW_Hotmail_parent}->get($_->url()); |
240
|
0
|
|
|
|
|
|
last; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
} |
243
|
0
|
|
|
|
|
|
return 1; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
1; |
247
|
|
|
|
|
|
|
__END__ |