Add HTML decode for email preview in case sender sends html encoded chars in plain text (#1585)

This commit is contained in:
Leendert de Borst
2026-02-03 12:27:03 +01:00
committed by Leendert de Borst
parent 44ad686898
commit fe0bb3a031

View File

@@ -189,8 +189,11 @@ public class DatabaseMessageStore(ILogger<DatabaseMessageStore> logger, Config c
{
if (email.MessagePlain != null && !string.IsNullOrEmpty(email.MessagePlain) && email.MessagePlain.Length > 3)
{
// Decode HTML entities (e.g., &#39; -> ', &amp; -> &)
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<DatabaseMessageStore> logger, Config c
{
string htmlToPlainText = Uglify.HtmlToText(email.MessageHtml).ToString();
// Decode HTML entities (e.g., &#39; -> ', &amp; -> &)
htmlToPlainText = System.Net.WebUtility.HtmlDecode(htmlToPlainText);
// Replace any newline characters with a space
htmlToPlainText = Regex.Replace(htmlToPlainText, @"\t|\n|\r", string.Empty, RegexOptions.NonBacktracking);