From ace103c617ea7b257370afe74d5c44a8a49c142e Mon Sep 17 00:00:00 2001 From: Daniel Lerch <36048059+daniel-lerch@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:30:29 +0200 Subject: [PATCH 1/2] Fix outbox email pipeline stall due to empty recipient address --- .../EmailDelivery/EmailDeliveryJobController.cs | 12 ++++++++++-- .../EmailDelivery/EmailDeliveryService.cs | 3 +++ .../EmailRelay/DistributionListService.cs | 6 ++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/server/src/Korga.Server/EmailDelivery/EmailDeliveryJobController.cs b/server/src/Korga.Server/EmailDelivery/EmailDeliveryJobController.cs index 78e55c3..e409a20 100644 --- a/server/src/Korga.Server/EmailDelivery/EmailDeliveryJobController.cs +++ b/server/src/Korga.Server/EmailDelivery/EmailDeliveryJobController.cs @@ -56,8 +56,16 @@ protected override async ValueTask ExecuteJob(OutboxEmail outboxEmail, Cancellat // Don't cancel this operation because messages would sent twice otherwise await database.SaveChangesAsync(CancellationToken.None); - logger.LogInformation("Delivered email #{Id} to {EmailAddress}", - outboxEmail.Id, outboxEmail.EmailAddress); + + if (outboxEmail.InboxEmailId.HasValue) + { + logger.LogInformation("Delivered inbox email #{InboxEmailId} as #{Id} to {EmailAddress}", + outboxEmail.InboxEmailId, outboxEmail.Id, outboxEmail.EmailAddress); + } + else + { + logger.LogInformation("Delivered system email #{Id} to {EmailAddress}", outboxEmail.Id, outboxEmail.EmailAddress); + } } catch (SmtpCommandException ex) when (ex.StatusCode == SmtpStatusCode.MailboxBusy) { diff --git a/server/src/Korga.Server/EmailDelivery/EmailDeliveryService.cs b/server/src/Korga.Server/EmailDelivery/EmailDeliveryService.cs index 4a57f0d..049956f 100644 --- a/server/src/Korga.Server/EmailDelivery/EmailDeliveryService.cs +++ b/server/src/Korga.Server/EmailDelivery/EmailDeliveryService.cs @@ -1,6 +1,7 @@ using Korga.Server.Utilities; using Microsoft.EntityFrameworkCore; using MimeKit; +using System; using System.IO; using System.Threading; using System.Threading.Tasks; @@ -20,6 +21,8 @@ public EmailDeliveryService(DatabaseContext database, JobQueue Enqueue(string emailAddress, MimeMessage mimeMessage, long? inboxEmailId, CancellationToken cancellationToken) { + if (string.IsNullOrEmpty(emailAddress)) throw new ArgumentException("The recipient address must not be null or empty", nameof(emailAddress)); + if (inboxEmailId.HasValue && await database.OutboxEmails .AnyAsync(email => email.EmailAddress == emailAddress && email.InboxEmailId == inboxEmailId, cancellationToken)) return false; diff --git a/server/src/Korga.Server/EmailRelay/DistributionListService.cs b/server/src/Korga.Server/EmailRelay/DistributionListService.cs index 536a4c6..1511792 100644 --- a/server/src/Korga.Server/EmailRelay/DistributionListService.cs +++ b/server/src/Korga.Server/EmailRelay/DistributionListService.cs @@ -44,6 +44,7 @@ public async ValueTask> GetPeople(DistributionList distribut await database.GroupMembers .Where(m => m.GroupId == groupFilter.GroupId && (groupFilter.GroupRoleId == null || m.GroupRoleId == groupFilter.GroupRoleId)) .Join(database.People, m => m.PersonId, p => p.Id, (m, p) => p) + .Where(p => !string.IsNullOrEmpty(p.Email)) .ToListAsync(cancellationToken)); } else if (personFilter is StatusFilter statusFilter) @@ -55,8 +56,9 @@ await database.People } else if (personFilter is SinglePerson singlePerson) { - people.Add( - await database.People.SingleAsync(p => p.Id == singlePerson.PersonId, cancellationToken)); + people.AddRange( + await database.People.Where(p => p.Id == singlePerson.PersonId && !string.IsNullOrEmpty(p.Email)) + .ToListAsync(cancellationToken)); } } From b7f40a23dc203748cfa201ed7c10915799a95e4c Mon Sep 17 00:00:00 2001 From: Daniel Lerch <36048059+daniel-lerch@users.noreply.github.com> Date: Mon, 25 Sep 2023 22:35:51 +0200 Subject: [PATCH 2/2] Update NuGet packages --- server/src/Korga.Core/Korga.Core.csproj | 2 +- server/src/Korga.Server/Korga.Server.csproj | 12 ++++++------ .../Korga.Server.Tests/Korga.Server.Tests.csproj | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/server/src/Korga.Core/Korga.Core.csproj b/server/src/Korga.Core/Korga.Core.csproj index 1e9b8a2..2d378a4 100644 --- a/server/src/Korga.Core/Korga.Core.csproj +++ b/server/src/Korga.Core/Korga.Core.csproj @@ -7,7 +7,7 @@ - + diff --git a/server/src/Korga.Server/Korga.Server.csproj b/server/src/Korga.Server/Korga.Server.csproj index 7d35fab..10847a8 100644 --- a/server/src/Korga.Server/Korga.Server.csproj +++ b/server/src/Korga.Server/Korga.Server.csproj @@ -7,16 +7,16 @@ - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/server/tests/Korga.Server.Tests/Korga.Server.Tests.csproj b/server/tests/Korga.Server.Tests/Korga.Server.Tests.csproj index 572e7dc..1359d17 100644 --- a/server/tests/Korga.Server.Tests/Korga.Server.Tests.csproj +++ b/server/tests/Korga.Server.Tests/Korga.Server.Tests.csproj @@ -8,14 +8,14 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive