[BUG] Incremental sync creates duplicate entries of the most recent email on every interval (Inclusive IMAP UID Fetch)

Open
#273 21 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
rust
Domain
backend, databases

Research direction

Start by tracing the incremental IMAP sync path and how it records the latest UID; the issue does not name files or tests. Reproduce with an unchanged mailbox and inspect whether the highest UID is fetched and indexed again on each sync. Done means repeated syncs without new mail create no duplicate entries, while new messages are still imported.

Written by the indexing model from the issue text.

Description

bug
Version

latest Docker image (rustmailer/bichon:latest)

Steps to Reproduce
  1. Configure an IMAP account in the Bichon Web GUI (reproduced both with a local Dovecot IMAP instance and directly via a remote Posteo IMAP mailbox).
  2. Allow the initial sync to complete fully (e.g., indexing ~4000 emails).
  3. Wait for the automatic background sync interval to trigger (or trigger a manual check) when no new emails have arrived on the server.
  4. Check the folders (e.g., Inbox or Sent) in the Bichon web interface.
Issue Description

Bichon creates duplicate entries of the exact same email—specifically the single most recent email (the highest UID) in every single folder—on every subsequent sync interval. For example, after 7 background sync cycles, the exact same sent email appears 7 identical times in the GUI.

Suspected Root Cause:
This appears to be an inclusive bounds issue ("off-by-one" logic error) during incremental IMAP fetching. When Bichon queries the server for new changes since the last sync, it likely requests a range like UID FETCH <Latest_Known_UID>:*.

According to the IMAP RFC, this range is inclusive. If no actual new emails exist on the server, the server faithfully returns the message that matches <Latest_Known_UID> again. Because Bichon does not seem to filter this out or increment the query cursor to <Latest_Known_UID> + 1 (i.e., UID FETCH <Latest_Known_UID+1>:*), it treats the returned message as a brand-new email and re-indexes it into the database on every single run.

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.