Skip to content

[Bugfix] email.Message.set_boundary() #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/future/backports/email/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def set_boundary(self, boundary):
# There was no Content-Type header, and we don't know what type
# to set it to, so raise an exception.
raise errors.HeaderParseError('No Content-Type header found')
newparams = []
newparams = list()
foundp = False
for pk, pv in params:
if pk.lower() == 'boundary':
Expand All @@ -814,10 +814,10 @@ def set_boundary(self, boundary):
# instead???
newparams.append(('boundary', '"%s"' % boundary))
# Replace the existing Content-Type header with the new value
newheaders = []
newheaders = list()
for h, v in self._headers:
if h.lower() == 'content-type':
parts = []
parts = list()
for k, v in newparams:
if v == '':
parts.append(k)
Expand Down
31 changes: 31 additions & 0 deletions tests/test_future/test_email_multipart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
"""Tests for multipart emails."""

from future.tests.base import unittest
import future.backports.email as email
import future.backports.email.mime.multipart
from future.builtins import list

class EmailMultiPartTests(unittest.TestCase):
"""Tests for handling multipart email Messages."""

def test_multipart_serialize_without_boundary(self):
"""Tests that serializing an empty multipart email does not fail."""
multipart_message = email.mime.multipart.MIMEMultipart()
self.assertIsNot(multipart_message.as_string(), None)

def test_multipart_set_boundary_does_not_change_header_type(self):
"""
Tests that Message.set_boundary() does not cause Python2 errors.

In particular, tests that set_boundary does not cause the type of the
message headers list to be changed from the future built-in list.
"""
multipart_message = email.mime.multipart.MIMEMultipart()
headers_type = type(multipart_message._headers)
self.assertEqual(headers_type, type(list()))

boundary = '===============6387699881409002085=='
multipart_message.set_boundary(boundary)
headers_type = type(multipart_message._headers)
self.assertEqual(headers_type, type(list()))