9cff87fe85
Remove project bookkeeping citations from shipped code comments across the solution: hyphenated task IDs (WP-14, StoreAndForward-025), milestone/task/ issue refs (M3, Task 4, Audit Log #23, #21), Bundle X task-bundle labels, and C/D/K/S/T phase labels. Comment text only — no code logic, string/log literals, or XML-doc structure changed. Genuine descriptions are preserved (only the citation is stripped), and technical lookalikes are retained (UTF-8, SHA-256, T00:00:00, M365, UTC-5, pre-C4/pre-C5 schema versions). Flagged by the new CommentChecker TaskReferenceInComment / TrackingReferenceInComment checks plus targeted grep passes; full solution builds clean, append-only guard tests pass.
42 lines
1.7 KiB
C#
42 lines
1.7 KiB
C#
using MimeKit;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.NotificationService;
|
|
|
|
/// <summary>
|
|
/// Validates the sender and recipient email addresses before an SMTP
|
|
/// delivery is attempted, so a malformed address surfaces as a clean error
|
|
/// string rather than a <c>ParseException</c> escaping the delivery path.
|
|
/// <para>
|
|
/// Public so the central Notification Outbox's <c>EmailNotificationDeliveryAdapter</c>
|
|
/// can share this exact pre-send validation rather than carry a divergent copy.
|
|
/// </para>
|
|
/// </summary>
|
|
public static class EmailAddressValidator
|
|
{
|
|
/// <summary>
|
|
/// Validates the sender and recipient email addresses, returning a
|
|
/// human-readable error string if any is malformed, or null if all parse.
|
|
/// </summary>
|
|
/// <param name="fromAddress">The sender email address to validate.</param>
|
|
/// <param name="recipients">The list of recipient addresses to validate.</param>
|
|
/// <returns>A human-readable error string if any address is malformed; <c>null</c> if all addresses parse successfully.</returns>
|
|
public static string? ValidateAddresses(
|
|
string fromAddress, IReadOnlyList<NotificationRecipient> recipients)
|
|
{
|
|
if (!MailboxAddress.TryParse(fromAddress, out _))
|
|
{
|
|
return $"Invalid sender (from) email address: '{fromAddress}'";
|
|
}
|
|
|
|
var invalid = recipients
|
|
.Where(r => !MailboxAddress.TryParse(r.EmailAddress, out _))
|
|
.Select(r => r.EmailAddress)
|
|
.ToList();
|
|
|
|
return invalid.Count > 0
|
|
? $"Invalid recipient email address(es): {string.Join(", ", invalid)}"
|
|
: null;
|
|
}
|
|
}
|