From: Jeremy Schlatter Date: Tue, 2 Dec 2014 23:37:44 +0000 (-0800) Subject: Don't throw an exception for .eml attachments with broken MIME. X-Git-Tag: v0.3.24^2~2 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=c00899dd19386b2c394c701996b18c20bba8d51c;p=flanker.git Don't throw an exception for .eml attachments with broken MIME. This function used to fail when creating an attachment that happened to contain text with broken MIME. Now when that happens, we just encode it and call the attachment type 'text/plain'. --- diff --git a/flanker/mime/create.py b/flanker/mime/create.py index b30a1b5..816826d 100644 --- a/flanker/mime/create.py +++ b/flanker/mime/create.py @@ -1,6 +1,7 @@ """ This package is a set of utilities and methods for building mime messages """ import uuid +from flanker.mime import DecodingError from flanker.mime.message import ContentType, utils from flanker.mime.message.part import MimePart, Body, Part, adjust_content_type from flanker.mime.message import scanner @@ -63,16 +64,18 @@ def attachment(content_type, body, filename=None, ContentType(main, sub), body, filename) if content_type.main == 'message': - message = message_container(from_string(body)) - message.headers['Content-Disposition'] = WithParams(disposition) - return message - else: - return binary( - content_type.main, - content_type.sub, - body, filename, - disposition, - charset) + try: + message = message_container(from_string(body)) + message.headers['Content-Disposition'] = WithParams(disposition) + return message + except DecodingError: + content_type = ContentType('text', 'plain') + return binary( + content_type.main, + content_type.sub, + body, filename, + disposition, + charset) def from_string(string):