Generalize mail templates from a fixed pair to an operator-managed list

ArchiveKind was a hardcoded two-value enum (ssh_access/config_update),
wired through FilenameParser's regex, MailTemplateSet's two fixed
slots, and SettingsForm's two fixed tabs. Operators wanted arbitrary
custom templates (own file-name suffix, subject, body) without a code
change per new archive kind ssh-access-tui might start producing.

Replaced with MailTemplateDefinition (DisplayName/FileSuffix/Subject/
BodyHtml) in an open-ended list: FilenameParser now accepts any
"{login}_{suffix}.7z" and ArchiveScanner matches the suffix against
the configured list; SendJob.Kind/SendLogEntry.Kind became plain
strings; SettingsForm gained a template list (+/- buttons, editor
panel) replacing the two static tabs. ssh_access/config_update are now
just the two default entries in that list, not special-cased.

Handles the two backward-compat edges that matter for a tool already
in real use: old config.json's object-shaped "templates" migrates to
the new list shape transparently on first load (DataContractJsonSerializer
turned out to silently produce an empty list rather than throw on the
old shape, so detection is structural, not exception-based), and old
send-log.csv rows with PascalCase Kind values (SshAccess/ConfigUpdate)
still dedupe correctly against the new snake_case suffixes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
redlineoandClaude Sonnet 5 committed 2026-07-24 11:26:31 +03:00
1 parent cb3b273741
commit 804b9610ca
16 files changed
+904 -288

No files matched your search

@@ -0,0 +1,34 @@
namespace BulkArchiveMailer.Core
{
/// <summary>
/// One configured mail template: which files it applies to (by file
/// name suffix, "{login}_{FileSuffix}.7z"), plus its Subject/BodyHtml.
/// Replaces the old fixed pair of named templates (ssh_access /
/// config_update) with an arbitrary, operator-editable list -
/// AppSettingsData.Templates now holds a List&lt;MailTemplateDefinition&gt;
/// instead of two hard-coded slots.
///
/// FileSuffix is the only identifier a template needs: it must be
/// non-empty and unique (case-insensitively) among all configured
/// templates for ArchiveScanner's suffix-to-template lookup to be
/// unambiguous. Enforcing that (non-empty + unique) is SettingsForm's
/// job at save time, not this class's - a plain data holder has no
/// validation of its own.
/// </summary>
public sealed class MailTemplateDefinition
{
public string DisplayName { get; set; } = "";
/// <summary>
/// Suffix of the file name this template renders for: matches
/// files named "{login}_{FileSuffix}.7z" (case-insensitive; see
/// FilenameParser/ArchiveScanner). Must be non-empty and unique
/// among all configured templates - see class remarks.
/// </summary>
public string FileSuffix { get; set; } = "";
public string Subject { get; set; } = "";
public string BodyHtml { get; set; } = "";
}
}