Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#12791 closed (fixed)

Setting encoding on EmailMessage does not produce intended result

Reported by: oyvind Owned by: oyvind
Component: Core (Mail) Version: dev
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: no UI/UX: no

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 14 years ago.
Patch with tests
emailmessage-body-encoding.2.diff (3.7 KB ) - added by oyvind 14 years ago.
Also works with MIME attachments
emailmessage-body-header-encoding.diff (7.5 KB ) - added by oyvind 14 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 by oyvind, 14 years ago

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

comment:2 by oyvind, 14 years ago

milestone: 1.31.2

comment:3 by Russell Keith-Magee, 14 years ago

Resolution: duplicate
Status: newclosed

I suspect this is a duplicate of #11924.

comment:4 by oyvind, 14 years ago

Has patch: set

by oyvind, 14 years ago

Patch with tests

by oyvind, 14 years ago

Also works with MIME attachments

by oyvind, 14 years ago

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

comment:5 by Russell Keith-Magee, 14 years ago

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 by Jacob, 14 years ago

Triage Stage: AcceptedReady for checkin

comment:7 by Karen Tracey, 14 years ago

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 by Karen Tracey, 14 years ago

(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 by Jacob, 12 years ago

milestone: 1.2

Milestone 1.2 deleted

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