Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
fix (Line Breaks) use different line break for plain text
Browse files Browse the repository at this point in the history
Also, minor code style changes.

See: #214
  • Loading branch information
Nicholas-Westby committed Jul 18, 2022
1 parent cef8565 commit 05f5a35
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/formulate.app/Forms/Handlers/Email/EmailHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ public class EmailHandler : IFormHandlerType
public EmailHandler(IConfigurationManager configurationManager)
{
Config = configurationManager;
var options = RegexOptions.Compiled;
LineBreakRegex = new Regex(@"\r\n|\r(?!\n)|(?<!\r)\n", options);
}

#endregion


#region Public Properties

/// <summary>
Expand All @@ -88,6 +91,7 @@ public EmailHandler(IConfigurationManager configurationManager)

#endregion


#region Private Properties

/// <summary>
Expand All @@ -96,9 +100,9 @@ public EmailHandler(IConfigurationManager configurationManager)
private IConfigurationManager Config { get; set; }

/// <summary>
/// Precompiled regex for finding line breaks.
/// Matches line breaks.
/// </summary>
private static Regex LineBreakRegex = new Regex(@"(\r\n|\r(?!\n)|(?<!\r)\n)", RegexOptions.Compiled);
private static Regex LineBreakRegex { get; set; }

#endregion

Expand Down Expand Up @@ -458,9 +462,10 @@ private string ConstructMessage(
if (isHtml)
{
baseMessage = WebUtility.HtmlEncode(baseMessage);

lines = lines.Select(x => LineBreakRegex.Replace(WebUtility.HtmlEncode(x),
Environment.NewLine + "<br>" + Environment.NewLine)).ToList();
lines = lines
.Select(x => WebUtility.HtmlEncode(x))
.Select(x => LineBreakRegex.Replace(x, nl))
.ToList();
}

// Return message.
Expand Down Expand Up @@ -555,4 +560,4 @@ private object AttemptGetValue(Dictionary<string, object> dictionary, string key

#endregion
}
}
}

0 comments on commit 05f5a35

Please sign in to comment.