core icon indicating copy to clipboard operation
core copied to clipboard

IMAP may go IDLE when there are unfetched \Seen flags

Open link2xt opened this issue 1 year ago • 0 comments

test_markseen_contact_request failed here with a timeout:

    def test_markseen_contact_request(acfactory, tmp_path):
        """
        Test that seen status is synchronized for contact request messages
        even though read receipt is not sent.
        """
        alice, bob = acfactory.get_online_accounts(2)

        # Bob sets up a second device.
        bob.export_backup(tmp_path)
        files = list(tmp_path.glob("*.tar"))
        bob2 = acfactory.get_unconfigured_account()
        bob2.import_backup(files[0])
        bob2.start_io()

        alice_chat_bob = alice.create_chat(bob)
        alice_chat_bob.send_text("Hello Bob!")

        message = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id)
        message2 = bob2.get_message_by_id(bob2.wait_for_incoming_msg_event().msg_id)
        assert message2.get_snapshot().state == MessageState.IN_FRESH

        message.mark_seen()
        while True:
>           event = bob2.wait_for_event()

In the log this happened:

DEBUG    root:rpc.py:180 account_id=2 got an event {'kind': 'Info', 'msg': 'src/imap.rs:1137: Marked messages 1 in folder INBOX as seen.'}
DEBUG    root:rpc.py:180 account_id=3 got an event {'kind': 'Info', 'msg': 'src/imap.rs:1207: FETCH result contains no UID, skipping'}
DEBUG    root:rpc.py:180 account_id=2 got an event {'kind': 'Info', 'msg': 'src/imap.rs:543: No new emails in folder "INBOX".'}
DEBUG    root:rpc.py:180 account_id=3 got an event {'kind': 'ConnectivityChanged'}
DEBUG    root:rpc.py:180 account_id=3 got an event {'kind': 'ImapInboxIdle'}
DEBUG    root:rpc.py:180 account_id=3 got an event {'kind': 'Info', 'msg': 'src/scheduler.rs:678: IMAP session supports IDLE, using it.'}
DEBUG    root:rpc.py:180 account_id=3 got an event {'kind': 'Info', 'msg': 'src/imap/idle.rs:65: INBOX: Idle entering wait-on-remote state'}
DEBUG    root:rpc.py:180 account_id=2 got an event {'kind': 'ConnectivityChanged'}
DEBUG    root:rpc.py:180 account_id=2 got an event {'kind': 'ImapInboxIdle'}
DEBUG    root:rpc.py:180 account_id=2 got an event {'kind': 'Info', 'msg': 'src/scheduler.rs:678: IMAP session supports IDLE, using it.'}
DEBUG    root:rpc.py:180 account_id=2 got an event {'kind': 'Info', 'msg': 'src/imap/idle.rs:65: INBOX: Idle entering wait-on-remote state'}

So it seems account 3 (bob2 I guess) ignored FETCH result that wanted to inform it about new \Seen flag and went IDLE forever.

So exactly when we were syncing Seen flags, a new Seen flag was set but we ignored it here: https://github.com/deltachat/deltachat-core-rust/blob/aa71fbe04c17a89b0af8441d330e81304df9123d/src/imap.rs#L1207-L1208

We should probably just set new_mail flag to skip IDLE in this case, FETCH without UID means there are new flags. Can also check if there is a \Seen flag in this FETCH response.

Also server_sent_unsolicited_exists should look for FETCH that indicate new Seen flags to skip IDLE in this case.

link2xt avatar Oct 21 '24 14:10 link2xt