Skip to content

config: validate from at load (empty/invalid from was only caught at send time) - #39

Open
farangkao wants to merge 1 commit into
ssp-data:mainfrom
farangkao:fix/validate-from-address
Open

farangkao wants to merge 1 commit into
ssp-data:mainfrom
farangkao:fix/validate-from-address

Conversation

@farangkao

Copy link
Copy Markdown
Contributor

Problem

While it was my own fault (empty from="") i've run into this behavior myself, the problem is that neomd didn't warn me.
luckily i was able to recover the typed email body using ":recover"
Note: during editing i noticed the empty From field, but i suspected he will simply fallback to my defined email address for the current account selected.

Details:
With from left empty (its default) neomd starts fine, the pre-send screen
shows a blank From: line, and the failure surfaces only after the mail is
written:

✗ build message: invalid From address "": cannot parse address for Message-ID (ensure address format is valid)

The same goes for a malformed from = "xx". extractDomain's comment even
assumes "the From address always comes from validated config.toml accounts" —
but validate() never checked from at all.

Fix

Config.validate() now requires a from on every [[accounts]] entry and
[[senders]] alias, and checks it is a single RFC 5322 address with a
non-empty domain (validFromAddress — the same bar extractDomain applies
at send, so anything that passes load can actually send):

  • empty → account "name": from is required (set from to your address, e.g. "Name <you@example.com>")
  • malformed ("xx", Name <xx>, multiple addresses) → account "name": from "xx" is not a valid email address

Both surface through the existing config validation: startup error, before
any mail is composed.

Behavior change: configs with an empty from previously loaded (but could
never send) — they now refuse to start, with a message that says exactly what
to set.

Tests

  • TestValidate_AccountRequiresFrom, TestValidate_SenderRequiresFrom
  • TestValidate_FromFormat (valid/invalid table: "xx", Name <xx>, xx@, multiple addresses)
  • TestLoad_EmptyFromIsLoadError (through Load)

Full suite + Hardening suites pass. +157/−0 (code, tests, CHANGELOG entry, AGENTS.md invariant).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant