From fe0bb3a031dfec08836e2e0947aa376ab0dfef9d Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Tue, 3 Feb 2026 12:27:03 +0100 Subject: [PATCH] Add HTML decode for email preview in case sender sends html encoded chars in plain text (#1585) --- .../Handlers/DatabaseMessageStore.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs b/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs index 3a5a23b16..bfd696698 100644 --- a/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs +++ b/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs @@ -189,8 +189,11 @@ public class DatabaseMessageStore(ILogger logger, Config c { if (email.MessagePlain != null && !string.IsNullOrEmpty(email.MessagePlain) && email.MessagePlain.Length > 3) { + // Decode HTML entities (e.g., ' -> ', & -> &) + string plainToPlainText = System.Net.WebUtility.HtmlDecode(email.MessagePlain); + // Replace any newline characters with a space - string plainToPlainText = Regex.Replace(email.MessagePlain, @"\t|\n|\r", " ", RegexOptions.NonBacktracking); + plainToPlainText = Regex.Replace(plainToPlainText, @"\t|\n|\r", " ", RegexOptions.NonBacktracking); // Remove all "-" or "=" characters if there are 3 or more in a row plainToPlainText = Regex.Replace(plainToPlainText, @"-{3,}|\={3,}", string.Empty, RegexOptions.NonBacktracking); @@ -212,6 +215,9 @@ public class DatabaseMessageStore(ILogger logger, Config c { string htmlToPlainText = Uglify.HtmlToText(email.MessageHtml).ToString(); + // Decode HTML entities (e.g., ' -> ', & -> &) + htmlToPlainText = System.Net.WebUtility.HtmlDecode(htmlToPlainText); + // Replace any newline characters with a space htmlToPlainText = Regex.Replace(htmlToPlainText, @"\t|\n|\r", string.Empty, RegexOptions.NonBacktracking);