fix(imap): persist vanished messages immediately on EXAMINE commands
Problem
When QRESYNC is used the server will report all changed and vanished messages right away on each EXAMINE command. This is a bandwith optimization for IMAP. However, our code doesn't expect any (sync) changes to happen outside of explicit sync runs so we miss those changes when they are caught on arbitrary IMAP commands (not syncs).
To solve this, Horde authors came up with a "cache" that will be notified if unsolicited changes are received. However, our Horde cache class stays in memory and doesn't actually reconcile changes with the main db cache which is the source of truth.
This can lead to situations were Horde informs us of vanished messages that we delete from the memory cache but don't actually propagate to the db. Because Horde already notified us of this change, it won't necessarily inform us again, when an explicit sync for vanished messages is performed.
Solution
- Propagate delete uids to the db cache.
- Use the db cache as a source of truth for determining which UIDs are actually cached/known by the client. This is done lazily to reduce the performance impact.