Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix outbox email pipeline stall due to empty recipient address #38

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/src/Korga.Core/Korga.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.11" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions server/src/Korga.Server/EmailDelivery/EmailDeliveryService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,6 +21,8 @@ public EmailDeliveryService(DatabaseContext database, JobQueue<EmailDeliveryJobC

public async ValueTask<bool> 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;
Expand Down
6 changes: 4 additions & 2 deletions server/src/Korga.Server/EmailRelay/DistributionListService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public async ValueTask<IEnumerable<Person>> 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)
Expand All @@ -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));
}
}

Expand Down
12 changes: 6 additions & 6 deletions server/src/Korga.Server/Korga.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MailKit" Version="4.1.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" />
<PackageReference Include="McMaster.Extensions.Hosting.CommandLine" Version="4.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
<PackageReference Include="MailKit" Version="4.2.0" />
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.1.0" />
<PackageReference Include="McMaster.Extensions.Hosting.CommandLine" Version="4.1.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="NSwag.AspNetCore" Version="13.19.0" />
<PackageReference Include="NSwag.AspNetCore" Version="13.20.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
<PackageReference Include="System.DirectoryServices.Protocols" Version="7.0.1" />
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions server/tests/Korga.Server.Tests/Korga.Server.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.11" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down