git.schokokeks.org
Repositories
Help
Report an Issue
keks-overlay.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
aff96d0
Branches
Tags
master
keks-overlay.git
mail-filter
courier-pythonfilter
files
courier-pythonfilter-ipv6-networkblocks.patch
courier pythonfilter patches
Hanno Böck
commited
aff96d0
at 2017-03-19 10:21:11
courier-pythonfilter-ipv6-networkblocks.patch
Blame
History
Raw
From 85c456fce923cb967fb3852d81763eb74093cc26 Mon Sep 17 00:00:00 2001 From: Bernd Wurst <bernd@milch.schokokeks.org> Date: Tue, 14 Mar 2017 14:44:28 +0100 Subject: [PATCH] Add IPv6 network calculation --- filters/greylist.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/filters/greylist.py b/filters/greylist.py index ad044ea..ffc1eb7 100644 --- a/filters/greylist.py +++ b/filters/greylist.py @@ -87,8 +87,16 @@ def doFilter(bodyFile, controlFileList): # Calculate the /24 network IPv4Match = _IPv4Regex.match(sendersIP) if(IPv4Match is None): - # IPv6 network calculation isn't handled yet - sendersIPNetwork = sendersIP + # possibly IPv6 + try: + pos = sendersIP.rindex(':') + sendersIPNetwork = sendersIP[:pos+1] + # If there are not more than 4 colons left in the address after stripping, something is wrong + if sendersIPNetwork.count(':') < 5: + raise ValueError('Too generic address or no valid ipv6 address: %s\n' % sendersIPNetwork) + except ValueError as e: + sendersIPNetwork = sendersIP + sys.stderr.write(str(e)) else: sendersIPNetwork = IPv4Match.group(1)