# HG changeset patch # User Pascal Volk # Date 1271012444 0 # Node ID 3a392067015ca5d8cc3bbf065fb44d1718a6da53 # Parent 7f131cf431bcbb4e1740759ccbb60f4877ae4d92 Count also naked IPv4 addresses. Beautified NiXSapmSum:RE_PF. diff -r 7f131cf431bc -r 3a392067015c nixspamsum --- a/nixspamsum Fri Feb 19 11:40:39 2010 +0000 +++ b/nixspamsum Sun Apr 11 19:00:44 2010 +0000 @@ -18,8 +18,14 @@ """ __slots__ = ('_doms', '_mxs', '_repo') + RE_FQDN = '(?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}' + RE_IPv4 = '(?:[\d]{1,3}\.){3}[\d]{1,3}' """Regular expression pattern for mail logs from Postfix""" - RE_PF = '''^[\w\s:-]{17,80}\spostfix\/smtpd\[[\d]{3,5}\]: NOQUEUE: reject:.*blocked using ix.dnsbl.manitu.net; Spam sent to the mailhost ((?:[a-z0-9-]{1,63}\.){1,}[a-z]{2,6}) was detected by NiX Spam.*$''' + RE_PF = r'''^[\w\s:-]{17,80}\spostfix\/smtpd\[[\d]{1,5}\]:\sNOQUEUE: + \sreject:.*blocked\susing\six.dnsbl.manitu.net; + \sSpam\ssent\sto\sthe\smailhost\s(%s|%s) + \swas\sdetected\sby\sNiX\sSpam.*$''' % (RE_FQDN, RE_IPv4) + def __init__(self): self._doms = {} @@ -28,7 +34,7 @@ def setLogFormat(self, format='postfix'): if format == 'postfix': - self._repo = re.compile(NiXSapmSum.RE_PF) + self._repo = re.compile(NiXSapmSum.RE_PF, re.VERBOSE) else: raise Exception('MTA/Logformat not supported yet.') @@ -43,8 +49,13 @@ self._mxs[mx] = 1 def countByDom(self): + ipv4po = re.compile(NiXSapmSum.RE_IPv4) for mx in self._mxs.keys(): - dom = '.'.join(mx.split('.')[-2:]) + mo = ipv4po.match(mx) + if mo: + dom = mo.group(0) + else: + dom = '.'.join(mx.split('.')[-2:]) try: self._doms[dom] += self._mxs[mx] except KeyError: