[Django] #18967: django.core.mail._create_mime_attachment incorrectly encodes message/rfc822 attachments in base64, breaks in Evolution and Thunderbird

48 views
Skip to first unread message

Django

unread,
Sep 16, 2012, 9:36:32 PM9/16/12
to django-...@googlegroups.com
#18967: django.core.mail._create_mime_attachment incorrectly encodes message/rfc822
attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+--------------------
Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
Django appears to insert message/rfc822 attachments in base64 encoding.
This breaks display in Novell Evolution
[https://bugzilla.gnome.org/show_bug.cgi?id=651197 #651197] and Mozilla
Thunderbird [https://bugzilla.mozilla.org/show_bug.cgi?id=333880 #333880].

This behaviour is similar to some other mail clients (namely Gmail and
Microsoft Outlook), but is non-standard according to
[http://www.ietf.org/rfc/rfc2046.txt RFC2046]:

5.2.1. RFC822 Subtype
No encoding other than "7bit", "8bit", or "binary" is permitted for the
body of a "message/rfc822" entity.

The Mozilla Thunderbird bug entry seems to indicate that with certain
versions of Thunderbird, this behaviour is accepted, but this seems to
change sporadically. They believe that encoding message/rfc822
attachments in this fashion is not acceptable behaviour.

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

Django

unread,
Sep 16, 2012, 10:45:51 PM9/16/12
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+--------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by micolous):

* needs_better_patch: => 0
* needs_tests: => 1
* easy: 0 => 1
* needs_docs: => 1
* has_patch: 0 => 1


Comment:

I've created a patch and pull request:
https://github.com/django/django/pull/373

This patch is against Django master.

There are some changes in the behaviour of
django.core.mail.EmailMessage.attach:

* message/rfc822 attachments may be a email.message.Message object (not
just a string)
* When passing in a string attachment, Django will now automatically
convert it to email.message.Message internally for
email.mime.message.MIMEMessage. This means that if the message/rfc822
attachment is not well-formed, an exception may be thrown.
* Per RFC2046, the attached message headers must be ASCII encoded. As a
result SafeMIMEMessage checks headers with ASCII encoding.

This also implements SafeMIMEMessage (like the other SafeMIME* classes).

The tests currently pass, however there are no specific tests in this
patch for this functionality.

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

Django

unread,
Sep 17, 2012, 11:37:16 PM9/17/12
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+--------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------
Changes (by micolous):

* needs_tests: 1 => 0


Comment:

I've added regression tests for the bug, and fixed an issue where it was
applying the transforms to all message/* mimetypes, and not just
message/rfc822. I've also allowed the EmailMessage.attach method to take
in Django's EmailMessage object as an argument for message/rfc822 objects.

I've updated my pull request (above) with these changes.

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

Django

unread,
Oct 25, 2012, 1:50:33 PM10/25/12
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by claudep):

* stage: Unreviewed => Accepted


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

Django

unread,
May 23, 2013, 5:24:47 AM5/23/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by micolous):

I notice the patch for this bug was marked as "Accepted" 7 months ago,
however the patch for the issue has not been merged. I'm confused to what
is going on.

This is still an outstanding bug, as Django continues to produce non-
RFC2046 s5.2.1-compliant mail, which breaks in multiple popular email
clients when attempting to send message/rfc822 attachments from Django.

I've now rebased this patch against the stable 1.5 tree as at today,
however this has now got GitHub very confused, as it's pulled in hundreds
of commits in the last 9 months. I've since created a new pull request
that fixes this:

https://github.com/django/django/pull/1202

If there is something needed from me to make this proceed please let me
know. Thanks.

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

Django

unread,
May 23, 2013, 10:56:29 AM5/23/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by aaugustin):

* needs_better_patch: 0 => 1


Comment:

This ticket was marked as "Accepted" because the issue was recognized as
valid.

Once someone has written a patch (with tests and docs if appropriate),
someone else can review it, and mark the ticket as "Ready for Checkin" if
the patch is good.

Then the patch can be merged.

A pull request is an appropriate way to provide a patch, however, it must
be done against the master branch, not a stable branch.

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

Django

unread,
May 26, 2013, 9:52:00 PM5/26/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by micolous):

I will write some documentation and rebase this against master.

How can I target the stable versions of Django for getting this patch in
future bugfix releases? This bug affects Django 1.3, 1.4 and 1.5...
though probably also other releases as well.

I'm going to have to backport this patch to 1.5.x anyway, because it
causes my application to fail in many of it's email-related tasks, as it
is sending emails attached to emails quite frequently.

Trying to get this fixed in other email clients is an uphill battle, as
it's non-RFC and has been an open bug in Thunderbird for 7 years.

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

Django

unread,
May 27, 2013, 12:48:42 AM5/27/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.5

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------
Changes (by micolous):

* needs_better_patch: 1 => 0
* version: 1.4 => 1.5
* needs_docs: 1 => 0


Comment:

I've written documentation for the change. I've got another pull request
against django master:

https://github.com/django/django/pull/1222

As this fixes a bug in Django, it would be great if this was also pulled
into Django 1.5.2. Pull request 1202 has been updated against current
stable/1.5.x.

This already has unit tests which identify the buggy behaviour.

--
Ticket URL: <https://code.djangoproject.com/ticket/18967#comment:7>

Django

unread,
May 27, 2013, 4:58:57 PM5/27/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: 1.5
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+------------------------------------

Comment (by lukeplant):

I'm afraid that are policy with bug fixes is that this can only go into
master - it won't be backported. To ensure it gets into 1.6 it would help
if you can find someone to review your patch.

--
Ticket URL: <https://code.djangoproject.com/ticket/18967#comment:8>

Django

unread,
May 27, 2013, 11:23:02 PM5/27/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+---------------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by cuerty):

* cc: cuerty (added)
* version: 1.5 => master
* stage: Accepted => Ready for checkin


Comment:

IMHO: This patch seems good.

I was able to reproduce the bug with the test provided and the patch fix
it. Also the last version of the patch merges without problems with
master.

--
Ticket URL: <https://code.djangoproject.com/ticket/18967#comment:9>

Django

unread,
Aug 16, 2013, 6:30:16 PM8/16/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+---------------------------------------------

Reporter: micolous | Owner: nobody
Type: Bug | Status: new
Component: Core (Mail) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+---------------------------------------------

Comment (by anonymous):

nbnbmn

--
Ticket URL: <https://code.djangoproject.com/ticket/18967#comment:10>

Django

unread,
Aug 20, 2013, 9:20:56 PM8/20/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+---------------------------------------------
Reporter: micolous | Owner: nobody
Type: Bug | Status: closed

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

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+---------------------------------------------
Changes (by Ramiro Morales <cramm0@…>):

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


Comment:

In [changeset:"f9d1d5dc1377cb21b39452b0897e7a79a3d02844"]:
{{{
#!CommitTicketReference repository=""
revision="f9d1d5dc1377cb21b39452b0897e7a79a3d02844"
Fixed #18967 -- Don't base64-encode message/rfc822 attachments.

Thanks Michael Farrell for the report and his work on the fix.
}}}

Django

unread,
Aug 23, 2013, 7:41:43 AM8/23/13
to django-...@googlegroups.com
#18967: django.core.mail.EmailMessage._create_mime_attachment incorrectly encodes

message/rfc822 attachments in base64, breaks in Evolution and Thunderbird
-----------------------------+---------------------------------------------
Reporter: micolous | Owner: nobody

Type: Bug | Status: closed
Component: Core (Mail) | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+---------------------------------------------

Comment (by Andrew Godwin <andrew@…>):

In [changeset:"01223840f34ff2eacf1425bc133c347564fe2614"]:
{{{
#!CommitTicketReference repository=""
revision="01223840f34ff2eacf1425bc133c347564fe2614"


Fixed #18967 -- Don't base64-encode message/rfc822 attachments.

Thanks Michael Farrell for the report and his work on the fix.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/18967#comment:11>

Reply all
Reply to author
Forward
0 new messages