summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_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/test/test_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/test/test_email')
-rw-r--r--Lib/test/test_email/test__header_value_parser.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py
index 71168f3..d59d701 100644
--- a/Lib/test/test_email/test__header_value_parser.py
+++ b/Lib/test/test_email/test__header_value_parser.py
@@ -2639,10 +2639,44 @@ class TestParser(TestParserMixin, TestEmailBase):
self.assertEqual(msg_id.token_type, 'msg-id')
def test_get_msg_id_invalid_expected_msg_id_not_found(self):
- text = "Message-Id: 935-XPB-567:0:86089:180874:0:45327:9:90305:17843586-40@example.com"
+ text = "935-XPB-567:0:45327:9:90305:17843586-40@example.com"
msg_id = parser.parse_message_id(text)
- self.assertDefectsEqual(msg_id.all_defects,
- [errors.InvalidHeaderDefect])
+ self.assertDefectsEqual(
+ msg_id.all_defects,
+ [errors.InvalidHeaderDefect])
+
+ def test_parse_invalid_message_id(self):
+ message_id = self._test_parse_x(
+ parser.parse_message_id,
+ "935-XPB-567:0:45327:9:90305:17843586-40@example.com",
+ "935-XPB-567:0:45327:9:90305:17843586-40@example.com",
+ "935-XPB-567:0:45327:9:90305:17843586-40@example.com",
+ [errors.InvalidHeaderDefect],
+ )
+ self.assertEqual(message_id.token_type, 'invalid-message-id')
+
+ def test_parse_valid_message_id(self):
+ message_id = self._test_parse_x(
+ parser.parse_message_id,
+ "<aperson@somedomain>",
+ "<aperson@somedomain>",
+ "<aperson@somedomain>",
+ [],
+ )
+ self.assertEqual(message_id.token_type, 'message-id')
+
+ def test_parse_message_id_with_remaining(self):
+ message_id = self._test_parse_x(
+ parser.parse_message_id,
+ "<validmessageid@example>thensomething",
+ "<validmessageid@example>",
+ "<validmessageid@example>",
+ [errors.InvalidHeaderDefect],
+ [],
+ )
+ self.assertEqual(message_id.token_type, 'message-id')
+ self.assertEqual(str(message_id.all_defects[0]),
+ "Unexpected 'thensomething'")
def test_get_msg_id_no_angle_start(self):
with self.assertRaises(errors.HeaderParseError):