@@ -3082,13 +3082,40 @@ def test_address_list_with_list_separator_after_fold(self):
30823082 self ._test (parser .get_address_list (to )[0 ],
30833083 f'{ a } ,\n =?utf-8?q?H=C3=BCbsch?= Kaktus <beautiful@example.com>\n ' )
30843084
3085- a = '.' * 79
3085+ a = '.' * 79 # ('.' is a special, so must be in quoted-string.)
30863086 to = f'"{ a } " <xyz@example.com>, "Hübsch Kaktus" <beautiful@example.com>'
30873087 self ._test (parser .get_address_list (to )[0 ],
3088- f'{ a } \n '
3088+ f'" { a } " \n '
30893089 ' <xyz@example.com>, =?utf-8?q?H=C3=BCbsch?= Kaktus '
30903090 '<beautiful@example.com>\n ' )
30913091
3092+ def test_address_list_with_specials_in_long_quoted_string (self ):
3093+ # Regression for gh-80222.
3094+ policy = self .policy .clone (max_line_length = 40 )
3095+ cases = [
3096+ # (to, folded)
3097+ ('"Exfiltrator <spy@example.org> (unclosed comment?" <to@example.com>' ,
3098+ '"Exfiltrator <spy@example.org> (unclosed\n '
3099+ ' comment?" <to@example.com>\n ' ),
3100+ ('"Escaped \\ " chars \\ \\ in quoted-string stay escaped" <to@example.com>' ,
3101+ '"Escaped \\ " chars \\ \\ in quoted-string\n '
3102+ ' stay escaped" <to@example.com>\n ' ),
3103+ ('This long display name does not need quotes <to@example.com>' ,
3104+ 'This long display name does not need\n '
3105+ ' quotes <to@example.com>\n ' ),
3106+ ('"Quotes are not required but are retained here" <to@example.com>' ,
3107+ '"Quotes are not required but are\n '
3108+ ' retained here" <to@example.com>\n ' ),
3109+ ('"A quoted-string, it can be a valid local-part"@example.com' ,
3110+ '"A quoted-string, it can be a valid\n '
3111+ ' local-part"@example.com\n ' ),
3112+ ('"local-part-with-specials@but-no-fws.cannot-fold"@example.com' ,
3113+ '"local-part-with-specials@but-no-fws.cannot-fold"@example.com\n ' ),
3114+ ]
3115+ for (to , folded ) in cases :
3116+ with self .subTest (to = to ):
3117+ self ._test (parser .get_address_list (to )[0 ], folded , policy = policy )
3118+
30923119 # XXX Need tests with comments on various sides of a unicode token,
30933120 # and with unicode tokens in the comments. Spaces inside the quotes
30943121 # currently don't do the right thing.
0 commit comments