@@ -484,3 +484,55 @@ def test_scan_folders(acfactory, log, direct_imap, folder, move, expected_destin
484484 if folder != expected_destination :
485485 ac1_direct_imap .select_folder (folder )
486486 assert len (ac1_direct_imap .get_all_messages ()) == 0
487+
488+
489+ def test_trash_multiple_messages (acfactory , direct_imap , log ):
490+ ac1 , ac2 = acfactory .get_online_accounts (2 )
491+ ac2 .stop_io ()
492+
493+ # Create the Trash folder on IMAP server and configure deletion to it. There was a bug that if
494+ # Trash wasn't configured initially, it can't be configured later, let's check this.
495+ log .section ("Creating trash folder" )
496+ ac2_direct_imap = direct_imap (ac2 )
497+ ac2_direct_imap .create_folder ("Trash" )
498+ ac2 .set_config ("delete_server_after" , "0" )
499+ ac2 .set_config ("sync_msgs" , "0" )
500+ ac2 .set_config ("delete_to_trash" , "1" )
501+
502+ log .section ("Check that Trash can be configured initially as well" )
503+ ac3 = ac2 .clone ()
504+ ac3 .bring_online ()
505+ assert ac3 .get_config ("configured_trash_folder" )
506+ ac3 .stop_io ()
507+
508+ ac2 .start_io ()
509+ chat12 = acfactory .get_accepted_chat (ac1 , ac2 )
510+
511+ log .section ("ac1: sending 3 messages" )
512+ texts = ["first" , "second" , "third" ]
513+ for text in texts :
514+ chat12 .send_text (text )
515+
516+ log .section ("ac2: waiting for all messages on the other side" )
517+ to_delete = []
518+ for text in texts :
519+ msg = ac2 .wait_for_incoming_msg ().get_snapshot ()
520+ assert msg .text in texts
521+ if text != "second" :
522+ to_delete .append (msg )
523+ # ac2 has received some messages, this is impossible w/o the trash folder configured, let's
524+ # check the configuration.
525+ assert ac2 .get_config ("configured_trash_folder" ) == "Trash"
526+
527+ log .section ("ac2: deleting all messages except second" )
528+ assert len (to_delete ) == len (texts ) - 1
529+ ac2 .delete_messages (to_delete )
530+
531+ log .section ("ac2: test that only one message is left" )
532+ while 1 :
533+ ac2 .wait_for_event (EventType .IMAP_MESSAGE_MOVED )
534+ ac2_direct_imap .select_config_folder ("inbox" )
535+ nr_msgs = len (ac2_direct_imap .get_all_messages ())
536+ assert nr_msgs > 0
537+ if nr_msgs == 1 :
538+ break
0 commit comments