Skip to content

Commit

Permalink
Merge branch 'master' into dev-proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lerch committed Jul 1, 2024
2 parents 6326715 + 6c8e318 commit 7787398
Show file tree
Hide file tree
Showing 35 changed files with 2,519 additions and 11,939 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,5 @@ During development the frontend running on the Vue CLI development server will u
That means the backend can be running in Visual Studio with Debugger attached.

If you just want to work on the frontend you can also use a public test server by creating a file `webapp/.env.development.local`
to override the defaults with `VUE_APP_API_URL=https://lerchen.net/korga`.
to override the defaults with `VITE_API_URL=https://lerchen.net/korga`.
Then you don't have to setup a database server and the ASP.NET Core backend.
2 changes: 1 addition & 1 deletion server/Korga.Tests/Http/VueSpaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public async Task TestVueEntrypoint(string pathbase, string url)
Assert.Equal("text/html", response.Content.Headers.ContentType?.MediaType);
string body = await response.Content.ReadAsStringAsync();
Assert.True(body.StartsWith("<!DOCTYPE html>"), "Body is missing DOCTYPE");
Assert.True(body.Contains($"window.resourceBasePath = '{pathbase}/'"), "Body is missing pathbase");
Assert.True(body.Contains($"window.basePath = '{pathbase}/'"), "Body is missing pathbase");
}
}
6 changes: 2 additions & 4 deletions server/Korga/EmailDelivery/EmailDeliveryJobController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ protected override async ValueTask ExecuteJob(OutboxEmail outboxEmail, Cancellat
{
SmtpClient smtp = await GetConnection(cancellationToken);

MimeMessage mimeMessage;

using (MemoryStream memoryStream = new(outboxEmail.Content))
mimeMessage = MimeMessage.Load(memoryStream, CancellationToken.None);
using MemoryStream memoryStream = new(outboxEmail.Content);
using MimeMessage mimeMessage = MimeMessage.Load(memoryStream, CancellationToken.None);

try
{
Expand Down
11 changes: 9 additions & 2 deletions server/Korga/EmailDelivery/EmailDeliveryService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Korga.Utilities;
using Korga.EmailDelivery.Entities;
using Korga.Utilities;
using Microsoft.EntityFrameworkCore;
using MimeKit;
using System;
Expand Down Expand Up @@ -35,8 +36,14 @@ public async ValueTask<bool> Enqueue(string emailAddress, MimeMessage mimeMessag
content = memoryStream.ToArray();
}

database.OutboxEmails.Add(new(emailAddress, content) { InboxEmailId = inboxEmailId });
OutboxEmail outboxEmail = new(emailAddress, content) { InboxEmailId = inboxEmailId };
database.OutboxEmails.Add(outboxEmail);
await database.SaveChangesAsync(cancellationToken);

// Explicitly free entity for garbage collection because our DbContext won't be disposed soon enough
// Without this line, Korga takes gigabytes of memory when sending large messages to many recipients
database.Entry(outboxEmail).State = EntityState.Detached;

jobQueue.EnsureRunning();
return true;
}
Expand Down
14 changes: 9 additions & 5 deletions server/Korga/EmailRelay/EmailRelayJobController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ protected override async ValueTask ExecuteJob(InboxEmail email, CancellationToke
{
if (email.Receiver == null)
{
await SendErrorMessage(email, emailRelay.InvalidServerConfiguration(email), cancellationToken);
using MimeMessage? errorMessage = emailRelay.InvalidServerConfiguration(email);
await SendErrorMessage(email, errorMessage, cancellationToken);

logger.LogWarning("Could not determine receiver for message #{Id} from {From} to {To}. This message will not be forwarded." +
"Please make sure your email provider specifies the receiver in the Received, Envelope-To, or X-Envelope-To header", email.Id, email.From, email.To);
Expand All @@ -54,23 +55,26 @@ protected override async ValueTask ExecuteJob(InboxEmail email, CancellationToke

if (distributionList == null)
{
await SendErrorMessage(email, emailRelay.InvalidAlias(email), cancellationToken);
using MimeMessage? errorMessage = emailRelay.InvalidAlias(email);
await SendErrorMessage(email, errorMessage, cancellationToken);

logger.LogInformation("No group found with alias {Receiver} for email #{Id} from {From}", email.Receiver, email.Id, email.From);
return;
}

if (email.Header == null)
{
await SendErrorMessage(email, emailRelay.TooManyHeaders(email), cancellationToken);
using MimeMessage? errorMessage = emailRelay.TooManyHeaders(email);
await SendErrorMessage(email, errorMessage, cancellationToken);

logger.LogInformation("Email #{Id} from {From} to {Receiver} exceeded the header size limit", email.Id, email.From, email.Receiver);
return;
}

if (email.Body == null)
{
await SendErrorMessage(email, emailRelay.TooBigMessage(email), cancellationToken);
using MimeMessage? errorMessage = emailRelay.TooBigMessage(email);
await SendErrorMessage(email, errorMessage, cancellationToken);

logger.LogInformation("Email #{Id} from {From} to {Receiver} exceeded the body size limit", email.Id, email.From, email.Receiver);
return;
Expand All @@ -79,7 +83,7 @@ protected override async ValueTask ExecuteJob(InboxEmail email, CancellationToke
MailboxAddress[] recipients = await distributionListService.GetRecipients(distributionList, cancellationToken);
foreach (MailboxAddress address in recipients)
{
MimeMessage preparedMessage = distributionList.Flags.HasFlag(DistributionListFlags.Newsletter)
using MimeMessage preparedMessage = distributionList.Flags.HasFlag(DistributionListFlags.Newsletter)
? await emailRelay.PrepareForForwardTo(email, address, cancellationToken)
: emailRelay.PrepareForResentTo(email, address);
await emailDelivery.Enqueue(address.Address, preparedMessage, email.Id, cancellationToken);
Expand Down
16 changes: 2 additions & 14 deletions server/Korga/Utilities/VueSpaFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,8 @@ public IFileInfo GetFileInfo(string subpath)

private MemoryFileInfo CreateCache(DateTime lastWrite, string? pathBase)
{
byte[] buffer;

if (string.IsNullOrEmpty(pathBase))
{
buffer = File.ReadAllBytes(path);
}
else
{
buffer = Encoding.UTF8.GetBytes(
File.ReadAllText(path)
.Replace("\"/", $"\"{pathBase}/")
.Replace("'/'", $"'{pathBase}/'")
);
}
byte[] buffer = Encoding.UTF8.GetBytes(
File.ReadAllText(path).Replace("/__base_path__/", $"{pathBase}/"));

return new MemoryFileInfo("index.html", buffer, lastWrite, pathBase);
}
Expand Down
2 changes: 1 addition & 1 deletion server/Korga/appsettings.Development.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"Hosting": {
"CorsOrigins": [
"http://localhost:8080"
"http://localhost:5173"
]
},
"Logging": {
Expand Down
2 changes: 1 addition & 1 deletion server/Korga/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h1>Korga Backend</h1>
</p>
</main>
<script>
window.resourceBasePath = '/'
window.basePath = '/__base_path__/'
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion webapp/.env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VUE_APP_API_URL=http://localhost:10501
VITE_API_URL=http://localhost:10501
17 changes: 5 additions & 12 deletions webapp/.eslintrc.js → webapp/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
/* eslint-env node */
require("@rushstack/eslint-patch/modern-module-resolution")

module.exports = {
root: true,
env: {
node: true,
},
extends: [
"plugin:vue/vue3-essential",
"eslint:recommended",
"@vue/typescript/recommended",
"plugin:prettier/recommended",
],
parserOptions: {
ecmaVersion: 2020,
ecmaVersion: "latest",
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
"vue/multi-word-component-names": ["warn"],
"prettier/prettier": [
"error",
{
endOfLine: "auto",
trailingComma: "es5",
},
],
},
};
}
8 changes: 8 additions & 0 deletions webapp/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"endOfLine": "auto",
"semi": false,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5"
}
1 change: 1 addition & 0 deletions webapp/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
9 changes: 4 additions & 5 deletions webapp/public/index.html → webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#223859">
<link rel="icon" href="/favicon.ico">
<link rel="icon" type="image/png" href="/brand.png">
<title>Korga</title>
</head>

Expand All @@ -17,9 +16,9 @@
</noscript>
<div id="app"></div>
<script>
window.resourceBasePath = '/'
window.basePath = '/__base_path__/'
</script>
<!-- built files will be auto injected -->
<script type="module" src="/src/main.ts"></script>
</body>

</html>
Loading

0 comments on commit 7787398

Please sign in to comment.