From 8ada1c09b35615d9de41bb1304164f6b4bb7f747 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Tue, 12 Nov 2019 23:44:24 +0100 Subject: [PATCH] remail/mail: Sanitize incoming headers Remove CR/LF leftovers which might be in incoming headers before setting them. Happens when handling the weird GPG Outlook attachments. Signed-off-by: Thomas Gleixner --- remail/mail.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/remail/mail.py b/remail/mail.py index bb86800..6499156 100644 --- a/remail/mail.py +++ b/remail/mail.py @@ -197,11 +197,16 @@ def msg_force_msg_id(msg, name): id = make_msgid(name.split('@')[0]) msg_set_header(msg, 'Message-ID', id) +re_rmlfcr = re.compile('[\r\n]') def msg_set_header(msg, hdr, txt): ''' Set new or replace a message header ''' + # Sanitize the header first. Broken Outlook GPG payloads + # come with wreckaged headers. + txt = re_rmlfcr.sub(' ', txt) + for k in msg.keys(): if hdr.lower() == k.lower(): msg.replace_header(k, txt)