{{{
#!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.
* Attachment "patch.diff" added.
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>
* 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>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/29830#comment:3>
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>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29830#comment:5>
* 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>