Skip to content
Open
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
2 changes: 1 addition & 1 deletion Lib/email/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ def get_boundary(self, failobj=None):
parameter, and it is unquoted.
"""
missing = object()
boundary = self.get_param('boundary', missing)
boundary = self.get_param('boundary', missing, unquote=False)
if boundary is missing:
return failobj
# RFC 2046 says that boundaries may begin but not end in w/s
Expand Down
36 changes: 36 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,42 @@ def test_boundary_with_leading_space(self):
eq(msg.get_boundary(), ' XXXX')
eq(len(msg.get_payload()), 2)

def test_boundary_stripped_only_once(self):
eq = self.assertEqual
msg = email.message_from_string(textwrap.dedent('''\
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="<>"

--<>
Content-Type: text/plain


--<>
Content-Type: text/plain

--<>--
'''))
self.assertTrue(msg.is_multipart())
eq(msg.get_boundary(), '<>')
eq(len(msg.get_payload()), 2)

msg = email.message_from_string(textwrap.dedent('''\
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=<"">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this is not a valid parameter value. Technically this should in fact fail to be recognized as a multipart. Per rfc 2045, <> characters must be inside quotes to be valid. Any idea what other email programs do with this kind of broken value?

I'm reluctant to apply the proposed fix since it would make valid a boundary specification that is not in fact valid. See my comments on the issue for more.


--""
Content-Type: text/plain


--""
Content-Type: text/plain

--""--
'''))
self.assertTrue(msg.is_multipart())
eq(msg.get_boundary(), '""')
eq(len(msg.get_payload()), 2)

def test_boundary_without_trailing_newline(self):
m = Parser().parsestr("""\
Content-Type: multipart/mixed; boundary="===============0012394164=="
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :func:`email.message.Message.get_boundary` strips boundaries twice.
Loading