Code

Opened 4 years ago

Closed 4 years ago

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

  • Keywords iso-8859-1 added; iso-8849-1 removed
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by oyvind

  • milestone changed from 1.3 to 1.2

comment:3 Changed 4 years ago by russellm

  • Resolution set to duplicate
  • Status changed from new to closed

I suspect this is a duplicate of #11924.

comment:4 Changed 4 years ago by oyvind

  • Has patch set

Changed 4 years ago by oyvind

Patch with tests

Changed 4 years ago by oyvind

Also works with MIME attachments

Changed 4 years ago by oyvind

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

comment:5 Changed 4 years ago by russellm

  • Resolution duplicate deleted
  • Status changed from closed to reopened
  • Triage Stage changed from Unreviewed to Accepted

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 4 years ago by jacob

  • Triage Stage changed from Accepted to Ready for checkin

comment:7 Changed 4 years ago by kmtracey

  • Resolution set to fixed
  • Status changed from reopened to closed

(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 4 years ago by kmtracey

(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 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.