@@ -24,6 +24,68 @@ def test_move_works(acfactory):
2424 assert msg .text == "message1"
2525
2626
27+ def test_move_avoids_loop (acfactory , direct_imap ):
28+ """Test that the message is only moved from INBOX to DeltaChat.
29+
30+ This is to avoid busy loop if moved message reappears in the Inbox
31+ or some scanned folder later.
32+ For example, this happens on servers that alias `INBOX.DeltaChat` to `DeltaChat` folder,
33+ so the message moved to `DeltaChat` appears as a new message in the `INBOX.DeltaChat` folder.
34+ We do not want to move this message from `INBOX.DeltaChat` to `DeltaChat` again.
35+ """
36+ ac1 , ac2 = acfactory .get_online_accounts (2 )
37+ ac2 .set_config ("mvbox_move" , "1" )
38+ ac2 .set_config ("delete_server_after" , "0" )
39+ ac2 .bring_online ()
40+
41+ # Create INBOX.DeltaChat folder and make sure
42+ # it is detected by full folder scan.
43+ ac2_direct_imap = direct_imap (ac2 )
44+ ac2_direct_imap .create_folder ("INBOX.DeltaChat" )
45+ ac2 .stop_io ()
46+ ac2 .start_io ()
47+
48+ while True :
49+ event = ac2 .wait_for_event ()
50+ # Wait until the end of folder scan.
51+ if event .kind == EventType .INFO and "Found folders:" in event .msg :
52+ break
53+
54+ ac1_chat = acfactory .get_accepted_chat (ac1 , ac2 )
55+ ac1_chat .send_text ("Message 1" )
56+
57+ # Message is moved to the DeltaChat folder and downloaded.
58+ ac2_msg1 = ac2 .wait_for_incoming_msg ().get_snapshot ()
59+ assert ac2_msg1 .text == "Message 1"
60+
61+ # Move the message to the INBOX.DeltaChat again.
62+ # We assume that test server uses "." as the delimiter.
63+ ac2_direct_imap .select_folder ("DeltaChat" )
64+ ac2_direct_imap .conn .move (["*" ], "INBOX.DeltaChat" )
65+
66+ ac1_chat .send_text ("Message 2" )
67+ ac2_msg2 = ac2 .wait_for_incoming_msg ().get_snapshot ()
68+ assert ac2_msg2 .text == "Message 2"
69+
70+ # Stop and start I/O to trigger folder scan.
71+ ac2 .stop_io ()
72+ ac2 .start_io ()
73+ while True :
74+ event = ac2 .wait_for_event ()
75+ # Wait until the end of folder scan.
76+ if event .kind == EventType .INFO and "Found folders:" in event .msg :
77+ break
78+
79+ # Check that Message 1 is still in the INBOX.DeltaChat folder
80+ # and Message 2 is in the DeltaChat folder.
81+ ac2_direct_imap .select_folder ("INBOX" )
82+ assert len (ac2_direct_imap .get_all_messages ()) == 0
83+ ac2_direct_imap .select_folder ("DeltaChat" )
84+ assert len (ac2_direct_imap .get_all_messages ()) == 1
85+ ac2_direct_imap .select_folder ("INBOX.DeltaChat" )
86+ assert len (ac2_direct_imap .get_all_messages ()) == 1
87+
88+
2789def test_reactions_for_a_reordering_move (acfactory , direct_imap ):
2890 """When a batch of messages is moved from Inbox to DeltaChat folder with a single MOVE command,
2991 their UIDs may be reordered (e.g. Gmail is known for that) which led to that messages were
0 commit comments