git.schokokeks.org
Repositories
Help
Report an Issue
keks-overlay.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
b5be8cb
Branches
Tags
master
keks-overlay.git
mail-filter
courier-pythonfilter
files
courier-pythonfilter-3.0.6-ipv6.diff
courier-pythonfilter with ipv6 patch
Hanno Böck
commited
b5be8cb
at 2025-06-12 14:03:08
courier-pythonfilter-3.0.6-ipv6.diff
Blame
History
Raw
https://github.com/gordonmessmer/courier-pythonfilter/pull/10 diff --git a/filters/pythonfilter/whitelist_dnswl.py b/filters/pythonfilter/whitelist_dnswl.py index aa03376..57b0ff5 100644 --- a/filters/pythonfilter/whitelist_dnswl.py +++ b/filters/pythonfilter/whitelist_dnswl.py @@ -19,6 +19,7 @@ import sys import socket +import ipaddress import courier.control import courier.config @@ -45,22 +46,30 @@ def do_filter(body_path, control_paths): except: return '451 Internal failure locating control files' - if senders_ip and '.' in senders_ip: - # '.' must be in senders_ip until there are DNSWLs that support IPv6 - octets = senders_ip.split('.') - octets.reverse() - octets_r = '.'.join(octets) - for zone in dnswl_zone: - lookup = '%s.%s' % (octets_r, zone) - try: - lookup_result = socket.gethostbyname(lookup) - except: - lookup_result = None - if lookup_result: - # For now, any result is good enough. - return '200 Ok' - - # Return no decision for everyone else. + try: + sender = ipaddress.ip_address(senders_ip) + except ValueError: + sys.stderr.write(f'whitelist_dnswl: unparsable senders_ip: {senders_ip}\n') + return '' + + # sender is either IPV4Address or IPV6Address object, + reverse = sender.reverse_pointer.replace('.in-addr.arpa', '').replace('.ip6.arpa', '') + + for zone in dnswl_zone: + lookup = '%s.%s' % (reverse, zone) + try: + lookup_result = socket.gethostbyname(lookup) + except: + lookup_result = None + if lookup_result: + # special case for access blocked on dnswl.org + if lookup_result == '127.0.0.255': + # access blocked, no nonspam indicator + continue + # For now, any other result is good enough. + return '200 Ok' + + # Return no decision if reaching this return ''