@@ -242,6 +242,52 @@ def cmd_CAPABILITY(self, tag, args):
242242 self .assertRaises (imaplib .IMAP4 .abort , self .imap_class ,
243243 * server .server_address )
244244
245+ def test_create_quoted (self ):
246+ # https://bugs.python.org/issue13940
247+ class CreateHandler (SimpleIMAPHandler ):
248+ def cmd_CREATE (self , tag , args ):
249+ if ' ' .join (args ) == '"quoted name with spaces and escaped \\ " \\ \\ specials"' :
250+ self ._send_tagged (tag , 'OK' , 'CREATE completed' )
251+ return self ._send_tagged (tag , 'BAD' , args [0 ])
252+ client , server = self ._setup (CreateHandler )
253+ client .state = 'AUTH'
254+ typ , data = client .create ('quoted name with spaces and escaped " \\ specials' )
255+ self .assertEqual (typ , 'OK' )
256+ self .assertEqual (data [0 ], b'CREATE completed' )
257+
258+ def test_create_unquoted (self ):
259+ # https://bugs.python.org/issue13940
260+ class CreateHandler (SimpleIMAPHandler ):
261+ def cmd_CREATE (self , tag , args ):
262+ if args [0 ] == 'unquoted-name-with-no-sp3cials' :
263+ self ._send_tagged (tag , 'OK' , 'CREATE completed' )
264+ return self ._send_tagged (tag , 'BAD' , args [0 ])
265+ client , server = self ._setup (CreateHandler )
266+ client .state = 'AUTH'
267+ typ , data = client .create ('unquoted-name-with-no-sp3cials' )
268+ self .assertEqual (typ , 'OK' )
269+ self .assertEqual (data [0 ], b'CREATE completed' )
270+
271+ def test_create_force_unquoted (self ):
272+ # https://bugs.python.org/issue13940
273+ class CreateHandler (SimpleIMAPHandler ):
274+ def cmd_CREATE (self , tag , args ):
275+ if ' ' .join (args ) == 'unquoted name with spaces and " \\ specials' :
276+ self ._send_tagged (tag , 'OK' , 'CREATE completed' )
277+ return self ._send_tagged (tag , 'BAD' , args [0 ])
278+ client , server = self ._setup (CreateHandler )
279+ client .state = 'AUTH'
280+ typ , data = client .create ('(unquoted name with spaces and " \\ specials)' )
281+ self .assertEqual (typ , 'OK' )
282+ self .assertEqual (data [0 ], b'CREATE completed' )
283+
284+ def test_create_crlf (self ):
285+ client , server = self ._setup (SimpleIMAPHandler )
286+ client .state = 'AUTH'
287+ with self .assertRaisesRegex (imaplib .IMAP4 .error ,
288+ 'illegal cr or lf in argument' ):
289+ typ , data = client .create ('name with CR and LF \n \r ' )
290+
245291 def test_enable_raises_error_if_not_AUTH (self ):
246292 class EnableHandler (SimpleIMAPHandler ):
247293 capabilities = 'AUTH ENABLE UTF8=ACCEPT'
0 commit comments