diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_email/test__header_value_parser.py | 72 | ||||
-rw-r--r-- | Lib/test/test_email/test_headerregistry.py | 28 |
2 files changed, 100 insertions, 0 deletions
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py index 676732b..12da3cf 100644 --- a/Lib/test/test_email/test__header_value_parser.py +++ b/Lib/test/test_email/test__header_value_parser.py @@ -2494,6 +2494,78 @@ class TestParser(TestParserMixin, TestEmailBase): ";foo", ";foo", ";foo", [errors.InvalidHeaderDefect]*3 ) + # get_msg_id + + def test_get_msg_id_valid(self): + msg_id = self._test_get_x( + parser.get_msg_id, + "<simeple.local@example.something.com>", + "<simeple.local@example.something.com>", + "<simeple.local@example.something.com>", + [], + '', + ) + self.assertEqual(msg_id.token_type, 'msg-id') + + def test_get_msg_id_obsolete_local(self): + msg_id = self._test_get_x( + parser.get_msg_id, + '<"simeple.local"@example.com>', + '<"simeple.local"@example.com>', + '<simeple.local@example.com>', + [errors.ObsoleteHeaderDefect], + '', + ) + self.assertEqual(msg_id.token_type, 'msg-id') + + def test_get_msg_id_non_folding_literal_domain(self): + msg_id = self._test_get_x( + parser.get_msg_id, + "<simple.local@[someexamplecom.domain]>", + "<simple.local@[someexamplecom.domain]>", + "<simple.local@[someexamplecom.domain]>", + [], + "", + ) + self.assertEqual(msg_id.token_type, 'msg-id') + + + def test_get_msg_id_obsolete_domain_part(self): + msg_id = self._test_get_x( + parser.get_msg_id, + "<simplelocal@(old)example.com>", + "<simplelocal@(old)example.com>", + "<simplelocal@ example.com>", + [errors.ObsoleteHeaderDefect], + "" + ) + + def test_get_msg_id_no_id_right_part(self): + msg_id = self._test_get_x( + parser.get_msg_id, + "<simplelocal>", + "<simplelocal>", + "<simplelocal>", + [errors.InvalidHeaderDefect], + "" + ) + self.assertEqual(msg_id.token_type, 'msg-id') + + def test_get_msg_id_no_angle_start(self): + with self.assertRaises(errors.HeaderParseError): + parser.get_msg_id("msgwithnoankle") + + def test_get_msg_id_no_angle_end(self): + msg_id = self._test_get_x( + parser.get_msg_id, + "<simplelocal@domain", + "<simplelocal@domain>", + "<simplelocal@domain>", + [errors.InvalidHeaderDefect], + "" + ) + self.assertEqual(msg_id.token_type, 'msg-id') + @parameterize class Test_parse_mime_parameters(TestParserMixin, TestEmailBase): diff --git a/Lib/test/test_email/test_headerregistry.py b/Lib/test/test_email/test_headerregistry.py index d100709..7550546 100644 --- a/Lib/test/test_email/test_headerregistry.py +++ b/Lib/test/test_email/test_headerregistry.py @@ -1648,6 +1648,34 @@ class TestFolding(TestHeaderBase): 'xxxxxxxxxxxxxxxxxxxx=3D=3D-xxx-xx-xx?=\n' ' =?utf-8?q?=3E?=\n') + def test_message_id_header_is_not_folded(self): + h = self.make_header( + 'Message-ID', + '<somemessageidlongerthan@maxlinelength.com>') + self.assertEqual( + h.fold(policy=policy.default.clone(max_line_length=20)), + 'Message-ID: <somemessageidlongerthan@maxlinelength.com>\n') + + # Test message-id isn't folded when id-right is no-fold-literal. + h = self.make_header( + 'Message-ID', + '<somemessageidlongerthan@[127.0.0.0.0.0.0.0.0.1]>') + self.assertEqual( + h.fold(policy=policy.default.clone(max_line_length=20)), + 'Message-ID: <somemessageidlongerthan@[127.0.0.0.0.0.0.0.0.1]>\n') + + # Test message-id isn't folded when id-right is non-ascii characters. + h = self.make_header('Message-ID', '<ईमेल@wők.com>') + self.assertEqual( + h.fold(policy=policy.default.clone(max_line_length=30)), + 'Message-ID: <ईमेल@wők.com>\n') + + # Test message-id is folded without breaking the msg-id token into + # encoded words, *even* if they don't fit into max_line_length. + h = self.make_header('Message-ID', '<ईमेलfromMessage@wők.com>') + self.assertEqual( + h.fold(policy=policy.default.clone(max_line_length=20)), + 'Message-ID:\n <ईमेलfromMessage@wők.com>\n') if __name__ == '__main__': unittest.main() |