Skip to content

Commit

Permalink
Merge pull request odoo#286 from jbq/bugfix
Browse files Browse the repository at this point in the history
[FIX] mail: detection of MIME type

When parsing the mail headers, the content-type may has a 'type' attribute for Multipart/Related  objects (rfc2387).
Previous check would match on attached files of type text instead of real `content-type: text/`.
  • Loading branch information
mart-e committed Jun 2, 2014
2 parents e61fb4d + 310ecb0 commit 530d8bf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion addons/mail/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,14 @@ def _message_extract_payload(self, message, save_original=False):
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')
Expand Down

0 comments on commit 530d8bf

Please sign in to comment.