Skip to content

Commit 1db97a1

Browse files
authored
Merge pull request #430 from seshrs/bugfix/multipart-email
[Bugfix] email.Message.set_boundary()
2 parents d66fc88 + 961aa0f commit 1db97a1

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/future/backports/email/message.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ def set_boundary(self, boundary):
800800
# There was no Content-Type header, and we don't know what type
801801
# to set it to, so raise an exception.
802802
raise errors.HeaderParseError('No Content-Type header found')
803-
newparams = []
803+
newparams = list()
804804
foundp = False
805805
for pk, pv in params:
806806
if pk.lower() == 'boundary':
@@ -814,10 +814,10 @@ def set_boundary(self, boundary):
814814
# instead???
815815
newparams.append(('boundary', '"%s"' % boundary))
816816
# Replace the existing Content-Type header with the new value
817-
newheaders = []
817+
newheaders = list()
818818
for h, v in self._headers:
819819
if h.lower() == 'content-type':
820-
parts = []
820+
parts = list()
821821
for k, v in newparams:
822822
if v == '':
823823
parts.append(k)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
"""Tests for multipart emails."""
3+
4+
from future.tests.base import unittest
5+
import future.backports.email as email
6+
import future.backports.email.mime.multipart
7+
from future.builtins import list
8+
9+
class EmailMultiPartTests(unittest.TestCase):
10+
"""Tests for handling multipart email Messages."""
11+
12+
def test_multipart_serialize_without_boundary(self):
13+
"""Tests that serializing an empty multipart email does not fail."""
14+
multipart_message = email.mime.multipart.MIMEMultipart()
15+
self.assertIsNot(multipart_message.as_string(), None)
16+
17+
def test_multipart_set_boundary_does_not_change_header_type(self):
18+
"""
19+
Tests that Message.set_boundary() does not cause Python2 errors.
20+
21+
In particular, tests that set_boundary does not cause the type of the
22+
message headers list to be changed from the future built-in list.
23+
"""
24+
multipart_message = email.mime.multipart.MIMEMultipart()
25+
headers_type = type(multipart_message._headers)
26+
self.assertEqual(headers_type, type(list()))
27+
28+
boundary = '===============6387699881409002085=='
29+
multipart_message.set_boundary(boundary)
30+
headers_type = type(multipart_message._headers)
31+
self.assertEqual(headers_type, type(list()))

0 commit comments

Comments
 (0)