From 17914d94f5fff8d01ee6a816daa253e761afcc17 Mon Sep 17 00:00:00 2001 From: arclayto Date: Tue, 3 Mar 2026 23:02:41 -0600 Subject: [PATCH] fix: sort email batches by date instead of UID (#231) UID ordering is not reliable for all IMAP servers (e.g. Proton Bridge), causing emails to display oldest-first. Sort by Date instead, consistent with the Date-based sorting already used elsewhere in the codebase. Fixes #230 --- fetcher/fetcher.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fetcher/fetcher.go b/fetcher/fetcher.go index 49097f8ef5538efcb3f30c6e0a9d394bf466a4ec..35fd10373da0350c9f02d7191ff248feb90fcf6b 100644 --- a/fetcher/fetcher.go +++ b/fetcher/fetcher.go @@ -307,14 +307,11 @@ func FetchMailboxEmails(account *config.Account, mailbox string, limit, offset u }) } - // Sort batch Newest -> Oldest (since IMAP usually returns Oldest->Newest or arbitrary) - // Assuming seqset order or standard behavior, we want to ensure we append Newest emails first - // so that the final list is correct. - // Actually, let's just sort the batch by UID desc (Newest first) - // Simple bubble sort for small batch + // Sort batch by Date descending (newest first) + // UID ordering is not reliable for all IMAP servers (e.g. Proton Bridge) for i := 0; i < len(batchEmails); i++ { for j := i + 1; j < len(batchEmails); j++ { - if batchEmails[j].UID > batchEmails[i].UID { + if batchEmails[j].Date.After(batchEmails[i].Date) { batchEmails[i], batchEmails[j] = batchEmails[j], batchEmails[i] } }