Skip to content

miltertest: allow MT_SMTPREPLY check after any callback, not just EOM#342

Merged
thegushi merged 1 commit into
trusteddomainproject:developfrom
thegushi:issue-95-smtpreply-any-callback
May 25, 2026
Merged

miltertest: allow MT_SMTPREPLY check after any callback, not just EOM#342
thegushi merged 1 commit into
trusteddomainproject:developfrom
thegushi:issue-95-smtpreply-any-callback

Conversation

@thegushi
Copy link
Copy Markdown
Collaborator

Problem

mt.eom_check(ctx, MT_SMTPREPLY, ...) only worked after mt.eom() because SMFIR_REPLYCODE data was only captured in the EOM request accumulator (ctx_eomreqs). Milters can send a custom SMTP reply from any callback - for example, rejecting a message in mailfrom or rcptto - making it impossible to test those replies with miltertest.

Fix

  • Add char ctx_smtp_reply[BUFRSZ] to struct mt_context to capture the last SMFIR_REPLYCODE data from any non-EOM callback.
  • Every callback that reads a milter response (connect, helo, mailfrom, rcptto, data, header, eoh, bodystring, bodyrandom, bodyfile, and the automatic state-advancement paths in mt_assert_state) now saves the reply string when rcmd == SMFIR_REPLYCODE and clears the field otherwise.
  • mt_eom_check(MT_SMTPREPLY) checks ctx_eomreqs first (the EOM path, unchanged), then falls back to ctx_smtp_reply (the non-EOM path).

This means mt.eom_check(ctx, MT_SMTPREPLY, "550", "5.1.1", "User unknown") now works immediately after mt.mailfrom() or mt.rcptto() without requiring an EOM phase.

Fixes #95.

Previously SMFIR_REPLYCODE data was stored only in the EOM request list
(ctx_eomreqs), so mt.eom_check(ctx, MT_SMTPREPLY, ...) only worked after
mt.eom(). Milters can send a custom SMTP reply from any callback (e.g.
rejecting at MAIL FROM or RCPT TO), making the check unreachable there.

Add ctx_smtp_reply[BUFRSZ] to struct mt_context to capture SMFIR_REPLYCODE
data from non-EOM callbacks. Every callback that reads a milter response now
saves the reply string when rcmd == SMFIR_REPLYCODE and clears the field
otherwise. mt_eom_check(MT_SMTPREPLY) then checks ctx_eomreqs first (EOM
path) and falls back to ctx_smtp_reply (non-EOM path).

Fixes trusteddomainproject#95.
@thegushi thegushi merged commit fb2ac9f into trusteddomainproject:develop May 25, 2026
1 check passed
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