Opened 7 years ago

Closed 7 years ago

Last modified 5 years ago

#12791 closed (fixed)

Setting encoding on EmailMessage does not produce intended result

Reported by: oyvind Owned by: oyvind
Component: Core (Mail) Version: master
Severity: Keywords: iso-8859-1 utf-8 smart_str mail header
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

class MEmailMessage(EmailMessage):

    encoding = 'ISO-8859-1'

Produces a message with a header that says it is iso-8859-1, but the quoted-printable-encoded data in the body is utf-8.

class EmailMessage(object):

    ...

    def message(self):
        encoding = self.encoding or settings.DEFAULT_CHARSET
        msg = SafeMIMEText(smart_str(self.body, settings.DEFAULT_CHARSET),
                           self.content_subtype, encoding)

    ...

Should be:

class EmailMessage(object):

    ...

    def message(self):
        encoding = self.encoding or settings.DEFAULT_CHARSET
        msg = SafeMIMEText(smart_str(self.body, encoding),
                           self.content_subtype, encoding)

    ...

Attachments (3)

emailmessage-body-encoding.diff (2.2 KB) - added by oyvind 7 years ago.
Patch with tests
emailmessage-body-encoding.2.diff (3.7 KB) - added by oyvind 7 years ago.
Also works with MIME attachments
emailmessage-body-header-encoding.diff (7.5 KB) - added by oyvind 7 years ago.
A combination of the patches in #12791 and #6918 supporting different encodings both in body and headers.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 7 years ago by oyvind

Keywords: iso-8859-1 added; iso-8849-1 removed

comment:2 Changed 7 years ago by oyvind

milestone: 1.31.2

comment:3 Changed 7 years ago by Russell Keith-Magee

Resolution: duplicate
Status: newclosed

I suspect this is a duplicate of #11924.

comment:4 Changed 7 years ago by oyvind

Has patch: set

Changed 7 years ago by oyvind

Patch with tests

Changed 7 years ago by oyvind

Also works with MIME attachments

Changed 7 years ago by oyvind

A combination of the patches in #12791 and #6918 supporting different encodings both in body and headers.

comment:5 Changed 7 years ago by Russell Keith-Magee

Resolution: duplicate
Status: closedreopened
Triage Stage: UnreviewedAccepted

Apologies - you are correct. This is a different issue to #11924.

Given that the two issues are distinct, please keep the patches separate.

comment:6 Changed 7 years ago by Jacob

Triage Stage: AcceptedReady for checkin

comment:7 Changed 7 years ago by Karen Tracey

Resolution: fixed
Status: reopenedclosed

(In [12683]) Fixed #6918, #12791: If an email message has an encoding, actually use that encoding to encode body and headers. Thanks for patch with tests oyvind.

comment:8 Changed 7 years ago by Karen Tracey

(In [12689]) [1.1.X] Fixed #6918, #12791: If an email message has an encoding, actually use that encoding to encode body and headers. Thanks for patch with tests oyvind.

Backport of r12683 and r12688 from trunk.

comment:9 Changed 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top