summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-12-09 02:11:31 (GMT)
committerGitHub <noreply@github.com>2019-12-09 02:11:31 (GMT)
commitf66f4a09d0b6817fe6a86a567fd506aa223f1563 (patch)
tree67711559e33d2c2f03d04631520be00b07cff1d7 /Lib/email
parent960fca1a5887a277fd6031cf4c4b6fb31b08ebf5 (diff)
downloadcpython-f66f4a09d0b6817fe6a86a567fd506aa223f1563.zip
cpython-f66f4a09d0b6817fe6a86a567fd506aa223f1563.tar.gz
cpython-f66f4a09d0b6817fe6a86a567fd506aa223f1563.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. (cherry picked from commit 68157da8b42b26408af5d157d2dba4fcf29c6320) Co-authored-by: Abhilash Raj <maxking@users.noreply.github.com>
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
#