aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhilash Raj <maxking@users.noreply.github.com>2019-06-04 13:41:34 -0400
committerBarry Warsaw <barry@python.org>2019-06-04 10:41:34 -0700
commit46d88a113142b26c01c95c93846a89318ba87ffc (patch)
tree756e002f21f3fa01483b309ddf85b0ed37e2e19d /Lib/email/headerregistry.py
parentbpo-37153: test_venv.test_mutiprocessing() calls pool.terminate() (GH-13816) (diff)
downloadcpython-46d88a113142b26c01c95c93846a89318ba87ffc.tar.gz
cpython-46d88a113142b26c01c95c93846a89318ba87ffc.tar.bz2
cpython-46d88a113142b26c01c95c93846a89318ba87ffc.zip
bpo-35805: Add parser for Message-ID email header. (GH-13397)
* bpo-35805: Add parser for Message-ID header. This parser is based on the definition of Identification Fields from RFC 5322 Sec 3.6.4. This should also prevent folding of Message-ID header using RFC 2047 encoded words and hence fix bpo-35805. * Prevent folding of non-ascii message-id headers. * Add fold method to MsgID token to prevent folding.
Diffstat (limited to 'Lib/email/headerregistry.py')
-rw-r--r--Lib/email/headerregistry.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/email/headerregistry.py b/Lib/email/headerregistry.py
index 00652049f2f..452c6ad5084 100644
--- a/Lib/email/headerregistry.py
+++ b/Lib/email/headerregistry.py
@@ -520,6 +520,18 @@ class ContentTransferEncodingHeader:
return self._cte
+class MessageIDHeader:
+
+ max_count = 1
+ value_parser = staticmethod(parser.parse_message_id)
+
+ @classmethod
+ def parse(cls, value, kwds):
+ kwds['parse_tree'] = parse_tree = cls.value_parser(value)
+ kwds['decoded'] = str(parse_tree)
+ kwds['defects'].extend(parse_tree.all_defects)
+
+
# The header factory #
_default_header_map = {
@@ -542,6 +554,7 @@ _default_header_map = {
'content-type': ContentTypeHeader,
'content-disposition': ContentDispositionHeader,
'content-transfer-encoding': ContentTransferEncodingHeader,
+ 'message-id': MessageIDHeader,
}
class HeaderRegistry: