aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Sapiro <mark@msapiro.net>2018-06-05 12:14:08 -0700
committerMark Sapiro <mark@msapiro.net>2018-06-05 12:14:08 -0700
commit8291c814c54d87c7958304e471a5c5c013417e45 (patch)
treee4a3ff152cb9c352ecf42ccbee0db7c5f06de23c
parentca506e913faa49331db68f541774fdb773653988 (diff)
downloadmailman2-8291c814c54d87c7958304e471a5c5c013417e45.tar.gz
mailman2-8291c814c54d87c7958304e471a5c5c013417e45.tar.xz
mailman2-8291c814c54d87c7958304e471a5c5c013417e45.zip
Extend BLOCK_SPAMHAUS_LISTED_IP_SUBSCRIBE for IPv6.
Fix string formatting for Python 2.6.
-rw-r--r--Mailman/Utils.py28
-rw-r--r--NEWS4
2 files changed, 24 insertions, 8 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py
index cdc82366..6038667b 100644
--- a/Mailman/Utils.py
+++ b/Mailman/Utils.py
@@ -79,6 +79,12 @@ try:
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 xml_to_unicode(s, cset):
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)
diff --git a/NEWS b/NEWS
index ff4debae..e037982c 100644
--- a/NEWS
+++ b/NEWS
@@ -26,7 +26,9 @@ Here is a history of user visible changes to Mailman.
- 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