From e8265e45a534da4e835a367fefe1f8722760b73e Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Tue, 11 Feb 2020 08:53:29 +0100 Subject: [PATCH] Catch exceptions of get_body function --- pyquarantine/notifications.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyquarantine/notifications.py b/pyquarantine/notifications.py index 92ad162..1d4e4d7 100644 --- a/pyquarantine/notifications.py +++ b/pyquarantine/notifications.py @@ -216,7 +216,12 @@ class EMailNotification(BaseNotification): "Extract and decode email body and return it as BeautifulSoup object." # try to find the body part self.logger.debug("{}: trying to find email body".format(queueid)) - body = msg.get_body(preferencelist=("html", "plain")) + try: + body = msg.get_body(preferencelist=("html", "plain")) + except Exception as e: + self.logger.error("{}: an error occured in email.message.EmailMessage.get_body: {}".format( + queueid, e)) + body = None if body: charset = body.get_content_charset() or "utf-8"