diff options
Diffstat (limited to 'Lib/email/_header_value_parser.py')
-rw-r--r-- | Lib/email/_header_value_parser.py | 20 |
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 # |