avoid accidental complete delete.

This commit is contained in:
Thomas Güttler
2026-04-24 07:15:15 +02:00
parent fb805201a9
commit aa8d59453b
2 changed files with 21 additions and 1 deletions
+8
View File
@@ -1,5 +1,13 @@
# Later
---
docs
---
Thread view (group by `References` / `In-Reply-To`)
---
@@ -458,7 +458,6 @@ class EmailRepositoryImpl implements EmailRepository {
String mailboxPath,
List<int> 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();