From 50f0b7983ea998fb063dda5cdc76d2932d12e6d0 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Wed, 18 Dec 2019 16:41:55 +0100 Subject: [PATCH] Fix bug that occurs with linebreaks within from header value --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index b57c211..70e3a9b 100644 --- a/main.py +++ b/main.py @@ -22,8 +22,12 @@ split_from_regex = re.compile('(?P.*)<(?P.*)>$') address_domain_regex = re.compile('.*@(?P[\.\w-]+)') +def normalizeRawFromHeader(value): + return value.replace('\n', '').replace('\r', '').strip() + + def parseFromHeader(value): - """Split 'From:' header into label and address values.""" + """Split 'From:'-header into label and address values.""" match = split_from_regex.match(value) result = { 'label': match.group('from_label').strip(), @@ -59,7 +63,7 @@ class SuspiciousFrom(Milter.Base): """Header hook gets called for every header within the email processed.""" if field.lower() == 'from': logger.debug(f"({self.id}) Got \"From:\" header raw value: '{value}'") - value = value.strip('\n').strip() + value = normalizeRawFromHeader(value) if value == '': logger.info(f"Got empty from header value! WTF! Skipping.") return Milter.CONTINUE