Skip to content
Closed
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
1 change: 1 addition & 0 deletions Lib/email/feedparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def _parsegen(self):
# Done with the headers, so parse them and figure out what we're
# supposed to see in the body of the message.
self._parse_headers(headers)
self._cur.group_headers()
# Headers-only parsing is a backwards compatibility hack, which was
# necessary in the older parser, which could raise errors. All
# remaining lines in the input are thrown into the message body.
Expand Down
8 changes: 8 additions & 0 deletions Lib/email/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,14 @@ def set_raw(self, name, value):
"""
self._headers.append((name, value))

def group_headers(self):
"""Check if there are headers with same name and groups them"""
headers = {}
for name, value in self._headers:
headers.setdefault(name, []).append(value.strip(';'))

self._headers = [(name, '; '.join(value)) for name, value in headers.items()]

def raw_items(self):
"""Return the (name, value) header pairs without modification.

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ def test_get_params(self):
'X-Header: foo; bar="one"; baz=two\n')
eq(msg.get_params(header='x-header'),
[('foo', ''), ('bar', 'one'), ('baz', 'two')])
msg = email.message_from_string(
'X-Header: foo=one;\nX-Header: bar=two\nX-Header: baz=three;')
eq(msg.get_params(header='x-header'),
[('foo', 'one'), ('bar', 'two'), ('baz', 'three')])

# test_headerregistry.TestContentTypeHeader.spaces_around_param_equals
def test_get_param_liberal(self):
Expand Down
1 change: 1 addition & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ Extension Modules

Library
-------
- bpo-29678: Fixed email.Message.get_params decodes only first one header value.

- bpo-29615: SimpleXMLRPCDispatcher no longer chains KeyError (or any other
exception) to exception(s) raised in the dispatched methods.
Expand Down