From b07a3b3a87c22bcb192ccc75585841f5a701be60 Mon Sep 17 00:00:00 2001 From: duffyduck Date: Fri, 3 Apr 2026 20:03:51 +0200 Subject: [PATCH] Fix critical delete bug: don't mass-delete on EntryID change Two fixes for delete propagation in Phase 1: 1. When Outlook contact not found by EntryID, try to re-match by name/email/phone before assuming it was deleted. Outlook can change EntryIDs on restart or profile changes, causing the sync to think ALL contacts were deleted. 2. When Starface contact not found in current list, DON'T delete from Outlook. The contact may belong to a different address book. Just drop the mapping and let Phase 2/3 re-link it. These changes make delete propagation much safer and prevent accidental mass-deletion of contacts. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Services/SyncEngine.cs | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/StarfaceOutlookSync/Services/SyncEngine.cs b/src/StarfaceOutlookSync/Services/SyncEngine.cs index 7f49df3d..adcb5285 100644 --- a/src/StarfaceOutlookSync/Services/SyncEngine.cs +++ b/src/StarfaceOutlookSync/Services/SyncEngine.cs @@ -183,7 +183,21 @@ namespace StarfaceOutlookSync.Services if (oc == null && sc != null) { - // In Outlook geloescht -> in Starface auch loeschen + // Outlook-Kontakt nicht gefunden. + // Erst pruefen ob er vielleicht nur eine neue EntryID hat + var reMatch = FindMatch(sc, outlookContacts.Where(c => + !processedOutlookIds.Contains(c.OutlookEntryId)).ToList()); + if (reMatch != null) + { + // Kontakt existiert noch in Outlook, nur EntryID geaendert + Log($" EntryID geaendert, verknuepfe neu: {sc.DisplayName}"); + mapping.OutlookEntryId = reMatch.OutlookEntryId; + processedOutlookIds.Add(reMatch.OutlookEntryId); + newMappings.Add(mapping); + continue; + } + + // Wirklich geloescht -> in Starface auch loeschen if (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.OutlookToStarface) { if (await starface.DeleteContactAsync(mapping.StarfaceId)) @@ -194,7 +208,6 @@ namespace StarfaceOutlookSync.Services } else { - // Richtung erlaubt kein Loeschen -> Mapping behalten newMappings.Add(mapping); } continue; @@ -202,20 +215,12 @@ namespace StarfaceOutlookSync.Services if (oc != null && sc == null) { - // In Starface geloescht -> in Outlook auch loeschen - if (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.StarfaceToOutlook) - { - if (_outlookService.DeleteContact(mapping.OutlookEntryId)) - { - result.Updated++; - Log($" Geloescht (SF->OL): {oc.DisplayName}"); - } - } - else - { - // Richtung erlaubt kein Loeschen -> Mapping behalten - newMappings.Add(mapping); - } + // Starface-Kontakt nicht gefunden. + // Kann passieren wenn der Kontakt einem anderen Adressbuch gehoert. + // NICHT loeschen, nur Mapping entfernen - wird in Phase 2/3 neu verknuepft + Log($" Starface-Kontakt nicht in Liste (anderes Adressbuch?): {oc.DisplayName}"); + // Mapping verwerfen, Outlook-Kontakt als unverarbeitet belassen + // damit er in Phase 2 neu zugeordnet oder erstellt werden kann continue; }