From 310ecb0d60123094bdc1da6d7915e71749a1e480 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Quenot Date: Wed, 28 May 2014 15:45:29 +0200 Subject: [PATCH] Fix detection of MIME type in message_parse() Be careful, content-type may contain tricky content like in the following example so test the MIME type with startswith() Content-Type: multipart/related; boundary="_004_3f1e4da175f349248b8d43cdeb9866f1AMSPR06MB343eurprd06pro_"; type="text/html" --- addons/mail/mail_thread.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/addons/mail/mail_thread.py b/addons/mail/mail_thread.py index 90ae3cf..942dadd 100644 --- a/addons/mail/mail_thread.py +++ b/addons/mail/mail_thread.py @@ -780,7 +780,14 @@ class mail_thread(osv.AbstractModel): body = u'' if save_original: attachments.append(('original_email.eml', message.as_string())) - if not message.is_multipart() or 'text/' in message.get('content-type', ''): + + # Be careful, content-type may contain tricky content like in the + # following example so test the MIME type with startswith() + # + # Content-Type: multipart/related; + # boundary="_004_3f1e4da175f349248b8d43cdeb9866f1AMSPR06MB343eurprd06pro_"; + # type="text/html" + if not message.is_multipart() or message.get('content-type', '').startswith("text/"): encoding = message.get_content_charset() body = message.get_payload(decode=True) body = tools.ustr(body, encoding, errors='replace') -- 1.7.10.4