Anthony 34127f7587 Event-driven realtime delta: skip the full folder re-sync on a MOVE
The bridge no longer asks the server for a full folder listing on every
MailSetEntry CREATE/DELETE event. Instead it uses the encoding of the
entry id (4-byte timestamp + 9-byte Mail element id, see
`tuta-sdk::mail_set_entry_id`) to recover the affected mail directly,
and applies the delta to MailStore + LocalStore:

- MailSetEntry CREATE first (so a MOVE clones from the source folder
  before the matching DELETE runs). Hit path = `find_mail_anywhere` →
  clone the already-decrypted StoredMail into the target folder with a
  fresh UID. Miss path = a single `load_mail` against the cached
  `Mail.list_id`. Any decode failure / unknown folder / `load_mail`
  error queues a fallback full `sync_folder` for that folder — no
  silent miss.
- MailSetEntry DELETE second. Removes from the source folder only; the
  `.eml` and DB row are dropped only if no folder still holds the mail
  (multi-folder placement preserved, in-batch MOVE is correct because
  the target was upserted by the CREATE loop).
- Mail UPDATE / DELETE unchanged.
- MailSet folder-list dirty handling unchanged.

Saves the `load_range(1000)` round-trip on the common MOVE case. The
fallback path keeps the previous behaviour available so the change is
strictly an optimisation, not a behavioural change.

New MailStore helpers (5 new tests):
- `find_mail_anywhere(eid)` / `is_mail_anywhere(eid)` — multi-folder
  lookup.
- `remove_mail_from_folder(folder_id, eid)` — scoped remove (vs the
  existing `remove_mail_everywhere`).
- `upsert_mail_in_folder` — idempotent insert/replace by element_id.
- `mail_list_id()` — sniff once, cache; needed by the load_mail miss
  path.

`mail_to_metadata` made `pub(crate)` for the handler.

Bucketing in the event handler also split into `mail_set_entry_creates`
vs `mail_set_entry_deletes` so the order is explicit; 8 handler tests
cover empty / mixed / order-preserved / immutable-UPDATE-ignored shapes.

166/166 bridge lib tests pass.
2026-05-28 14:32:36 +02:00
Languages
Rust 89.5%
TypeScript 5.9%
CSS 2.5%
Python 1.2%
Shell 0.7%
Other 0.1%