Opened 6 years ago

Closed 6 years ago

#29830 closed Bug (fixed)

EmailMessage may ignore quote printable encoding

Reported by: Jannik Schürg Owned by: nobody
Component: Core (Mail) Version: dev
Severity: Normal Keywords: email, mail, encoding
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jannik Schürg)

I want to change the body encoding (base64, quoted-printible) of an email. Example code:

from email import charset
from django.core.mail import EmailMessage

msg = EmailMessage("Subject", "Hello World")
encoding = charset.Charset("utf-8")
encoding.body_encoding = charset.QP
msg.encoding = encoding
print(msg)  # Is not encoded with quoted-printables

The quoted-printible encoding in this case is overwritten in SafeMIMEText. The encoding property of EmailMessage seems not to be documented? I attached a patch which changes the bahvior of SafeMIMEText for the case a email.charset.Charset object was given.

Another idea is to add a new property to EmailMessage.__init__ which allows to set the body encoding.

Versions 1.11 through master are affected.

Attachments (1)

patch.diff (2.7 KB ) - added by Jannik Schürg 6 years ago.

Download all attachments as: .zip

Change History (7)

by Jannik Schürg, 6 years ago

Attachment: patch.diff added

comment:1 by Jannik Schürg, 6 years ago

Description: modified (diff)

comment:2 by Tim Graham, 6 years ago

Component: UncategorizedCore (Mail)
Has patch: unset
Summary: EmailMessage does not respect body encodingEmailMessage may ignore quote printable encoding
Type: New featureBug

Looks like the bug is in SafeMIMEText.set_payload(). The quoted-printable encodeding is dropped if the message doesn't have any "long lines."

comment:3 by Tim Graham, 6 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Jannik Schürg, 6 years ago

I have openend a pull request: https://github.com/django/django/pull/10526

comment:5 by Tim Graham, 6 years ago

Has patch: set

comment:6 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: newclosed

In efc0f77f:

Fixed #29830 -- Fixed loss of custom utf-8 body encoding in mails.

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