diff --git a/Lib/email/feedparser.py b/Lib/email/feedparser.py index 7c07ca86457a2aa..807192c4cc7745f 100644 --- a/Lib/email/feedparser.py +++ b/Lib/email/feedparser.py @@ -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. diff --git a/Lib/email/message.py b/Lib/email/message.py index b6512f2198af43f..efa1ef5ce887918 100644 --- a/Lib/email/message.py +++ b/Lib/email/message.py @@ -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. diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index f97ccc6711cc738..0f95a0434200ad8 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -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): diff --git a/Misc/NEWS b/Misc/NEWS index 9da682b38792a91..5efab5a0f42e073 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -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.