Fixed #27848 -- Prevented crash when attaching a .eml file to a message

Thanks Sébastien Ramage for the report.
This commit is contained in:
Claude Paroz 2017-04-01 15:08:21 +02:00
parent bde86ce9ae
commit 9a9e228321
3 changed files with 46 additions and 1 deletions

View File

@ -381,7 +381,7 @@ class EmailMessage:
elif not isinstance(content, Message): elif not isinstance(content, Message):
# For compatibility with existing code, parse the message # For compatibility with existing code, parse the message
# into an email.Message object if it is not one already. # into an email.Message object if it is not one already.
content = message_from_string(content) content = message_from_string(force_text(content))
attachment = SafeMIMEMessage(content, subtype) attachment = SafeMIMEMessage(content, subtype)
else: else:

View File

@ -0,0 +1,44 @@
MIME-Version: 1.0
Received: by 10.220.191.194 with HTTP; Wed, 11 May 2011 12:27:12 -0700 (PDT)
Date: Wed, 11 May 2011 13:27:12 -0600
Delivered-To: jncjkq@gmail.com
Message-ID: <BANLkTi=JCQO1h3ET-pT_PLEHejhSSYxTZw@mail.jncjkq.com>
Subject: Test
From: Bill Jncjkq <jncjkq@gmail.com>
To: bookmarks@jncjkq.net
Content-Type: multipart/mixed; boundary=bcaec54eecc63acce904a3050f79
--bcaec54eecc63acce904a3050f79
Content-Type: multipart/alternative; boundary=bcaec54eecc63acce604a3050f77
--bcaec54eecc63acce604a3050f77
Content-Type: text/plain; charset=ISO-8859-1
--
Bill Jncjkq
--bcaec54eecc63acce604a3050f77
Content-Type: text/html; charset=ISO-8859-1
<br clear="all">--<br>Bill Jncjkq<br>
--bcaec54eecc63acce604a3050f77--
--bcaec54eecc63acce904a3050f79
Content-Type: text/html; charset=US-ASCII; name="bookmarks-really-short.html"
Content-Disposition: attachment; filename="bookmarks-really-short.html"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_gnknv6u70
PCFET0NUWVBFIE5FVFNDQVBFLUJvb2ttYXJrLWZpbGUtMT4KCTxIVE1MPgoJPE1FVEEgSFRUUC1F
UVVJVj0iQ29udGVudC1UeXBlIiBDT05URU5UPSJ0ZXh0L2h0bWw7IGNoYXJzZXQ9VVRGLTgiPgoJ
PFRpdGxlPkJvb2ttYXJrczwvVGl0bGU+Cgk8SDE+Qm9va21hcmtzPC9IMT4KCQk8RFQ+PEgzIEZP
TERFRD5UZWNoIE5ld3M8L0gzPgoJCTxETD48cD4KCQkJPERUPjxBIEhSRUY9Imh0dHA6Ly93d3cu
Y25ldC5jb20vIj5DTmV0PC9BPgoJCQk8RFQ+PEEgSFJFRj0iaHR0cDovL3d3dy53aXJlZC5jb20v
Ij5XaXJlZCBOZXdzPC9BPgoJCTwvREw+PHA+CgkJPERUPjxIMyBGT0xERUQ+VG9vbHMgYW5kIFJl
ZmVyZW5jZTwvSDM+CgkJPERMPjxwPgoJCQk8RFQ+PEEgSFJFRj0iaHR0cDovL3d3dy5tb25zdGVy
LmNvbS8iPk1vbnN0ZXIuY29tPC9BPgoJCQk8RFQ+PEEgSFJFRj0iaHR0cDovL3d3dy53ZWJtZC5j
b20vIj5XZWJNRDwvQT4KCQk8L0RMPjxwPgoJCTxEVD48SDMgRk9MREVEPlRyYXZlbDwvSDM+CgkJ
PERMPjxwPgoJCQk8RFQ+PEEgSFJFRj0iaHR0cDovL2ZvZG9ycy5jb20vIj5Gb2RvcnM8L0E+CgkJ
CTxEVD48QSBIUkVGPSJodHRwOi8vd3d3LnRyYXZlbG9jaXR5LmNvbS8iPlRyYXZlbG9jaXR5PC9B
PgoJCTwvREw+PHA+Cgk8L0RMPjxwPgo8L0hUTUw+
--bcaec54eecc63acce904a3050f79--

View File

@ -401,6 +401,7 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
('file_png', None), ('file_png', None),
('file_txt.png', 'image/png'), ('file_txt.png', 'image/png'),
('file_png.txt', 'text/plain'), ('file_png.txt', 'text/plain'),
('file.eml', 'message/rfc822'),
) )
test_mimetypes = ['text/plain', 'image/png', None] test_mimetypes = ['text/plain', 'image/png', None]