@@ -1041,6 +1041,51 @@ def cmd_FETCH(self, tag, args):
10411041 self .assertEqual (data , [(b'1 (BODY[HEADER] {13}' , b'Subject: test' ),
10421042 b')' ])
10431043
1044+ def test_literal_terminating_response (self ):
1045+ # A literal ending a response (a LIST mailbox name sent as a literal)
1046+ # has an empty trailer that must not be swallowed. Conforming case:
1047+ # no spurious blank lines.
1048+ names = [b'My (box)"' , b'Another' , b'Third' ]
1049+ class Handler (SimpleIMAPHandler ):
1050+ def cmd_LIST (self , tag , args ):
1051+ for name in names :
1052+ self ._send (b'* LIST (\\ HasNoChildren) "/" {%d}\r \n '
1053+ % len (name ))
1054+ self ._send (name )
1055+ self ._send (b'\r \n ' ) # ends the response, no blank
1056+ self ._send_tagged (tag , 'OK' , 'LIST completed' )
1057+ client , _ = self ._setup (Handler )
1058+ client .login ('user' , 'pass' )
1059+ typ , data = client .list ()
1060+ self .assertEqual (typ , 'OK' )
1061+ self .assertEqual (data , [
1062+ (b'(\\ HasNoChildren) "/" {9}' , b'My (box)"' ), b'' ,
1063+ (b'(\\ HasNoChildren) "/" {7}' , b'Another' ), b'' ,
1064+ (b'(\\ HasNoChildren) "/" {5}' , b'Third' ), b'' ,
1065+ ])
1066+
1067+ def test_spurious_blank_lines_between_responses (self ):
1068+ # A spurious blank line after each terminating literal falls between the
1069+ # untagged responses and must be skipped, even several in a row.
1070+ names = [b'My (box)"' , b'Another' , b'Third' ]
1071+ class Handler (SimpleIMAPHandler ):
1072+ def cmd_LIST (self , tag , args ):
1073+ for name in names :
1074+ self ._send (b'* LIST (\\ HasNoChildren) "/" {%d}\r \n '
1075+ % len (name ))
1076+ self ._send (name )
1077+ self ._send (b'\r \n \r \n ' ) # ends the response, then a blank
1078+ self ._send_tagged (tag , 'OK' , 'LIST completed' )
1079+ client , _ = self ._setup (Handler )
1080+ client .login ('user' , 'pass' )
1081+ typ , data = client .list ()
1082+ self .assertEqual (typ , 'OK' )
1083+ self .assertEqual (data , [
1084+ (b'(\\ HasNoChildren) "/" {9}' , b'My (box)"' ), b'' ,
1085+ (b'(\\ HasNoChildren) "/" {7}' , b'Another' ), b'' ,
1086+ (b'(\\ HasNoChildren) "/" {5}' , b'Third' ), b'' ,
1087+ ])
1088+
10441089 def test_unselect (self ):
10451090 client , server = self ._setup (SimpleIMAPHandler )
10461091 client .login ('user' , 'pass' )
0 commit comments