[Django] #26344: EmailMultiAlternatives ignores alternatives when it has attachments and body is empty

13 views
Skip to first unread message

Django

unread,
Mar 10, 2016, 10:03:34 AM3/10/16
to django-...@googlegroups.com
#26344: EmailMultiAlternatives ignores alternatives when it has attachments and
body is empty
-------------------------------+--------------------
Reporter: alvinlindstam | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Mail) | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
It seems like django.core.mail.EmailMultiAlternatives does not include the
body or the alternative if the body is falsey and if it has attachments.

{{{
>>> from django.core.mail import EmailMultiAlternatives
>>> m = EmailMultiAlternatives(body="")
>>> m.attach_alternative("<img
src='https://example.com/example_image.png'>", "text/html")
>>> "example_image.png" in m.message().as_string()
True
>>> m.attach('example.txt', "example attachment", 'text/plain')
>>> "example_image.png" in m.message().as_string()
False
>>> print(m.message().as_string())
Content-Type: multipart/mixed;
boundary="===============2599669765216026223=="
MIME-Version: 1.0
Subject:
From: webmaster@localhost
To:
Date: Thu, 10 Mar 2016 14:31:12 -0000
Message-ID: <2016031014311...@236.1.168.192.in-addr.arpa>

--===============2599669765216026223==
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="example.txt"

example attachment
--===============2599669765216026223==--

}}}

It is probably because of
[https://github.com/django/django/blob/53ccffdb8c8e47a4d4304df453d8c79a9be295ab/django/core/mail/message.py#L351
this] conditional. It checks if body is truthy, even though it is
sometimes called from EmailMultiAlternatives with a msg that should be
included.

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

Django

unread,
Mar 10, 2016, 11:09:10 AM3/10/16
to django-...@googlegroups.com
#26344: EmailMultiAlternatives ignores alternatives when it has attachments and
body is empty
-------------------------------+------------------------------------
Reporter: alvinlindstam | Owner: nobody
Type: Bug | Status: new

Component: Core (Mail) | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* stage: Unreviewed => Accepted


Comment:

I haven't completely verified the report to say what the proper solution
should be, however, the `if self.body` check was introduced in
2d082a34dc61a832710d98a933858fd2c0059644 without any tests, so at least
some test should be added to demonstrate what it accomplishes (if
anything).

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

Django

unread,
Aug 28, 2017, 8:41:02 AM8/28/17
to django-...@googlegroups.com
#26344: EmailMultiAlternatives ignores alternatives when it has attachments and
body is empty
--------------------------------+------------------------------------
Reporter: Alvin Lindstam | Owner: nobody
Type: Bug | Status: new

Component: Core (Mail) | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
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


Comment:

[https://github.com/django/django/pull/8983 PR]

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

Django

unread,
Sep 2, 2017, 6:28:36 AM9/2/17
to django-...@googlegroups.com
#26344: EmailMultiAlternatives ignores alternatives when it has attachments and
body is empty
-------------------------------------+-------------------------------------

Reporter: Alvin Lindstam | Owner: nobody
Type: Bug | Status: new

Component: Core (Mail) | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

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

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* stage: Accepted => Ready for checkin


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

Django

unread,
Sep 4, 2017, 8:46:50 AM9/4/17
to django-...@googlegroups.com
#26344: EmailMultiAlternatives ignores alternatives when it has attachments and
body is empty
-------------------------------------+-------------------------------------
Reporter: Alvin Lindstam | Owner: nobody
Type: Bug | Status: closed

Component: Core (Mail) | Version: 1.9
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: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"af35c69a3c595ff77188ff0d7dac6ab747484ac3" af35c69a]:
{{{
#!CommitTicketReference repository=""
revision="af35c69a3c595ff77188ff0d7dac6ab747484ac3"
Fixed #26344 -- Made EmailMessage include alternatives when the body is
empty and it has attachments.
}}}

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

Reply all
Reply to author
Forward
0 new messages