Skip to content

Add manual sync API and bichonsync CLI#158

Open
azure9 wants to merge 4 commits intorustmailer:mainfrom
azure9:syncapi
Open

Add manual sync API and bichonsync CLI#158
azure9 wants to merge 4 commits intorustmailer:mainfrom
azure9:syncapi

Conversation

@azure9
Copy link
Copy Markdown

@azure9 azure9 commented Feb 13, 2026

Summary

  • Add a new sync module with REST API endpoints for on-demand IMAP sync, single-folder gap-aware sync, mailbox status inspection, sync verification, and raw EML fetching
  • Add bichonsync CLI binary for manual sync controls against the Bichon API
  • Extend EnvelopeIndexManager and EmlIndexManager with flush(), count_messages_in_mailbox(), and get_all_uids() methods

New API Endpoints

Method Path Description
POST /api/v1/sync/:account_id Trigger on-demand full sync for an IMAP account
POST /api/v1/sync/:account_id/:mailbox_id Gap-aware single folder sync (compares all server UIDs vs local, fetches missing)
GET /api/v1/sync/mailbox-status/:account_id Offline mailbox status with server vs local message counts
GET /api/v1/sync/verify/:account_id Verify sync completeness against the IMAP server (detects missing folders and messages)
POST /api/v1/sync/:account_id/:mailbox_id/fetch-eml Fetch raw EML content for specific UIDs from IMAP (base64 encoded, without storing)

bichonsync CLI Commands

Command Description
list-accounts List all accounts
list-mailboxes -a <id> List mailboxes with server/local counts and sync status
sync -a <id> Trigger full account sync
sync-folder -a <id> -m <id> [--export-dupes] Sync single folder; optionally export missing/duplicate messages as .eml files
verify -a <id> Verify sync completeness (remote vs local)

Key Implementation Details

  • Gap-aware sync: perform_single_folder_sync compares the full set of server UIDs against local UIDs (via new get_all_uids()), fetching only the delta — unlike perform_incremental_sync which only looks at UIDs above the local max
  • Index flush: Added a Flush variant to WriteMessage with a oneshot channel to synchronously commit pending writes, ensuring accurate counts immediately after sync
  • EML export: The --export-dupes flag on sync-folder fetches raw email bodies via IMAP BODY.PEEK[] and saves them to a temp directory, useful for debugging duplicate/missing messages
  • RFC 2047 decoding: Included a decode_rfc2047 helper for readable subject lines in the missing-messages report

Files Changed

File Change
Cargo.toml Register bichonsync binary
src/bin/bichonsync.rs New — CLI tool (539 lines)
src/modules/sync/mod.rs New — Sync service logic (486 lines)
src/modules/rest/api/sync.rs New — API endpoints (139 lines)
src/modules/rest/api/mod.rs Register SyncApi tag and endpoints
src/modules/indexer/manager.rs Add flush(), count_messages_in_mailbox(), get_all_uids(), Flush message variant
src/modules/cache/imap/sync/flow.rs Make perform_incremental_sync public
src/modules/mod.rs Add pub mod sync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant