http://bugzilla.spamassassin.org/show_bug.cgi?id=3417
------- Additional Comments From [EMAIL PROTECTED] 2004-05-23 01:52 -------
new version of sub:
sub check_for_from_mx {
my ($self) = @_;
my $from = $self->get ('Reply-To:addr');
if (!defined $from || $from !~ /[EMAIL PROTECTED]/) {
$from = $self->get ('From:addr');
}
return 0 unless ($from =~ /\@(\S+)/);
$from = $1;
# First check that DNS is available, if not do not perform this check
return 0 unless $self->is_dns_available();
$self->load_resolver();
if ($from eq 'compiling.spamassassin.taint.org') {
# only used when compiling
return 0;
}
if ($self->{conf}->{check_mx_attempts} < 1) {
return 0;
}
local ($_);
# First check that DNS is available, if not do not perform this check
return 0 if $self->{conf}->{skip_rbl_checks};
return 0 unless $self->is_dns_available();
$self->load_resolver();
# How many IPs max you check in the received lines
my $checklast=$self->{conf}->{num_check_received};
my @fullips = map { $_->{ip} } @{$self->{relays_untrusted}};
# Make sure a header significantly improves results before adding here
# X-Sender-Ip: could be worth using (very low occurance for me)
# X-Sender: has a very low bang-for-buck for me
my @originating;
for my $header ('X-Originating-IP', 'X-Apparently-From') {
my $str = $self->get($header);
next unless defined $str;
push (@originating, ($str =~ m/($IP_ADDRESS)/g));
}
return 0 unless (scalar @fullips + scalar @originating > 0);
# Let's go ahead and trim away all Reserved ips (KLC)
# also uniq the list and strip dups. (jm)
my @ips = ();
my %seen = ();
foreach my $ip (@fullips) {
next if (exists ($seen{$ip})); $seen{$ip} = 1;
if (!($ip =~ /${IP_IN_RESERVED_RANGE}/o)) { push(@ips, $ip); }
}
dbg("From_MX: Got the following IPs: ".join(", ", @ips));
if (scalar @ips + scalar @originating > 0) {
# create a new list to avoid undef errors
my @newips = ();
my $i; for ($i = 0; $i < $checklast; $i++) {
my $ip = pop @ips; last unless defined($ip);
push (@newips, $ip);
}
# add originating IPs as untrusted IPs
for my $ip (@originating) {
next if (exists ($seen{$ip})); $seen{$ip} = 1;
if (!($ip =~ /${IP_IN_RESERVED_RANGE}/o)) { push(@newips, $ip); }
}
@ips = @newips;
}
dbg("From_MX: But only inspecting the following IPs: " . join(", ", @ips));
# Try check_mx_attempts times to protect against temporary outages.
# sleep between checks to give the DNS a chance to recover.
my @mxips = ();
for my $i (1..$self->{conf}->{check_mx_attempts}) {
my @mx = Net::DNS::mx($self->{res}, $from);
dbg ("From_MX: DNS MX records found: " . scalar(@mx));
foreach my $mx (@mx) {
my $query = $self->{res}->search($mx->exchange);
if ($query) {
my $count = 0;
foreach my $rr ($query->answer) {
if ($rr->type eq "A") {
$count++;
push (@mxips, $rr->rdatastr);
}
}
dbg ("From_MX: DNS A records found: $count");
}
}
if ($i < $self->{conf}->{check_mx_attempts}) {sleep
$self->{conf}->{check_mx_delay}; };
}
dbg("From_MX: DNS MX A records: " . join(", ", @mxips)) if (scalar @mxips >
0);
foreach my $ip (@ips) {
my $flag = 1;
foreach my $mxip (@mxips) {
$flag = 0 if ($ip eq $mxip);
}
return 1 if ($flag eq 1);
}
return 0;
}
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.