------------------------------------------------------------
revno: 1766
fixes bug: https://launchpad.net/bugs/1775233
committer: Mark Sapiro <m...@msapiro.net>
branch nick: 2.1
timestamp: Tue 2018-06-05 12:14:08 -0700
message:
  Extend BLOCK_SPAMHAUS_LISTED_IP_SUBSCRIBE for IPv6.
  Fix string formatting for Python 2.6.
modified:
  Mailman/Utils.py
  NEWS


--
lp:mailman/2.1
https://code.launchpad.net/~mailman-coders/mailman/2.1

Your team Mailman Checkins is subscribed to branch lp:mailman/2.1.
To unsubscribe from this branch go to 
https://code.launchpad.net/~mailman-coders/mailman/2.1/+edit-subscription
=== modified file 'Mailman/Utils.py'
--- Mailman/Utils.py	2018-06-05 02:19:31 +0000
+++ Mailman/Utils.py	2018-06-05 19:14:08 +0000
@@ -79,6 +79,12 @@
 except ImportError:
     dns_resolver = False
 
+try:
+    import ipaddress
+    have_ipaddress = True
+except ImportError:
+    have_ipaddress = False
+
 EMPTYSTRING = ''
 UEMPTYSTRING = u''
 CR = '\r'
@@ -1498,13 +1504,21 @@
 def banned_ip(ip):
     if not dns_resolver:
         return False
-    parts = ip.split('.')
-    if len(parts) != 4:
-        return False
-    lookup = '{}.{}.{}.{}.zen.spamhaus.org'.format(parts[3],
-                                                   parts[2],
-                                                   parts[1],
-                                                   parts[0])
+    if have_ipaddress:
+        try:
+            uip = unicode(ip, encoding='us-ascii', errors='replace')
+            ptr = ipaddress.ip_address(uip).reverse_pointer
+        except ValueError:
+            return False
+	lookup = '{0}.zen.spamhaus.org'.format('.'.join(ptr.split('.')[:-2]))
+    else:
+        parts = ip.split('.')
+        if len(parts) != 4:
+            return False
+        lookup = '{0}.{1}.{2}.{3}.zen.spamhaus.org'.format(parts[3],
+                                                           parts[2],
+                                                           parts[1],
+                                                           parts[0])
     resolver = dns.resolver.Resolver()
     try:
         ans = resolver.query(lookup, dns.rdatatype.A)

=== modified file 'NEWS'
--- NEWS	2018-06-05 02:19:31 +0000
+++ NEWS	2018-06-05 19:14:08 +0000
@@ -26,7 +26,9 @@
 
     - A new BLOCK_SPAMHAUS_LISTED_IP_SUBSCRIBE setting has been added to
       enable blocking web subscribes from IPv4 addresses listed in Spamhaus
-      SBL, CSS or XBL.
+      SBL, CSS or XBL.  It will work with IPv6 addresses if Python's
+      py2-ipaddress module is installed.  The module can be installed via pip
+      if not included in your Python.
 
   i18n
 

_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: 
https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to