miltertest: allow MT_SMTPREPLY check after any callback, not just EOM#342
Merged
thegushi merged 1 commit intoMay 25, 2026
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
mt.eom_check(ctx, MT_SMTPREPLY, ...)only worked aftermt.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 inmailfromorrcptto- making it impossible to test those replies with miltertest.Fix
char ctx_smtp_reply[BUFRSZ]tostruct mt_contextto capture the last SMFIR_REPLYCODE data from any non-EOM callback.mt_assert_state) now saves the reply string whenrcmd == SMFIR_REPLYCODEand clears the field otherwise.mt_eom_check(MT_SMTPREPLY)checksctx_eomreqsfirst (the EOM path, unchanged), then falls back toctx_smtp_reply(the non-EOM path).This means
mt.eom_check(ctx, MT_SMTPREPLY, "550", "5.1.1", "User unknown")now works immediately aftermt.mailfrom()ormt.rcptto()without requiring an EOM phase.Fixes #95.