From 6e1dd172676e398c4cf4ff70a06b35b18ee63d04 Mon Sep 17 00:00:00 2001 From: Axel Dunkel Date: Sat, 16 Aug 2025 08:43:09 +0000 Subject: [PATCH 1/2] Fix IMAP sync marking all emails as synced before fetching Initialize newMaxUids with lastUid instead of mailbox maximum to prevent marking unfetched emails as synced. The bug sets newMaxUids to the highest UID before fetching, causing all existing emails to be skipped when sync state is saved early. Fixes #45 --- .../src/services/ingestion-connectors/ImapConnector.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/services/ingestion-connectors/ImapConnector.ts b/packages/backend/src/services/ingestion-connectors/ImapConnector.ts index 3c3649e..ed9cead 100644 --- a/packages/backend/src/services/ingestion-connectors/ImapConnector.ts +++ b/packages/backend/src/services/ingestion-connectors/ImapConnector.ts @@ -189,7 +189,10 @@ export class ImapConnector implements IEmailConnector { currentMaxUid = lastMessage.uid; } } - this.newMaxUids[mailboxPath] = currentMaxUid; + + // Initialize with last synced UID, not the maximum UID in mailbox + this.newMaxUids[mailboxPath] = lastUid || 0; + // Only fetch if the mailbox has messages, to avoid errors on empty mailboxes with some IMAP servers. if (mailbox.exists > 0) { From c05b3b92d94d4529aa655e981b51861b67a128a1 Mon Sep 17 00:00:00 2001 From: Axel Dunkel Date: Sun, 17 Aug 2025 11:34:21 +0000 Subject: [PATCH 2/2] fix the indentation, to use tabs not spaces --- .../src/services/ingestion-connectors/ImapConnector.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/services/ingestion-connectors/ImapConnector.ts b/packages/backend/src/services/ingestion-connectors/ImapConnector.ts index ed9cead..46cfed9 100644 --- a/packages/backend/src/services/ingestion-connectors/ImapConnector.ts +++ b/packages/backend/src/services/ingestion-connectors/ImapConnector.ts @@ -190,8 +190,8 @@ export class ImapConnector implements IEmailConnector { } } - // Initialize with last synced UID, not the maximum UID in mailbox - this.newMaxUids[mailboxPath] = lastUid || 0; + // Initialize with last synced UID, not the maximum UID in mailbox + this.newMaxUids[mailboxPath] = lastUid || 0; // Only fetch if the mailbox has messages, to avoid errors on empty mailboxes with some IMAP servers.