App-SpamcupNG
view release on metacpan or search on metacpan
lib/App/SpamcupNG.pm view on Meta::CPAN
return 0;
}
=pod
=head2 main_loop
Processes all the pending SPAM reports in a loop until finished.
Expects as parameter (in this sequence):
=over
=item *
a L<LWP::UserAgent> instance
=item *
A hash reference with the following key/values:
=over
=item *
ident => The identity to Spamcop
=item *
pass => The password to Spamcop
=item *
delay => time in seconds to wait for next iteration with Spamcop website
=item *
verbosity => defines what level of information should be provided. Uses the
same values as defined by L<Log::Log4perl>.
As confusing as it seems, current implementation may accept debug messages
B<and> disable other messages.
=item *
check_only => true (1) or false (0) to only check for unreported SPAM, but not
reporting them
=back
=back
Returns true if everything went right, or C<die> if a fatal error happened.
=cut
sub main_loop {
my ( $ua, $opts_ref ) = @_;
my $logger = get_logger('SpamcupNG');
binmode( STDOUT, ":utf8" );
# last seen SPAM id
my $last_seen;
# Get first page that contains link to next one...
if ( $logger->is_debug ) {
$logger->debug( "Sleeping for " . $opts_ref->{delay} . ' seconds' );
}
sleep $opts_ref->{delay};
my $response_ref = $ua->login( $opts_ref->{ident}, $opts_ref->{pass} );
return 0 if ( _error_handling($response_ref) );
$logger->debug('Log in completed');
my $next_id;
my $summary = App::SpamcupNG::Summary->new;
if ($response_ref) {
$next_id = find_next_id($response_ref);
if ( $logger->is_debug ) {
$logger->debug("ID of next SPAM report found: $next_id")
if ($next_id);
}
$summary->set_tracking_id($next_id);
return -1 unless ( defined($next_id) );
}
else {
return 0;
}
# avoid loops
if ( ($last_seen) and ( $next_id eq $last_seen ) ) {
$logger->die(
'I have seen this ID earlier, we do not want to report it again.'
. 'This usually happens because of a bug in Spamcup.'
. 'Make sure you use latest version!'
. "You may also want to go check from Spamcop what is happening: http://www.spamcop.net/sc?id=$next_id"
);
}
$last_seen = $next_id; # store for comparison
# Fetch the SPAM report form
if ( $logger->is_debug ) {
$logger->debug( 'Sleeping for ' . $opts_ref->{delay} . ' seconds' );
}
sleep $opts_ref->{delay};
# Getting a SPAM report
$response_ref = $ua->spam_report($next_id);
return 0 unless ($response_ref);
if ( my $age_info_ref = find_message_age($response_ref) ) {
if ($age_info_ref) {
if ( $logger->is_info ) {
$logger->info( 'Message age: '
( run in 0.929 second using v1.01-cache-2.11-cpan-140bd7fdf52 )