From 384de32d8563e0a29437f218144e676ee6aea9f2 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Thu, 25 Jul 2013 00:14:24 -0700 Subject: [PATCH] Encode email message body into UTF-8 always when on Python 2; although I originally thought that this was a Python 2.6 thing, it looks like it might be some combination of platform/version, but bytes should always be fine. --- django_mailbox/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/django_mailbox/models.py b/django_mailbox/models.py index df2d57a..9ad3ddd 100755 --- a/django_mailbox/models.py +++ b/django_mailbox/models.py @@ -467,9 +467,9 @@ class Message(models.Model): def get_email_object(self): """ Returns an `email.message.Message` instance for this message. - Note: Python 2.6's version of email.message_from_string requires - bytes and will incorrectly create an e-mail object if a unicode - object is passed-in. + Note: Python 2's version of email.message.fromstring on some platforms + requires bytes and will incorrectly create an e-mail object if a + unicode object is passed-in. Note that in reality 7-bit ascii *should* be an acceptable encoding here per RFC-2822 (2.1), but given that `message_from_string` really @@ -480,7 +480,7 @@ class Message(models.Model): """ body = self.body - if sys.version_info < (2, 7): + if sys.version_info < (3, 0): body = body.encode('utf-8') return self._rehydrate( email.message_from_string(body) @@ -514,7 +514,7 @@ class MessageAttachment(models.Model): headers = self.headers if headers is None: return EmailMessage() - if sys.version_info < (2, 7): + if sys.version_info < (3, 0): headers = headers.encode('utf-8') return email.message_from_string(headers)