You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by fe...@apache.org on 2004/10/11 15:01:36 UTC

svn commit: rev 54577 - spamassassin/branches/3.0/lib/Mail/SpamAssassin/Util

Author: felicity
Date: Mon Oct 11 06:01:35 2004
New Revision: 54577

Modified:
   spamassassin/branches/3.0/lib/Mail/SpamAssassin/Util/RegistrarBoundaries.pm
Log:
bug 3831: due to the RegistrarBoundaries REs being too loose, we would often misparse the given domain into the wrong number of parts.  make the RE more strict to avoid this issue and also skip doing the RE check when the RE can't possibly match based on number of parts in the string.

Modified: spamassassin/branches/3.0/lib/Mail/SpamAssassin/Util/RegistrarBoundaries.pm
==============================================================================
--- spamassassin/branches/3.0/lib/Mail/SpamAssassin/Util/RegistrarBoundaries.pm	(original)
+++ spamassassin/branches/3.0/lib/Mail/SpamAssassin/Util/RegistrarBoundaries.pm	Mon Oct 11 06:01:35 2004
@@ -987,12 +987,10 @@
 
 sub split_domain {
   my ($domain) = @_;
-
-  # turn "host.dom.ain" into "dom.ain".
   my $hostname = '';
 
   if ($domain) {
-    my $partsreqd;
+    my $partsreqd = 2;	# default to domain.tld
 
     # www..spamassassin.org -> www.spamassassin.org
     $domain =~ tr/././s;
@@ -1001,17 +999,20 @@
     $domain =~ s/^\.+//;
     $domain =~ s/\.+$//;
 
-    if ($domain =~ /${FOUR_LEVEL_DOMAINS}/io)     # Fire-Dept.CI.Los-Angeles.CA.US
+    # Split scalar domain into components
+    my @domparts = split (/\./, $domain);
+
+    # Look for a sub-delegated TLD
+    # use @domparts to skip trying to match on TLDs that can't possibly
+    # match, but keep in mind that the hostname can be blank, so 4TLD needs 4,
+    # 3TLD needs 3, 2TLD needs 2 ...
+    #
+    if (@domparts >= 4 && $domain =~ /(?:\.|^)${FOUR_LEVEL_DOMAINS}$/io)     # Fire-Dept.CI.Los-Angeles.CA.US
     { $partsreqd = 5; }
-    elsif ($domain =~ /${THREE_LEVEL_DOMAINS}/io) # demon.co.uk
+    elsif (@domparts >= 3 && $domain =~ /(?:\.|^)${THREE_LEVEL_DOMAINS}$/io) # demon.co.uk
     { $partsreqd = 4; }
-    elsif ($domain =~ /${TWO_LEVEL_DOMAINS}/io)   # co.uk
+    elsif (@domparts >= 2 && $domain =~ /(?:\.|^)${TWO_LEVEL_DOMAINS}$/io)   # co.uk
     { $partsreqd = 3; }
-    else                                          # com
-    { $partsreqd = 2; }
-
-    # drop any hostname parts, if we can.
-    my @domparts = split (/\./, $domain);
 
     if (@domparts >= $partsreqd) {
       # reset the domain to the last $partsreqd parts