Skip to content

Commit

Permalink
TNO-2598 Fix Reporting Service (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fosol authored May 1, 2024
1 parent 88e092f commit 9bc815a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
23 changes: 22 additions & 1 deletion libs/net/core/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Globalization;
using System.Net.Mail;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -290,7 +291,9 @@ public static string ConvertTextToParagraphs(string? text, string paragraphRegex
// found at least one paragraph placeholder
sanitizedString = $"<p>{result.Replace(PARAGRAPH_MARKER, "</p><p>")}</p>";
}
} else {
}
else
{
// this is markup, so remove excess carriage returns and line feeds if found
string result = Regex.Replace(sanitizedString, @"\r\n?|\n", PARAGRAPH_MARKER);
if (!result.Equals(sanitizedString, StringComparison.CurrentCultureIgnoreCase))
Expand Down Expand Up @@ -383,4 +386,22 @@ public static string Escape(this string value)
{
return Regex.Replace(value, @"[^a-zA-Z\d\s:]", "\\$0");
}

/// <summary>
/// Determines if the email address is valid.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool IsValidEmail(this string value)
{
try
{
var email = new MailAddress(value);
}
catch
{
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ data:
MAX_FAIL_LIMIT: "5"
TOPICS: index
CHES_EMAIL_ENABLED: "true"
CHES_EMAIL_AUTHORIZED: "false"
CHES_EMAIL_AUTHORIZED: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ data:
MAX_FAIL_LIMIT: "5"
TOPICS: index
CHES_EMAIL_ENABLED: "true"
CHES_EMAIL_AUTHORIZED: "false"
CHES_EMAIL_AUTHORIZED: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ data:
MAX_FAIL_LIMIT: "5"
TOPICS: reporting
CHES_EMAIL_ENABLED: "true"
CHES_EMAIL_AUTHORIZED: "false"
CHES_EMAIL_AUTHORIZED: "true"
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ data:
MAX_FAIL_LIMIT: "5"
TOPICS: reporting
CHES_EMAIL_ENABLED: "true"
CHES_EMAIL_AUTHORIZED: "false"
CHES_EMAIL_AUTHORIZED: "true"
4 changes: 2 additions & 2 deletions services/net/reporting/ReportingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ private async Task GenerateReportAsync(ReportRequestModel request, API.Areas.Ser
await HandleChesEmailOverrideAsync(request.RequestorId);

var contexts = new List<EmailContextModel>();
if (!String.IsNullOrWhiteSpace(request.To))
if (!String.IsNullOrWhiteSpace(request.To) && request.To.IsValidEmail())
{
// Add a context for the requested list of users.
var another = request.To.Split(",").Select(v => v.Trim());
Expand All @@ -714,7 +714,7 @@ private async Task GenerateReportAsync(ReportRequestModel request, API.Areas.Ser
}
else
{
contexts.AddRange(to.Select(v => new EmailContextModel(new[] { v }, new Dictionary<string, object>(), DateTime.Now)
contexts.AddRange(to.Where(v => v.IsValidEmail()).Select(v => new EmailContextModel(new[] { v }, new Dictionary<string, object>(), DateTime.Now)
{
Tag = tag,
}).ToList());
Expand Down

0 comments on commit 9bc815a

Please sign in to comment.