From 86ef78b296dab0a826a0d9896cbf4c7df42c2ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Burak=20Kaan=20K=C3=B6se?= Date: Fri, 30 Aug 2024 01:03:35 +0200 Subject: [PATCH] Fixed invalid contacts causing folder loading to crash. --- Wino.Core/Services/MailService.cs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Wino.Core/Services/MailService.cs b/Wino.Core/Services/MailService.cs index 5cea1088..5a9e9123 100644 --- a/Wino.Core/Services/MailService.cs +++ b/Wino.Core/Services/MailService.cs @@ -298,7 +298,11 @@ namespace Wino.Core.Services } } - bool isContactCached = contactCache.TryGetValue(mailCopy.FromAddress, out AccountContact contactAssignment); + AccountContact contactAssignment = null; + + bool isContactCached = !string.IsNullOrEmpty(mailCopy.FromAddress) ? + contactCache.TryGetValue(mailCopy.FromAddress, out contactAssignment) : + false; if (!isContactCached && accountAssignment != null) { @@ -312,11 +316,33 @@ namespace Wino.Core.Services mailCopy.AssignedFolder = folderAssignment; mailCopy.AssignedAccount = accountAssignment; - mailCopy.SenderContact = contactAssignment ?? new AccountContact() { Name = mailCopy.FromName, Address = mailCopy.FromAddress }; + mailCopy.SenderContact = contactAssignment ?? CreateUnknownContact(mailCopy.FromName, mailCopy.FromAddress); } } } + private AccountContact CreateUnknownContact(string fromName, string fromAddress) + { + if (string.IsNullOrEmpty(fromName) && string.IsNullOrEmpty(fromAddress)) + { + return new AccountContact() + { + Name = Translator.UnknownSender, + Address = Translator.UnknownAddress + }; + } + else + { + if (string.IsNullOrEmpty(fromName)) fromName = fromAddress; + + return new AccountContact() + { + Name = fromName, + Address = fromAddress + }; + } + } + private async Task> GetMailItemsAsync(string mailCopyId) { var mailCopies = await Connection.Table().Where(a => a.Id == mailCopyId).ToListAsync();