Repository navigation
fix(mailer): set Date and Message-ID on SMTP messages - #176
Conversation
|
All contributors have signed the CLA. ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
ℹ️ Minor suggestions only — the header generation is correct, but the
Message-IDdomain has an edge case and neither new header is covered by a test.
Reviewed changes
Reviewed the single commit adding RFC 5322 Date and Message-ID headers to the SMTP transport.
internal/mailer/smtp.go—buildRawnow writesDateviatime.RFC1123Z(numeric zone) andMessage-ID: <uuid@from-domain>before the existingFrom/To/Subjectheaders. Only the SMTP path is touched; Resend continues to set its own headers.
deepseek-v4.1-flash | 𝕏
There was a problem hiding this comment.
✅ No new issues found. The follow-up commit addresses both prior threads cleanly and adds solid coverage.
Reviewed changes
Reviewed the incremental delta since the previous pullfrog review, commit c622ca7.
- Message-ID domain hardened —
messageIDDomainnow recovers the domain by parsings.fromwithmail.ParseAddress(handling display names and empty/unparseable values), falling back to the SMTP host and thenlocalhost. - Header-injection guard added —
messageIDDomainOKrestricts the right-hand side to[a-z0-9.-], blocking CR/LF and angle brackets from operator-supplied values. - Tests added —
TestBuildRaw_dateHeader,TestBuildRaw_messageIDHeader, andTestBuildRaw_messageIDDomaincover the date parse round-trip, numeric-zone form, Message-ID structure/uniqueness, and each From/host fallback including a CRLF-host case. - CHANGELOG updated — documents the new headers and the domain fallback behavior.
deepseek-v4.1-flash | 𝕏
Messages sent through the SMTP mailer carried From, To and Subject but no Date or Message-ID header. RFC 5322 requires Date on every message and says each message should carry a Message-ID. Some relays add the missing headers on the way through, but not all of them do, and receiving servers and spam filters score messages without them as suspicious, so confirmations and reminders could land in spam. buildRaw now writes Date (RFC 1123 with numeric zone, the RFC 5322 date-time form) and a Message-ID of the form <unique-id@sender-domain>, with the domain taken from the From address. Only the SMTP path is affected. Validated with go test ./... and make build.
email_from is not validated anywhere: PatchEmailSettings does not check it and the settings form does not require it. Slicing the domain off the raw value therefore produced <id@> for an empty setting, and <[email protected]> for "Calnode <[email protected]>" — malformed identifiers, which work against the deliverability the header was added for. messageIDDomain parses the address instead and falls back to the SMTP host, then to localhost. Both operator-supplied candidates must pass a dot-atom check first, so neither can carry a CR/LF into the header line. Cover the Date and Message-ID headers: Date against mail.ParseDate rather than the layout that produced it, Message-ID for shape, uniqueness and each From/host combination that reaches buildRaw unvalidated.
c622ca7 to
e334f89
Compare
The append-only guard added in Calnode#161 compares the pull request's ledger with the tip of the base branch. Signatures are committed to main by the CLA bot, so any signature added after a PR was opened is absent from its head by construction. Comparing with today's main calls that "removed" and fails the PR. That is what happened to Calnode#176, Calnode#179, Calnode#158 and Calnode#159 at once: MohammadHadi2031 signed, the ledger on main grew from 11 to 12 entries, and every PR forked before that point was reported as revoking his signature. Nothing was removed. Compare against git merge-base HEAD origin/<base> instead, which only sees entries the PR's own branch actually had. A shallow clone cannot compute a merge base, so warn and skip rather than fail closed on an infrastructure limitation. Checkout now fetches full history for this job; the repository is 8MB. Verified against the real Calnode#176: base=main tip reports "MohammadHadi2031 (id 17288524)" as removed and exits 1; base=merge-base reports nothing and exits 0. A ledger with one signature genuinely deleted still fails, naming tgrahammer (id 3223680).
|
Merging this. The single red check is our bug, not your code.
Everything else is green here, including arm64-smoke and both security scans. The code reads well. Two things I checked deliberately: |

Messages sent through the SMTP mailer carried
From,ToandSubjectbut noDateorMessage-IDheader. RFC 5322 requiresDateon every message and says each message should carry aMessage-ID. Some relays add the missing headers on the way through, but not all of them do, and receiving servers and spam filters score messages without them as suspicious, so confirmations and reminders could land in spam.buildRawnow writesDate(RFC 1123 with numeric zone, the RFC 5322 date-time form) and aMessage-IDof the formunique-id@sender-domain. Only the SMTP path is affected; the Resend transport sets both headers itself.Message-ID domain.
email_fromis not validated anywhere —PatchEmailSettingsdoes not check it and the settings form does not require it — so the domain is not sliced off the raw value.messageIDDomainparses the address and falls back to the SMTP host, then tolocalhost; both operator-supplied candidates must pass a dot-atom check first, so neither can carry a CR/LF into the header line. This covers an unsetemail_from(which would have produced<id@>) and the fullCalnode <[email protected]>form (which would have produced<[email protected]>, closing the identifier early).Tests.
TestBuildRaw_dateHeadervalidates the header againstmail.ParseDaterather than the layout that produced it, plus the numeric zone.TestBuildRaw_messageIDHeadercovers shape, a non-empty local part, the expected domain and uniqueness.TestBuildRaw_messageIDDomaintables every From/host combination that reachesbuildRawunvalidated and asserts no header injection.CHANGELOG has an
[Unreleased] → Fixedentry for the change.Validated with
make build,go test ./..., gofmt and go vet.