From 05f5a355229e0f2e2ba21ff391b64ddd2d0fec2a Mon Sep 17 00:00:00 2001 From: Nicholas-Westby Date: Mon, 18 Jul 2022 12:53:39 -0700 Subject: [PATCH] fix (Line Breaks) use different line break for plain text Also, minor code style changes. See: https://github.com/rhythmagency/formulate/issues/214 --- .../Forms/Handlers/Email/EmailHandler.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/formulate.app/Forms/Handlers/Email/EmailHandler.cs b/src/formulate.app/Forms/Handlers/Email/EmailHandler.cs index 8a78f2c0..6e55c5b9 100644 --- a/src/formulate.app/Forms/Handlers/Email/EmailHandler.cs +++ b/src/formulate.app/Forms/Handlers/Email/EmailHandler.cs @@ -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)|(? @@ -88,6 +91,7 @@ public EmailHandler(IConfigurationManager configurationManager) #endregion + #region Private Properties /// @@ -96,9 +100,9 @@ public EmailHandler(IConfigurationManager configurationManager) private IConfigurationManager Config { get; set; } /// - /// Precompiled regex for finding line breaks. + /// Matches line breaks. /// - private static Regex LineBreakRegex = new Regex(@"(\r\n|\r(?!\n)|(? LineBreakRegex.Replace(WebUtility.HtmlEncode(x), - Environment.NewLine + "
" + Environment.NewLine)).ToList(); + lines = lines + .Select(x => WebUtility.HtmlEncode(x)) + .Select(x => LineBreakRegex.Replace(x, nl)) + .ToList(); } // Return message. @@ -555,4 +560,4 @@ private object AttemptGetValue(Dictionary dictionary, string key #endregion } -} +} \ No newline at end of file