From 30f1f8a21cdfc8983cff968873a3cf4dd56ba0ba Mon Sep 17 00:00:00 2001 From: b3yond Date: Sun, 7 Oct 2018 18:47:37 +0200 Subject: [PATCH] fixing #40 - treating different message MIMEtypes --- active_bots/mailbot.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/active_bots/mailbot.py b/active_bots/mailbot.py index 8125137..ae764c2 100644 --- a/active_bots/mailbot.py +++ b/active_bots/mailbot.py @@ -55,7 +55,24 @@ def make_report(msg, user): author = msg['From'] # get mail author from email header # :todo take only the part in between the < > - text = msg.get_payload() + if msg.is_multipart(): + text = [] + for part in msg.get_payload(): + if part.get_content_type() == "text": + text.append(part.get_payload()) + elif part.get_content_type() == "multipart/mixed": + for p in part: + if p.get_content_type() == "text": + text.append(part.get_payload()) + else: + logger.error("unknown MIMEtype: " + + p.get_content_type()) + else: + logger.error("unknown MIMEtype: " + + part.get_content_type()) + text = '\n'.join(text) + else: + text = msg.get_payload() post = report.Report(author, "mail", text, None, date) user.save_seen_mail(date) return post