From aaab73cdf1a7690f5703c3a96e692a1e1cf92709 Mon Sep 17 00:00:00 2001 From: Sascha Rommelfangen Date: Fri, 13 Apr 2018 10:27:14 +0200 Subject: [PATCH] fixed subject decoding --- mail_to_misp.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mail_to_misp.py b/mail_to_misp.py index fefaf08..a5d2dfb 100755 --- a/mail_to_misp.py +++ b/mail_to_misp.py @@ -94,7 +94,13 @@ msg = email.message_from_string(mailcontent) if not mail_subject: try: mail_subject = msg.get('Subject').encode("utf-8", "ignore") - except: + sub, enc = email.header.decode_header(msg.get('subject'))[0] + if enc==None: + email_subject = sub + else: + email_subject = sub.decode(enc) + except Exception as e: + print(e) pass for part in msg.walk(): if part.get_content_charset() is None: