IMAP: track the connection state properly when synchronizing mailboxes

This fixes a status message in the GUI about "syncing mailbox" which previously
wouldn't go away. Thanks to "serpentine" on IRC for reminding me.