Dallas L. Engelken wrote:
|| 5;
+ my $timer =
Mail::SpamAssassin::Timeout->new({ secs =>
$timeout
});
+ my $err = $time->run_and_catch(sub {
+ $answer =
I assume you mean $timer-> (vs $time->) there?
D
This diff seems to work. I'm going to let it run while I can watch it
and see what happens.
Anyone let me know if you'd rather an attachment.
If anyone sees anything really stupid, please let me know, I'm thick
skinned :)
Regards,
Rick
--- ixhash.pm.old 2006-07-10 19:43:50.226400000 -0400
+++ ixhash.pm 2006-07-10 19:53:10.497730000 -0400
@@ -32,6 +32,7 @@
use Mail::SpamAssassin;
use Mail::SpamAssassin::Plugin;
use Mail::SpamAssassin::Util;
+use Mail::SpamAssassin::Timeout;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use Net::DNS;
use Net::DNS::Resolver;
@@ -74,6 +75,7 @@
my ($digest,$answer,$ixdigest,$body) = "";
my @body = $permsgstatus->{msg}->get_body();
my $resolver = Net::DNS::Resolver->new;
+ my $timeout = $permsgstatus->{main}->{conf}->{'ixhash_timeout'}
|| 5;
my $body_copy = "";
foreach (@body) {
$body .= join "", @$_;
@@ -85,12 +87,6 @@
# here we implement proper alarms, ala Pyzor, Razor2 plugins.
# keep the alarm as $oldalarm, so we dont loose the
timeout-child alarm
# see
http://issues.apache.org/SpamAssassin/show_bug.cgi?id=3828#c123
- my $oldalarm = 0;
- my $timeout = $permsgstatus->{main}->{conf}->{'ixhash_timeout'}
|| 5;
- eval {
- Mail::SpamAssassin::Util::trap_sigalrm_fully(sub { die
"ixhash
timeout reached"; });
- $oldalarm = alarm($timeout);
-
#----------------------------------------------------------------------
-
# Creation of hash # 1 if following conditions are met:
# - mail contains at least 16 spaces or tabs
@@ -112,7 +108,11 @@
dbg ("IXHASH: Computed hash-value $digest via method 1");
dbg ("IXHASH: Now checking $digest.$dnsserver");
# Now check via DNS query
- $answer = $resolver->search($digest.'.'.$dnsserver,
"A", "IN");
+ my $timer = Mail::SpamAssassin::Timeout->new({ secs =>
$timeout
});
+ my $err = $timer->run_and_catch(sub {
+ $answer =
$resolver->search($digest.'.'.$dnsserver, "A",
"IN");
+ });
+
if ($answer) {
foreach $rr ($answer->answer) {
next unless $rr->type eq "A";
@@ -120,6 +120,11 @@
$hits = 1 if $rr->address;
}
}
+
+ if ($timer->timed_out()) {
+ dbg("ixhash: check timed out after $timeout
seconds");
+ return 0;
+ }
}
# End of computing hash #1
#---------------------------------------------------------------------
@@ -146,7 +151,10 @@
dbg ("IXHASH: Computed hash-value $digest via method 2");
dbg ("IXHASH: Now checking $digest.$dnsserver");
# Now check via DNS query
- $answer = $resolver->search($digest.'.'.$dnsserver,
"A", "IN");
+ my $timer = Mail::SpamAssassin::Timeout->new({ secs =>
$timeout
});
+ my $err = $timer->run_and_catch(sub {
+ $answer =
$resolver->search($digest.'.'.$dnsserver, "A",
"IN");
+ });
if ($answer) {
foreach $rr ($answer->answer) {
next unless $rr->type eq "A";
@@ -154,6 +162,10 @@
$hits = 1 if $rr->address;
}
}
+ if ($timer->timed_out()) {
+ dbg("ixhash: check timed out after $timeout
seconds");
+ return 0;
+ }
}
# End of computing hash #2
@@ -178,7 +190,10 @@
dbg ("IXHASH: Computed hash-value $digest via method 3");
dbg ("IXHASH: Now checking $digest.$dnsserver");
# Check via DNS
- $answer = $resolver->search($digest.'.'.$dnsserver,
"A", "IN");
+ my $timer = Mail::SpamAssassin::Timeout->new({ secs =>
$timeout
});
+ my $err = $timer->run_and_catch(sub {
+ $answer =
$resolver->search($digest.'.'.$dnsserver, "A",
"IN");
+ });
if ($answer) {
foreach $rr ($answer->answer) {
next unless $rr->type eq "A";
@@ -186,18 +201,11 @@
$hits = 1 if $rr->address;
}
}
+ if ($timer->timed_out()) {
+ dbg("ixhash: check timed out after $timeout
seconds");
+ return 0;
+ }
}
- if (defined $oldalarm) {
- alarm $oldalarm; $oldalarm = undef;
- }
+ return $hits;
}; # End of sub ixhashtest
-
-# Error handling - parto of Dallas' code
-if ($@ =~ m/timeout/) {
- dbg("IXHASH: $timeout second timeout exceeded while checking
$digest.$d
nsserver");
-}
-
-return $hits;
-
-}
1;