in lib/Mail/SpamAssassin/Plugin/URIDetail.pm [189:319]
sub check_uri_detail {
my ($self, $permsg) = @_;
my $test = $permsg->{current_rule_name};
my $rule = $permsg->{conf}->{uri_detail}->{$test};
my %uri_detail = %{ $permsg->get_uri_detail_list() };
while (my ($raw, $info) = each %uri_detail) {
next if $info->{types}->{unlinked};
dbg("uri: running uri_detail $test: $raw");
if (exists $rule->{raw}) {
my($op,$patt,$neg) = @{$rule->{raw}};
my $match = 0;
if ( ($op eq '=~' && $raw =~ $patt) ||
($op eq '!~' && $raw !~ $patt) ) {
$match = 1;
}
$match = 1-$match if $neg;
next unless $match;
}
if (exists $rule->{type}) {
my($op,$patt,$neg) = @{$rule->{type}};
my $match;
if ( $info->{types} ) {
for my $text (keys %{$info->{types}}) {
if (($op eq '=~' && $text =~ $patt) ||
($op eq '!~' && $text !~ $patt)) {
$match = $text;
last
}
}
}
if ( $neg ) {
next if defined $match;
dbg("uri: type negative matched: %s /%s/", $op,$patt);
} else {
next unless defined $match;
dbg("uri: type matched: '%s' %s /%s/", $match,$op,$patt);
}
}
if (exists $rule->{cleaned}) {
my($op,$patt,$neg) = @{$rule->{cleaned}};
my $match;
if ( $info->{cleaned} ) {
for my $text (@{$info->{cleaned}}) {
if (($op eq '=~' && $text =~ $patt) ||
($op eq '!~' && $text !~ $patt)) {
$match = $text;
last
}
}
}
if ( $neg ) {
next if defined $match;
dbg("uri: cleaned negative matched: %s /%s/", $op,$patt);
} else {
next unless defined $match;
dbg("uri: cleaned matched: '%s' %s /%s/", $match,$op,$patt);
}
}
if (exists $rule->{text}) {
my($op,$patt,$neg) = @{$rule->{text}};
my $match;
if ( $info->{anchor_text} ) {
for my $text (@{$info->{anchor_text}}) {
if (($op eq '=~' && $text =~ $patt) ||
($op eq '!~' && $text !~ $patt)) {
$match = $text;
last
}
}
}
if ( $neg ) {
next if defined $match;
dbg("uri: text negative matched: %s /%s/", $op,$patt);
} else {
next unless defined $match;
dbg("uri: text matched: '%s' %s /%s/", $match,$op,$patt);
}
}
if (exists $rule->{domain}) {
my($op,$patt,$neg) = @{$rule->{domain}};
my $match;
if ( $info->{domains} ) {
for my $text (keys %{ $info->{domains} }) {
if ( ($op eq '=~' && $text =~ $patt) ||
($op eq '!~' && $text !~ $patt) ) { $match = $text; last }
}
}
if ( $neg ) {
next if defined $match;
dbg("uri: domain negative matched: %s /%s/", $op,$patt);
} else {
next unless defined $match;
dbg("uri: domain matched: '%s' %s /%s/", $match,$op,$patt);
}
}
if (exists $rule->{host}) {
my($op,$patt,$neg) = @{$rule->{host}};
my $match;
if ( $info->{hosts} ) {
for my $text (keys %{$info->{hosts}}) {
if (($op eq '=~' && $text =~ $patt) ||
($op eq '!~' && $text !~ $patt)) {
$match = $text;
last
}
}
}
if ( $neg ) {
next if defined $match;
dbg("uri: host negative matched: %s /%s/", $op,$patt);
} else {
next unless defined $match;
dbg("uri: host matched: '%s' %s /%s/", $match, $op, $patt);
}
}
dbg("uri: all criteria for $test met - HIT");
return 1;
}
return 0;
}