[BUG] Incremental sync warns "no stored highest_uid" on every round for folders with no new mail

Open Beginner friendly
#411 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

The bug is in crates/core/src/archive/imap/download/flow.rs. Start at the incremental branch that logs "no stored highest_uid" (around line 1293, where get_max_uid is called) and at the reconcile step (around line 1108) that keeps None. Done means that when no new mail is fetched, the max UID found by get_max_uid is persisted, so the warning no longer repeats on the next round.

Written by the indexing model from the issue text.

Description

bug
Version

2.3.2 (Docker rustmailer/bichon:2.3.2)

Steps to Reproduce
  1. Use an IMAP account (Gmail here) whose folders were archived by an older version, before highest_uid was stored for each mailbox.
  2. Upgrade to 2.3.2 and let the periodic incremental sync run.
  3. Watch the log for a folder that gets no new mail, such as a rarely used label.
Issue Description

Every sync round logs a warning for each of those folders, and it never stops: about 375 warnings an hour across around 30 folders for me. Folders that do get new mail save a highest_uid and stop warning. Archiving still works: the fallback finds the right start UID.

What I think causes it: in crates/core/src/archive/imap/download/flow.rs, when local_mailbox.highest_uid is None, the incremental path takes the start UID from ENVELOPE_MANAGER.get_max_uid(...) (around line 1293). But the function returns Ok(new_max_uid.or(local_mailbox.highest_uid)). With no new mail, both are None, so it returns None. Reconcile keeps None (new_highest_uid.or(local_mailbox.highest_uid), around line 1108), so the next round takes the fallback again.

Suggested fix: when no new mail is fetched, return the max UID that get_max_uid found, e.g. new_max_uid.or(local_mailbox.highest_uid).or(local_max_uid). Reconcile then saves it once, and both the warning and the repeated index query stop.

Screenshots or Logs (optional)

One round for an affected folder (account and mailbox names shortened):

WARN  bichon_core::archive::imap::download::flow: incremental: no stored highest_uid, falling back to Tantivy get_max_uid account_id=… mailbox=…
INFO  bichon_core::imap::executor: [account …][mailbox …] fetch_new_mail: enumerate UIDs via UID FETCH 13329:*
INFO  bichon_core::imap::executor: fetch_new_mail_range: UID FETCH result account_id=… mailbox=… start_uid=13329 found=0 skipped_oversized=0
INFO  bichon_core::archive::imap::download::flow: reconcile: computed highest_uid for mailbox account_id=… mailbox=…
INFO  bichon_core::archive::imap::download::flow: reconcile: persisting mailbox state account_id=… mailbox=…

For comparison, a folder that does have a stored value:

INFO  bichon_core::archive::imap::download::flow: reconcile: computed highest_uid for mailbox account_id=… mailbox=[Gmail]/Sent Mail local_highest=3447 new_highest=3447
INFO  bichon_core::archive::imap::download::flow: reconcile: persisting mailbox state account_id=… mailbox=[Gmail]/Sent Mail highest_uid=3447

In the real log the mailbox names are your email addresses, so I replaced them with …. Keep them that way when you post. The line numbers are from upstream main as of this morning; if someone has changed flow.rs since, adjust them.

Dominant language
Rust
Stars
2.1k
Forks
91
Avg merge
14h 54m
Merged PRs (30d)
6

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rustmailer/bichon

All issues in rustmailer/bichon

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.