summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorAbhilash Raj <maxking@users.noreply.github.com>2019-12-09 01:35:38 (GMT)
committerGitHub <noreply@github.com>2019-12-09 01:35:38 (GMT)
commit68157da8b42b26408af5d157d2dba4fcf29c6320 (patch)
tree24b6efbd34f13ad32d02ac4981b8f97b5156d027 /Lib/email
parent080ee5a88406fb68aaab741145cd5d2a7c5f2ad6 (diff)
downloadcpython-68157da8b42b26408af5d157d2dba4fcf29c6320.zip
cpython-68157da8b42b26408af5d157d2dba4fcf29c6320.tar.gz
cpython-68157da8b42b26408af5d157d2dba4fcf29c6320.tar.bz2
bpo-38698: Add a new InvalidMessageID token to email header parser. (GH-17503)
This adds a new InvalidMessageID token to the email header parser which can be used to represent invalid message-id headers in the parse tree.
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/_header_value_parser.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index abdef81..cb01322 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -850,10 +850,15 @@ class MsgID(TokenList):
# message-id tokens may not be folded.
return str(self) + policy.linesep
+
class MessageID(MsgID):
token_type = 'message-id'
+class InvalidMessageID(MessageID):
+ token_type = 'invalid-message-id'
+
+
class Header(TokenList):
token_type = 'header'
@@ -2110,11 +2115,18 @@ def parse_message_id(value):
message_id = MessageID()
try:
token, value = get_msg_id(value)
- except errors.HeaderParseError:
- message_id.defects.append(errors.InvalidHeaderDefect(
- "Expected msg-id but found {!r}".format(value)))
- else:
message_id.append(token)
+ except errors.HeaderParseError as ex:
+ token = get_unstructured(value)
+ message_id = InvalidMessageID(token)
+ message_id.defects.append(
+ errors.InvalidHeaderDefect("Invalid msg-id: {!r}".format(ex)))
+ else:
+ # Value after parsing a valid msg_id should be None.
+ if value:
+ message_id.defects.append(errors.InvalidHeaderDefect(
+ "Unexpected {!r}".format(value)))
+
return message_id
#