Description

This behaviour is similar to some other mail clients (namely Gmail and Microsoft Outlook), but is non-standard according to ​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.

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.

Because this changes some of the behaviour of Django when attaching messages which has a chance to break existing applications, I'm unsure whether this bugfix should be backported to earlier supported versions of Django.

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 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 8 months. I've since created a new pull request that fixes this:

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 a bit upset that this was missed in the lead-up to 1.5.

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.