mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
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.
This commit is contained in:
parent
32968aa678
commit
384de32d85
1 changed files with 5 additions and 5 deletions
|
|
@ -467,9 +467,9 @@ class Message(models.Model):
|
||||||
def get_email_object(self):
|
def get_email_object(self):
|
||||||
""" Returns an `email.message.Message` instance for this message.
|
""" Returns an `email.message.Message` instance for this message.
|
||||||
|
|
||||||
Note: Python 2.6's version of email.message_from_string requires
|
Note: Python 2's version of email.message.fromstring on some platforms
|
||||||
bytes and will incorrectly create an e-mail object if a unicode
|
requires bytes and will incorrectly create an e-mail object if a
|
||||||
object is passed-in.
|
unicode object is passed-in.
|
||||||
|
|
||||||
Note that in reality 7-bit ascii *should* be an acceptable encoding
|
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
|
here per RFC-2822 (2.1), but given that `message_from_string` really
|
||||||
|
|
@ -480,7 +480,7 @@ class Message(models.Model):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
body = self.body
|
body = self.body
|
||||||
if sys.version_info < (2, 7):
|
if sys.version_info < (3, 0):
|
||||||
body = body.encode('utf-8')
|
body = body.encode('utf-8')
|
||||||
return self._rehydrate(
|
return self._rehydrate(
|
||||||
email.message_from_string(body)
|
email.message_from_string(body)
|
||||||
|
|
@ -514,7 +514,7 @@ class MessageAttachment(models.Model):
|
||||||
headers = self.headers
|
headers = self.headers
|
||||||
if headers is None:
|
if headers is None:
|
||||||
return EmailMessage()
|
return EmailMessage()
|
||||||
if sys.version_info < (2, 7):
|
if sys.version_info < (3, 0):
|
||||||
headers = headers.encode('utf-8')
|
headers = headers.encode('utf-8')
|
||||||
return email.message_from_string(headers)
|
return email.message_from_string(headers)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue