diff options
| author | Michael Schwarz <michi@cloudscale.ch> | 2016-08-03 15:53:06 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-12 16:35:09 -0400 |
| commit | 72d541b61cd7b0a14f70242e2207fdb3f600c4d5 (patch) | |
| tree | aa90cd09c360ed41657ffca31507c8fef579c2ab /docs | |
| parent | 311a8e8d505049ff5644a94e16c00246c8a43a18 (diff) | |
Fixed #27007 -- Handled non-UTF-8 bytes objects for text/* attachments.
The fallback logic which allows non-UTF-8 encoded files to be passed to
attach_file() even when a `text/*` mime type has been specified is
moved to attach(). Both functions now fall back to a content type of
`application/octet-stream`.
A side effect is that a file's content is decoded in memory instead of
opening it in text mode and reading it into a string.
Some mimetype-related logic in _create_attachment() has become
obsolete as the code moved from attach_file() to attach() already
handles this.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/1.11.txt | 4 | ||||
| -rw-r--r-- | docs/topics/email.txt | 13 |
2 files changed, 17 insertions, 0 deletions
diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt index a23d5f3663..46c780eda8 100644 --- a/docs/releases/1.11.txt +++ b/docs/releases/1.11.txt @@ -162,6 +162,10 @@ Email * Added the :setting:`EMAIL_USE_LOCALTIME` setting to allow sending SMTP date headers in the local time zone rather than in UTC. +* ``EmailMessage.attach()`` and ``attach_file()`` now fall back to MIME type + ``application/octet-stream`` when binary content that can't be decoded as + UTF-8 is specified for a ``text/*`` attachment. + File Storage ~~~~~~~~~~~~ diff --git a/docs/topics/email.txt b/docs/topics/email.txt index 2b880e0ba9..7c8f5e6112 100644 --- a/docs/topics/email.txt +++ b/docs/topics/email.txt @@ -345,6 +345,11 @@ The class has the following methods: If you specify a ``mimetype`` of ``message/rfc822``, it will also accept :class:`django.core.mail.EmailMessage` and :py:class:`email.message.Message`. + For a ``mimetype`` starting with ``text/``, content is expected to be a + string. Binary data will be decoded using UTF-8, and if that fails, the + MIME type will be changed to ``application/octet-stream`` and the data will + be attached unchanged. + In addition, ``message/rfc822`` attachments will no longer be base64-encoded in violation of :rfc:`2046#section-5.2.1`, which can cause issues with displaying the attachments in `Evolution`__ and `Thunderbird`__. @@ -359,6 +364,14 @@ The class has the following methods: message.attach_file('/images/weather_map.png') + For MIME types starting with ``text/``, binary data is handled as in + ``attach()``. + +.. versionchanged:: 1.11 + + Added the fallback to MIME type ``application/octet-stream`` when binary + data for a ``text/*`` attachment cannot be decoded. + Sending alternative content types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
