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);