[Django] #29830: EmailMessage does not respect body encoding

7 views
Skip to first unread message

Django

unread,
Oct 6, 2018, 5:02:21 PM10/6/18
to django-...@googlegroups.com
#29830: EmailMessage does not respect body encoding
-------------------------------------+-------------------------------------
Reporter: jannschu | Owner: nobody
Type: New | Status: new
feature |
Component: | Version: master
Uncategorized | Keywords: email, mail,
Severity: Normal | encoding
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I want to change the body encoding (base64, quoted-printible) of an email.
Example code:

{{{
#!python
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29830>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Oct 6, 2018, 5:02:33 PM10/6/18
to django-...@googlegroups.com
#29830: EmailMessage does not respect body encoding
-------------------------------------+-------------------------------------
Reporter: jannschu | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Resolution:
Keywords: email, mail, | Triage Stage:
encoding | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jannschu):

* Attachment "patch.diff" added.

Django

unread,
Oct 6, 2018, 5:03:35 PM10/6/18
to django-...@googlegroups.com
#29830: EmailMessage does not respect body encoding
-------------------------------------+-------------------------------------
Reporter: jannschu | Owner: nobody
Type: New feature | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Resolution:
Keywords: email, mail, | Triage Stage:
encoding | Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by jannschu:

Old description:

> I want to change the body encoding (base64, quoted-printible) of an
> email. Example code:
>
> {{{
> #!python
> 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.

New description:

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

{{{
#!python
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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/29830#comment:1>

Django

unread,
Oct 10, 2018, 11:53:38 AM10/10/18
to django-...@googlegroups.com
#29830: EmailMessage may ignore quote printable encoding

-------------------------------------+-------------------------------------
Reporter: jannschu | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master

Severity: Normal | Resolution:
Keywords: email, mail, | Triage Stage:
encoding | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: New feature => Bug
* has_patch: 1 => 0
* component: Uncategorized => Core (Mail)


Comment:

Looks like the bug is in
[https://github.com/django/django/blob/f3d3338e06d571a529bb2046428eeac8e56bcbf6/django/core/mail/message.py#L173-L180
SafeMIMEText.set_payload()]. The quoted-printable encodeding is dropped if
the message doesn't have any "long lines."

--
Ticket URL: <https://code.djangoproject.com/ticket/29830#comment:2>

Django

unread,
Oct 10, 2018, 11:53:45 AM10/10/18
to django-...@googlegroups.com
#29830: EmailMessage may ignore quote printable encoding

-------------------------------------+-------------------------------------
Reporter: jannschu | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: email, mail, | Triage Stage: Accepted
encoding |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/29830#comment:3>

Django

unread,
Oct 17, 2018, 9:56:35 PM10/17/18
to django-...@googlegroups.com
#29830: EmailMessage may ignore quote printable encoding
-------------------------------------+-------------------------------------
Reporter: Jannik Schürg | Owner: nobody

Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: email, mail, | Triage Stage: Accepted
encoding |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Jannik Schürg):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/29830#comment:4>

Django

unread,
Oct 18, 2018, 8:18:25 PM10/18/18
to django-...@googlegroups.com
#29830: EmailMessage may ignore quote printable encoding
-------------------------------------+-------------------------------------
Reporter: Jannik Schürg | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: email, mail, | Triage Stage: Accepted
encoding |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29830#comment:5>

Django

unread,
Oct 22, 2018, 4:36:45 PM10/22/18
to django-...@googlegroups.com
#29830: EmailMessage may ignore quote printable encoding
-------------------------------------+-------------------------------------
Reporter: Jannik Schürg | Owner: nobody
Type: Bug | Status: closed

Component: Core (Mail) | Version: master
Severity: Normal | Resolution: fixed

Keywords: email, mail, | Triage Stage: Accepted
encoding |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"efc0f77f02de86a94e21cafd3c8409eb7dd99ef6" efc0f77f]:
{{{
#!CommitTicketReference repository=""
revision="efc0f77f02de86a94e21cafd3c8409eb7dd99ef6"
Fixed #29830 -- Fixed loss of custom utf-8 body encoding in mails.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29830#comment:6>

Reply all
Reply to author
Forward
0 new messages