diff options
| author | Jason McCormick <jason@mfamily.org> | 2026-11-05 18:37:48 -0500 |
|---|---|---|
| committer | Jason McCormick <jason@mfamily.org> | 2026-11-05 18:37:48 -0500 |
| commit | c2382d8b4cf93489614c5fe70a604ab698b9f613 (patch) | |
| tree | 8a8b28d010292271b24b9c3cd6bc175fc58e2a95 /server.py | |
| parent | 75719aa37f7317f3a8feeb516f1444edb4274410 (diff) | |
feat: 1-minute watcher and per-stanza email subject/header
Run the notification timer every minute and shrink the scan window to
match. Each upload URI stanza may now set subject and body_header to
override the default notification text.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'server.py')
| -rw-r--r-- | server.py | 29 |
1 files changed, 27 insertions, 2 deletions
@@ -51,6 +51,9 @@ class AppConfig: recipients: dict[str, str] # Absolute http(s) URL, ending in "/", under which a target's stored files are viewable. view_url_prefixes: dict[str, str] = field(default_factory=dict) + # Optional per-target notification email overrides. + subjects: dict[str, str] = field(default_factory=dict) + body_headers: dict[str, str] = field(default_factory=dict) def target_from_path(path: str) -> str | None: @@ -82,6 +85,19 @@ def _validate_view_url_prefix(value: object, setting: str) -> str: return value if value.endswith("/") else value + "/" +def _validate_text(value: object, setting: str, max_length: int, multiline: bool) -> str: + allowed = "\n\t" if multiline else "\t" + if ( + not isinstance(value, str) + or not value.strip() + or len(value) > max_length + or any((ord(character) < 32 and character not in allowed) or ord(character) == 127 for character in value) + ): + kind = "text" if multiline else "single-line text" + raise ValueError(f"{setting} must be non-empty {kind} of at most {max_length} characters") + return value.strip() + + def load_config(path: Path) -> AppConfig: """Load SMTP settings and URI-to-recipient mappings from TOML.""" try: @@ -111,7 +127,9 @@ def load_config(path: Path) -> AppConfig: recipients: dict[str, str] = {} view_url_prefixes: dict[str, str] = {} - allowed_keys = {"recipient", "view_url_prefix"} + subjects: dict[str, str] = {} + body_headers: dict[str, str] = {} + allowed_keys = {"recipient", "view_url_prefix", "subject", "body_header"} for stanza, values in raw_config.items(): if stanza == "GLOBAL": continue @@ -120,13 +138,18 @@ def load_config(path: Path) -> AppConfig: raise ValueError(f"Invalid upload URI stanza in {path}: {stanza!r}") if not isinstance(values, dict) or "recipient" not in values or not set(values) <= allowed_keys: raise ValueError( - f"[{stanza}] in {path} must define recipient and may define only view_url_prefix besides it" + f"[{stanza}] in {path} must define recipient and may also define only: " + f"{', '.join(sorted(allowed_keys - {'recipient'}))}" ) recipients[target] = _validate_email(values["recipient"], f"{stanza}.recipient") if "view_url_prefix" in values: view_url_prefixes[target] = _validate_view_url_prefix( values["view_url_prefix"], f"{stanza}.view_url_prefix" ) + if "subject" in values: + subjects[target] = _validate_text(values["subject"], f"{stanza}.subject", 200, multiline=False) + if "body_header" in values: + body_headers[target] = _validate_text(values["body_header"], f"{stanza}.body_header", 2000, multiline=True) if not recipients: raise ValueError(f"No upload URI stanzas are configured in {path}") @@ -134,6 +157,8 @@ def load_config(path: Path) -> AppConfig: smtp=SMTPSettings(send_as, smtp_server, smtp_port, tls, starttls), recipients=recipients, view_url_prefixes=view_url_prefixes, + subjects=subjects, + body_headers=body_headers, ) |
