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/26 07:27:39 UTC

svn commit: r1863776 - in /spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin: RelayCountry.pm URILocalBL.pm

Author: hege
Date: Fri Jul 26 07:27:39 2019
New Revision: 1863776

URL: http://svn.apache.org/viewvc?rev=1863776&view=rev
Log:
Bug 7741 - Support City database now properly

Modified:
    spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm
    spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm

Modified: spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm?rev=1863776&r1=1863775&r2=1863776&view=diff
==============================================================================
--- spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm (original)
+++ spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/RelayCountry.pm Fri Jul 26 07:27:39 2019
@@ -133,6 +133,7 @@ If not defined, GeoIP2 default search in
  /usr/local/share/GeoIP/GeoLite2-Country.mmdb
  /usr/share/GeoIP/GeoLite2-Country.mmdb
  /var/lib/GeoIP/GeoLite2-Country.mmdb
+ (and same paths again for -City.mmdb, which also has country functionality)
 
 =back
 
@@ -165,6 +166,12 @@ If not defined, GeoIP2 default search in
       '/usr/local/share/GeoIP/GeoLite2-Country.mmdb',
       '/usr/share/GeoIP/GeoLite2-Country.mmdb',
       '/var/lib/GeoIP/GeoLite2-Country.mmdb',
+      '/usr/local/share/GeoIP/GeoIP2-City.mmdb',
+      '/usr/share/GeoIP/GeoIP2-City.mmdb',
+      '/var/lib/GeoIP/GeoIP2-City.mmdb',
+      '/usr/local/share/GeoIP/GeoLite2-City.mmdb',
+      '/usr/share/GeoIP/GeoLite2-City.mmdb',
+      '/var/lib/GeoIP/GeoLite2-City.mmdb',
       ],
     type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRINGLIST,
     code => sub {
@@ -199,7 +206,11 @@ sub get_country {
     elsif ($country_db_type eq "GeoIP2") {
       my ($country, $country_rec);
       eval {
-        $country = $db->country( ip => $ip );
+        if (index($db->metadata()->description()->{en}, 'City') != -1) {
+          $country = $db->city( ip => $ip );
+        } else {
+          $country = $db->country( ip => $ip );
+        }
         $country_rec = $country->country();
         $cc = $country_rec->iso_code();
         1;

Modified: spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm?rev=1863776&r1=1863775&r2=1863776&view=diff
==============================================================================
--- spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm (original)
+++ spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm Fri Jul 26 07:27:39 2019
@@ -358,7 +358,7 @@ sub set_config {
 =item uri_country_db_path STRING
 
 This option tells SpamAssassin where to find the MaxMind country GeoIP2 
-database.
+database. Country or City database are both supported.
 
 =back
 
@@ -557,7 +557,12 @@ sub check_uri_local_bl {
           dbg("check: uri_local_bl countries %s\n", join(' ', sort keys %{$rule->{countries}}));
 
           if ( $self->{use_geoip2} == 1 ) {
-            my $country = $self->{geoip}->country( ip => $ip );
+            my $country;
+            if (index($self->{geoip}->metadata()->description()->{en}, 'City') != -1) {
+              $country = $self->{geoip}->city( ip => $ip );
+            } else {
+              $country = $self->{geoip}->country( ip => $ip );
+            }
             my $country_rec = $country->country();
             $cc = $country_rec->iso_code();
           } else {