From fe0bdb8f23453d83355eba2dde5e3ff20a716940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Thu, 10 May 2018 09:53:18 +0200 Subject: [PATCH] fix: Do not fail if the email has no body. --- mail_to_misp.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mail_to_misp.py b/mail_to_misp.py index 5373461..087b8f3 100755 --- a/mail_to_misp.py +++ b/mail_to_misp.py @@ -95,7 +95,11 @@ class Mail2MISP(): def email_from_spamtrap(self): '''The email comes from a spamtrap and should be attached as-is.''' - self.clean_email_body = html.unescape(self.original_mail.get_body(preferencelist=('html', 'plain')).get_payload(decode=True).decode()) + raw_body = self.original_mail.get_body(preferencelist=('html', 'plain')) + if raw_body: + self.clean_email_body = html.unescape(raw_body.get_payload(decode=True).decode()) + else: + self.clean_email_body = '' return self.forwarded_email(self.pseudofile) def forwarded_email(self, pseudofile: BytesIO):