diff --git a/backend/server/api/mail/scan-internal.post.ts b/backend/server/api/mail/scan-internal.post.ts index c49ed9c..4f64815 100644 --- a/backend/server/api/mail/scan-internal.post.ts +++ b/backend/server/api/mail/scan-internal.post.ts @@ -197,13 +197,18 @@ export default defineEventHandler(async (event) => { let allMessages: any[]; if (lastUid > 0) { - // Inkrementell: nur UIDs > lastUid suchen - const newUids = await (imap as any).search({ uid: `${lastUid + 1}:*` }); + // Inkrementell: nur UIDs > lastUid suchen. + // WICHTIG: { uid: true } als zweites Argument ist Pflicht! + // Ohne es sendet ImapFlow "SEARCH UID X:*" statt "UID SEARCH UID X:*" + // → Server antwortet mit Sequence Numbers statt UIDs. + // fetchAll(..., { uid: true }) würde die Seq-Nums als UIDs interpretieren + // → fetcht falsche (alte) Mails → neue Mail wird übersehen. + const newUids = await (imap as any).search({ uid: `${lastUid + 1}:*` }, { uid: true }); if (!newUids || newUids.length === 0) { // Keine neuen Nachrichten → Ordner skippen, kein fetchAll nötig continue; } - // Fetch nur die neuen UIDs + // Fetch nur die neuen UIDs — newUids enthält jetzt echte UIDs allMessages = await imap.fetchAll(newUids.join(","), { envelope: true }, { uid: true } as any); } else { // Full-Sweep (erster Scan, UIDVALIDITY-Reset, oder Quality-Full-Sweep):