Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Fix accented characters being stripped from email previews (#2154)
Leendert de Borst0cde2ad49f41
diff --git a/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs b/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.csindex dfd2fda6e..8e30d0159 100644--- a/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs+++ b/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs@@ -198,8 +198,8 @@ public class DatabaseMessageStore(ILogger<DatabaseMessageStore> logger, Config c// Remove all "-" or "=" characters if there are 3 or more in a rowplainToPlainText = Regex.Replace(plainToPlainText, @"-{3,}|\={3,}", string.Empty, RegexOptions.NonBacktracking);- // Remove any non-printable characters- plainToPlainText = Regex.Replace(plainToPlainText, @"[^\u0020-\u007E]", string.Empty, RegexOptions.NonBacktracking);+ // Remove control characters while preserving printable Unicode such as accented letters and emoji.+ plainToPlainText = Regex.Replace(plainToPlainText, @"\p{Cc}", string.Empty, RegexOptions.NonBacktracking);// Replace multiple spaces with a single spaceplainToPlainText = Regex.Replace(plainToPlainText, @"\s+", " ", RegexOptions.NonBacktracking);@@ -224,8 +224,8 @@ public class DatabaseMessageStore(ILogger<DatabaseMessageStore> logger, Config c// Remove all "-" or "=" characters if there are 3 or more in a rowhtmlToPlainText = Regex.Replace(htmlToPlainText, @"-{3,}|\={3,}", string.Empty, RegexOptions.NonBacktracking);- // Remove any non-printable characters- htmlToPlainText = Regex.Replace(htmlToPlainText, @"[^\u0020-\u007E]", string.Empty, RegexOptions.NonBacktracking);+ // Remove control characters while preserving printable Unicode such as accented letters and emoji.+ htmlToPlainText = Regex.Replace(htmlToPlainText, @"\p{Cc}", string.Empty, RegexOptions.NonBacktracking);// Replace multiple spaces with a single spacehtmlToPlainText = Regex.Replace(htmlToPlainText, @"\s+", " ", RegexOptions.NonBacktracking);diff --git a/apps/server/Tests/AliasVault.IntegrationTests/SmtpServer/SmtpServerTests.cs b/apps/server/Tests/AliasVault.IntegrationTests/SmtpServer/SmtpServerTests.csindex 538f058de..5f0fa1e76 100644--- a/apps/server/Tests/AliasVault.IntegrationTests/SmtpServer/SmtpServerTests.cs+++ b/apps/server/Tests/AliasVault.IntegrationTests/SmtpServer/SmtpServerTests.cs@@ -301,6 +301,36 @@ public class SmtpServerTests});}+ /// <summary>+ /// Tests that non-ASCII printable characters (e.g. accented letters) are preserved in the generated message preview.+ /// Regression test for a bug where the preview extraction stripped all non-ASCII characters (e.g. "répondre" became "rpondre").+ /// </summary>+ /// <returns>Task.</returns>+ [Test]+ public async Task SingleEmailNonAsciiPreviewPlain()+ {+ // Arrange+ var message = new MimeMessage();+ message.From.Add(new MailboxAddress("Test Sender", "[email protected]"));+ message.To.Add(new MailboxAddress("Test Recipient", "[email protected]"));+ message.Subject = "Test Email with accents.";+ const string textBody = "Veuillez répondre à cet e-mail. Voici quelques caractères accentués: éàçüñ.";+ message.Body = new BodyBuilder { TextBody = textBody }.ToMessageBody();+ await SendMessageToSmtpServer(message);++ // Check if the email is in the database.+ var processedEmail = await _testHostBuilder.GetDbContext().Emails.FirstAsync();++ // Decrypt the email and verify the accented characters survived into the preview.+ processedEmail = EmailEncryption.DecryptEmail(processedEmail, PrivateKey);+ Assert.Multiple(() =>+ {+ Assert.That(processedEmail, Is.Not.Null);+ Assert.That(processedEmail.MessagePreview, Does.Contain("répondre"));+ Assert.That(processedEmail.MessagePreview, Is.EqualTo(textBody));+ });+ }+/// <summary>/// Tests sending a single email in plain format to the SMTP server to check if it is processed correctly./// </summary>