You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2019/07/05 08:51:39 UTC
svn commit: r1862595 - in /spamassassin/trunk: UPGRADE
lib/Mail/SpamAssassin/Plugin/RelayCountry.pm
Author: hege
Date: Fri Jul 5 08:51:39 2019
New Revision: 1862595
URL: http://svn.apache.org/viewvc?rev=1862595&view=rev
Log:
Bug 7731 - Add external and msa metadata to RelayCountry
Modified:
spamassassin/trunk/UPGRADE
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm
Modified: spamassassin/trunk/UPGRADE
URL: http://svn.apache.org/viewvc/spamassassin/trunk/UPGRADE?rev=1862595&r1=1862594&r2=1862595&view=diff
==============================================================================
--- spamassassin/trunk/UPGRADE (original)
+++ spamassassin/trunk/UPGRADE Fri Jul 5 08:51:39 2019
@@ -49,6 +49,9 @@ Note for Users Upgrading to SpamAssassin
Utilized by RelayCountry and URILocalBL. Settings geodb_module, geodb_options,
geodb_search_path.
+- RelayCountry: Added new metadata: X-Spam-Countries-External (_RELAYCOUNTRYEXT_),
+ X-Spam-Countries-MUA (_RELAYCOUNTRYMUA_), X-Spam-Countries-All (_RELAYCOUNTRYALL_)
+
- new plugin callback method check_cleanup
- Razor2 razor_fork option added. It will fork separate Razor2 process and
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm?rev=1862595&r1=1862594&r2=1862595&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm Fri Jul 5 08:51:39 2019
@@ -27,8 +27,14 @@ RelayCountry - add message metadata indi
The RelayCountry plugin attempts to determine the domain country codes
of each relay used in the delivery path of messages and add that information
-to the message metadata as "X-Relay-Countries", or the C<_RELAYCOUNTRY_>
-header markup.
+to the message metadata.
+
+Following metadata headers and tags are added:
+
+X-Relay-Countries _RELAYCOUNTRY_ all untrusted relays
+X-Relay-Countries-External _RELAYCOUNTRYEXT_ all external relays
+X-Relay-Countries-MUA _RELAYCOUNTRYMUA_ all relays after first MSA
+X-Relay-Countries-All _RELAYCOUNTRYALL_ all relays
=head1 REQUIREMENT
@@ -84,16 +90,56 @@ sub extract_metadata {
my $msg = $opts->{msg};
my $geodb = $self->{main}->{geodb};
- my $countries = '';
+ my @cc_untrusted;
foreach my $relay (@{$msg->{metadata}->{relays_untrusted}}) {
my $ip = $relay->{ip};
my $cc = $geodb->get_country($ip);
- $countries .= $cc." ";
+ push @cc_untrusted, $cc;
+ }
+
+ my @cc_external;
+ foreach my $relay (@{$msg->{metadata}->{relays_external}}) {
+ my $ip = $relay->{ip};
+ my $cc = $geodb->get_country($ip);
+ push @cc_external, $cc;
+ }
+
+ my @cc_mua;
+ my $found_msa;
+ foreach my $relay (@{$msg->{metadata}->{relays_trusted}}) {
+ if ($relay->{msa}) {
+ $found_msa = 1;
+ next;
+ }
+ if ($found_msa) {
+ my $ip = $relay->{ip};
+ my $cc = $geodb->get_country($ip);
+ push @cc_mua, $cc;
+ }
}
- chop $countries;
- $msg->put_metadata("X-Relay-Countries", $countries);
- dbg("metadata: X-Relay-Countries: $countries");
+ my @cc_all;
+ foreach my $relay (@{$msg->{metadata}->{relays_internal}}, @{$msg->{metadata}->{relays_external}}) {
+ my $ip = $relay->{ip};
+ my $cc = $geodb->get_country($ip);
+ push @cc_all, $cc;
+ }
+
+ my $ccstr = join(' ', @cc_untrusted);
+ $msg->put_metadata("X-Relay-Countries", $ccstr);
+ dbg("metadata: X-Relay-Countries: $ccstr");
+
+ $ccstr = join(' ', @cc_external);
+ $msg->put_metadata("X-Relay-Countries-External", $ccstr);
+ dbg("metadata: X-Relay-Countries-External: $ccstr");
+
+ $ccstr = join(' ', @cc_mua);
+ $msg->put_metadata("X-Relay-Countries-MUA", $ccstr);
+ dbg("metadata: X-Relay-Countries-MUA: $ccstr");
+
+ $ccstr = join(' ', @cc_all);
+ $msg->put_metadata("X-Relay-Countries-All", $ccstr);
+ dbg("metadata: X-Relay-Countries-All: $ccstr");
}
sub parsed_metadata {
@@ -101,11 +147,26 @@ sub parsed_metadata {
return 1 if $self->{relaycountry_disabled};
- my $countries =
- $opts->{permsgstatus}->get_message->get_metadata('X-Relay-Countries');
- my @c_list = split(' ', $countries);
+ my @c_list = split(' ',
+ $opts->{permsgstatus}->get_message->get_metadata('X-Relay-Countries'));
$opts->{permsgstatus}->set_tag("RELAYCOUNTRY",
@c_list == 1 ? $c_list[0] : \@c_list);
+
+ @c_list = split(' ',
+ $opts->{permsgstatus}->get_message->get_metadata('X-Relay-Countries-External'));
+ $opts->{permsgstatus}->set_tag("RELAYCOUNTRYEXT",
+ @c_list == 1 ? $c_list[0] : \@c_list);
+
+ @c_list = split(' ',
+ $opts->{permsgstatus}->get_message->get_metadata('X-Relay-Countries-MUA'));
+ $opts->{permsgstatus}->set_tag("RELAYCOUNTRYMUA",
+ @c_list == 1 ? $c_list[0] : \@c_list);
+
+ @c_list = split(' ',
+ $opts->{permsgstatus}->get_message->get_metadata('X-Relay-Countries-All'));
+ $opts->{permsgstatus}->set_tag("RELAYCOUNTRYALL",
+ @c_list == 1 ? $c_list[0] : \@c_list);
+
return 1;
}