| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Mechanize::SpamCop; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Abso: abso/divers/mat/perl/WWW-Mechanize-SpamCop/SpamCop.pm,v 1.4 2003/08/05 14:28:00 mat Exp $ |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
#---[ pod head ]---{{{ |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
WWW::Mechanize::SpamCop - SpamCop reporting automation. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use WWW::Mechanize::SpamCop; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$s = WWW::Mechanize::SpamCop->new( |
|
16
|
|
|
|
|
|
|
login => 'login@spamcop.net', |
|
17
|
|
|
|
|
|
|
passwd => 'passwd' |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$s->report_one; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$s->report_all; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 ABSTRACT |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
WWW::Mechanize::SpamCop is used to automate spam reporting on spamcop.net's web |
|
28
|
|
|
|
|
|
|
site. |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#---}}} |
|
37
|
|
|
|
|
|
|
|
|
38
|
1
|
|
|
1
|
|
21596
|
use WWW::Mechanize; |
|
|
1
|
|
|
|
|
182916
|
|
|
|
1
|
|
|
|
|
46
|
|
|
39
|
1
|
|
|
1
|
|
11
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
40
|
|
|
40
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
8
|
|
|
|
1
|
|
|
|
|
90
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
1
|
|
|
1
|
|
6
|
use vars qw(@ISA $VERSION); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
761
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
@ISA = qw(WWW::Mechanize); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$VERSION = '0.08'; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
#---[ sub new ]---{{{ |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 new |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Create a new WWW::Mechanize::SpamCop object |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
The required arguments are login and passwd, you can also pass it a host, |
|
55
|
|
|
|
|
|
|
defaulting to 'www.spamcop.net:80' (the :80 is needed because of the |
|
56
|
|
|
|
|
|
|
authentication), a realm, defaulting to 'your SpamCop account' which is the |
|
57
|
|
|
|
|
|
|
domain's realm for autentication. and a report default to 'Report Now', which |
|
58
|
|
|
|
|
|
|
is the name of the link on the web page. |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub new { |
|
63
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
|
64
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
|
65
|
0
|
|
|
|
|
|
my %p = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
croak 'You must specify a login' |
|
68
|
|
|
|
|
|
|
unless ( exists( $p{login} ) ); |
|
69
|
0
|
0
|
|
|
|
|
croak 'You must specify a passwd' |
|
70
|
|
|
|
|
|
|
unless ( exists( $p{passwd} ) ); |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $login = delete( $p{login} ); |
|
73
|
0
|
|
|
|
|
|
my $passwd = delete( $p{passwd} ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new(%p); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
0
|
|
|
|
$self->{host} = $p{host} || 'www.spamcop.net:80'; |
|
78
|
0
|
|
0
|
|
|
|
$self->{realm} = $p{realm} || 'your SpamCop account'; |
|
79
|
0
|
|
0
|
|
|
|
$self->{report} = $p{report} || 'Report Now'; |
|
80
|
0
|
|
0
|
|
|
|
$self->{regex_remove_unreported} = $p{regex_remove_unreported} || qr/^Remove all unreported/; |
|
81
|
0
|
|
0
|
|
|
|
$self->{regex_removed_count} = $p{regex_removed_count} || qr/Removed\s+([0-9]+)\s+unreported/i; |
|
82
|
0
|
|
0
|
|
|
|
$self->{sendformname} = $p{sendformname} || 'sendreport'; |
|
83
|
0
|
|
|
|
|
|
$self->{login} = $login; |
|
84
|
0
|
|
|
|
|
|
$self->{passwd} = $passwd; |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
croak 'SomeThing went wrong' |
|
87
|
|
|
|
|
|
|
unless $self->get("http://$self->{host}/"); |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$self->form_number(1); |
|
90
|
0
|
|
|
|
|
|
$self->field('username', $self->{login}); |
|
91
|
0
|
|
|
|
|
|
$self->field('password', $self->{passwd}); |
|
92
|
0
|
0
|
|
|
|
|
$self->click() or return undef; |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $self; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#---}}} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#---[ sub report_one ]---{{{ |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 report_one |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Report one spam |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
returns : |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item undef |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
no spam was found |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item 1 |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
if a spam was reported |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item 2 |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
if the spam was too old |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub report_one { |
|
126
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
if ( $self->follow_link( text => $self->{report} ) ) { |
|
129
|
|
|
|
|
|
|
# Probably makes no sense because currently there's a submission form instead of link: |
|
130
|
|
|
|
|
|
|
#if ( $self->find_link( text => $self->{report} ) ) { |
|
131
|
|
|
|
|
|
|
# return 2; |
|
132
|
|
|
|
|
|
|
#} |
|
133
|
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my @forms = $self->forms(); |
|
135
|
|
|
|
|
|
|
# Look for "send report" form: |
|
136
|
0
|
0
|
|
|
|
|
if (scalar(@forms) < 1) { return undef }; |
|
|
0
|
|
|
|
|
|
|
|
137
|
0
|
0
|
|
|
|
|
@forms = grep { defined ($_->attr("name")) && $_->attr("name") eq $self->{sendformname}} @forms; |
|
|
0
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# If a form with the proper name is found, submit report: |
|
139
|
0
|
0
|
|
|
|
|
if (@forms) { |
|
140
|
0
|
|
|
|
|
|
$self->form_name($self->{sendformname}); |
|
141
|
0
|
0
|
|
|
|
|
$self->click() or return undef; |
|
142
|
0
|
|
|
|
|
|
return 1; |
|
143
|
|
|
|
|
|
|
} else { |
|
144
|
0
|
|
|
|
|
|
return 2; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} else { |
|
148
|
0
|
|
|
|
|
|
return undef; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
#---}}} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#---[ sub report_all ]---{{{ |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 report_all |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Report all waiting spams |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
If called in a scalar context, returns the number of spam reported. If in an |
|
161
|
|
|
|
|
|
|
array context, returns an array containing the number of reported spams and the |
|
162
|
|
|
|
|
|
|
number of old spams (not reported). |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub report_all { |
|
167
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
168
|
0
|
|
|
|
|
|
my ( $i, $j ) = ( 0, 0 ); |
|
169
|
0
|
|
|
|
|
|
while ( my $r = $self->report_one ) { |
|
170
|
0
|
0
|
|
|
|
|
$i++ if ( $r == 1 ); |
|
171
|
0
|
0
|
|
|
|
|
$j++ if ( $r == 2 ); |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
0
|
0
|
|
|
|
|
return unless defined wantarray; |
|
175
|
0
|
0
|
|
|
|
|
return ( wantarray ? ( $i, $j ) : $i ); |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
#---}}} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
#---[ sub remove_unreported ]---{{{ |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head2 remove_unreported |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Removes all unreported spams. Returns the number of removed spams as scalar value. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub remove_unreported { |
|
190
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
191
|
0
|
|
|
|
|
|
my $count = 0; |
|
192
|
0
|
0
|
|
|
|
|
if ( $self->follow_link( text_regex => $self->{regex_remove_unreported} ) ) { |
|
193
|
0
|
|
|
|
|
|
my $content = $self->content( format => "text" ); |
|
194
|
0
|
|
|
|
|
|
my $regex_removed_count = $self->{regex_removed_count}; |
|
195
|
0
|
0
|
|
|
|
|
if ($content =~ qr/$regex_removed_count/si) { |
|
196
|
0
|
|
|
|
|
|
$count = $1; |
|
197
|
|
|
|
|
|
|
} |
|
198
|
0
|
|
|
|
|
|
return $count; |
|
199
|
|
|
|
|
|
|
} else { |
|
200
|
0
|
|
|
|
|
|
return 0; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
#---}}} |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
1; |
|
207
|
|
|
|
|
|
|
__END__ |