Skip to content

Commit

Permalink
Merge pull request #174 from aidecoe/dmarc
Browse files Browse the repository at this point in the history
Simplify DMARC filter and make it consistent with existing filters
  • Loading branch information
GuillaumeSeren committed Dec 3, 2017
2 parents ff01897 + b8439e2 commit 4cbba65
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions afew/filters/DMARCReportInspectionFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import zipfile

from .BaseFilter import Filter
from ..NotmuchSettings import get_notmuch_new_tags


class ReportFilesIterator(object):
Expand Down Expand Up @@ -95,18 +94,15 @@ class DMARCReportInspectionFilter(Filter):
'''
def __init__(self, # pylint: disable=too-many-arguments
database,
archive_passed='on',
dkim_ok_tag='dmarc-dkim-ok',
dkim_fail_tag='dmarc-dkim-fail',
spf_ok_tag='dmarc-spf-ok',
spf_fail_tag='dmarc-spf-fail'):
dkim_ok_tag='dmarc/dkim-ok',
dkim_fail_tag='dmarc/dkim-fail',
spf_ok_tag='dmarc/spf-ok',
spf_fail_tag='dmarc/spf-fail'):
super(DMARCReportInspectionFilter, self).__init__(database)
self.dkim_tag = {True: dkim_ok_tag, False: dkim_fail_tag}
self.spf_tag = {True: spf_ok_tag, False: spf_fail_tag}
self.dmarc_subject = re.compile(r'^report domain:',
flags=re.IGNORECASE)
self.archive_passed = archive_passed.lower() in ['on', '1', 't',
'true', 'yes']

def handle_message(self, message):
if not self.dmarc_subject.match(message.get_header('Subject')):
Expand All @@ -122,6 +118,3 @@ def handle_message(self, message):
'dmarc',
self.dkim_tag[auth_results['dkim']],
self.spf_tag[auth_results['spf']])

if self.archive_passed and all(auth_results.values()):
self.remove_tags(message, *get_notmuch_new_tags())

0 comments on commit 4cbba65

Please sign in to comment.