37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System;
|
|
|
|
namespace BulkArchiveMailer.Core
|
|
{
|
|
/// <summary>
|
|
/// Derives the recipient's email address from the login embedded in an
|
|
/// archive file name. Rule (see repo README/plan, confirmed with the
|
|
/// operator): a Linux login such as "a-makarov" maps to
|
|
/// "a.makarov@<domain>" by replacing every hyphen with a dot -
|
|
/// there is no separate mapping table.
|
|
///
|
|
/// Known accepted limitation (do NOT try to fix this with an override
|
|
/// mechanism): if a real login contains a literal hyphen that is not
|
|
/// an initial/surname separator, this produces the wrong local part.
|
|
/// That is out of scope for this tool - see README.md.
|
|
/// </summary>
|
|
public static class EmailAddressBuilder
|
|
{
|
|
public static string BuildEmail(string login, string domain)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(login))
|
|
{
|
|
throw new ArgumentException("login must not be empty.", nameof(login));
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(domain))
|
|
{
|
|
throw new ArgumentException("domain must not be empty.", nameof(domain));
|
|
}
|
|
|
|
var localPart = login.Trim().ToLowerInvariant().Replace('-', '.');
|
|
var cleanDomain = domain.Trim().TrimStart('@');
|
|
return $"{localPart}@{cleanDomain}";
|
|
}
|
|
}
|
|
}
|