From aa8d59453b8f562d35681a705761ad836a149ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCttler?= Date: Fri, 24 Apr 2026 07:15:15 +0200 Subject: [PATCH] avoid accidental complete delete. --- LATER.md | 8 ++++++++ lib/data/repositories/email_repository_impl.dart | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/LATER.md b/LATER.md index 67bc966..aa01d4f 100644 --- a/LATER.md +++ b/LATER.md @@ -1,5 +1,13 @@ # Later + +--- + + +docs + +--- + Thread view (group by `References` / `In-Reply-To`) --- diff --git a/lib/data/repositories/email_repository_impl.dart b/lib/data/repositories/email_repository_impl.dart index 9f2107d..8c980c8 100644 --- a/lib/data/repositories/email_repository_impl.dart +++ b/lib/data/repositories/email_repository_impl.dart @@ -458,7 +458,6 @@ class EmailRepositoryImpl implements EmailRepository { String mailboxPath, List serverUids, ) async { - final serverUidSet = serverUids.toSet(); final localRows = await (_db.select(_db.emails) ..where( (t) => @@ -466,6 +465,19 @@ class EmailRepositoryImpl implements EmailRepository { t.mailboxPath.equals(mailboxPath), )) .get(); + + // Guard: if the server returned no UIDs but we have local emails, the + // server response is likely incomplete (network glitch, buggy IMAP server). + // Skip reconciliation to avoid wiping the local cache unnecessarily. + if (serverUids.isEmpty && localRows.isNotEmpty) { + log( + '_reconcileDeletedImap: skipping — server returned 0 UIDs for ' + '$mailboxPath but local DB has ${localRows.length} emails', + ); + return; + } + + final serverUidSet = serverUids.toSet(); for (final row in localRows) { if (!serverUidSet.contains(row.uid)) { await (_db.delete(_db.emails)..where((t) => t.id.equals(row.id))).go();