--- ./lib/Mail/SpamAssassin/Plugin/RelayCountry.pm.orig 2014-02-07 08:36:27.000000000 +0000 +++ ./lib/Mail/SpamAssassin/Plugin/RelayCountry.pm.orig 2014-03-11 23:38:52.000000000 +0000 @@ -117,18 +117,33 @@ my $msg = $opts->{msg}; my $countries = ''; + my $prev_country = 'Trusted_'; + my $country_tokens = ''; + my $IP_PRIVATE = IP_PRIVATE; foreach my $relay (@{$msg->{metadata}->{relays_untrusted}}) { my $ip = $relay->{ip}; # Private IPs will always be returned as '**' my $cc = $ip =~ /^$IP_PRIVATE$/o ? '**' : $ip_to_cc->($ip); $countries .= $cc." "; + if ($cc ne $prev_country && $cc ne "**") { + $country_tokens .= $prev_country.$cc." "; + if ($prev_country ne 'Trusted_') { + $country_tokens .= "deep_".$cc." "; + } + $prev_country = $cc; + } + } chop $countries; + chop $country_tokens; $msg->put_metadata("X-Relay-Countries", $countries); dbg("metadata: X-Relay-Countries: $countries"); + $msg->put_metadata("X-Relay-Country-Tokens", $country_tokens); + dbg("metadata: X-Relay-Country-Tokens: $country_tokens"); + return 1; } @@ -142,6 +157,11 @@ my @c_list = split(' ', $countries); $opts->{permsgstatus}->set_tag("RELAYCOUNTRY", @c_list == 1 ? $c_list[0] : \@c_list); + my $country_tokens = + $opts->{permsgstatus}->get_message->get_metadata('X-Relay-Country-Tokens'); + my @ct_list = split(' ', $country_tokens); + $opts->{permsgstatus}->set_tag("RELAYCOUNTRYTOKENS", + @ct_list == 1 ? $ct_list[0] : \@ct_list); return 1; }