Issue Description
Milter: SMFIC_BODY carries the full raw message, headers arrive twice at the milter
Expected Behavior
Stalwart sends the headers with SMFIC_HEADER/SMFIC_EOH and then only the message body with SMFIC_BODY, as Postfix and Sendmail do. A milter that stores the message (e.g. an archive) receives every header exactly once.
Actual Behavior
The SMFIC_BODY chunks contain the complete raw message (headers + body). The milter receives the headers twice, the second copy inside the body. A message stored by benno-milter looks like this:
X-REAL-MAILFROM: <[email protected]>
X-REAL-RCPTTO: <[email protected]>
Subject: test
From: [email protected]
Subject: test
From: [email protected]
body line
Cause in crates/smtp/src/inbound/milter/message.rs (v0.16.24, unchanged in v0.16.27, v1.0.0 and main 47df4c0b):
// Message body
let (action, modifications) = client.body(message.raw_message()).await?;
The headers were sent just before via client.headers(…). Other places pass the body only: the milter body replacement in the same file uses message.raw_body(), the MTA hooks (inbound/hooks/message.rs) use message.raw_body(), and the milter test client in
tests/src/smtp/inbound/milter.rs sends &message.raw_message()[message.root_part().raw_body_offset() as usize..].
Proposed fix:
- let (action, modifications) = client.body(message.raw_message()).await?;
+ let (action, modifications) = client.body(message.raw_body()).await?;
We run a 0.16.24 build with exactly this change on a test system.
Reproduction Steps
- Install a milter that writes the received message to disk, e.g. benno-milter 2.10 (Benno MailArchiv) listening on inet:[email protected].
- Add an MtaMilter: hostname 127.0.0.1, port 22500, protocol version 6, flagsProtocol 0x43 (see Additional Context).
- Deliver a message via SMTP port 25:
Subject: test From: [email protected] body line - Open the file written by the milter: the headers appear twice, once before the body and once at the start of the body.
Relevant Log Output
Stalwart accepts the message, the milter conversation itself succeeds (the defect is in the content of SMFIC_BODY, it does not produce an error):
2026-10-22T12:47:27Z INFO Milter action: Accept (milter.action-accept) listenerId = "submissions", localPort = 465, remoteIp = 203.0.113.10, remotePort = 56762, id = "MtaMilter with id jkyfwfcuadqa", elapsed = 0ms
Before setting flagsProtocol, the default negotiation failed:
2026-10-22T12:46:27Z WARN Milter disconnected (milter.disconnected) listenerId = "smtp", localPort = 25, remoteIp = 203.0.113.10, remotePort = 41502, id = "MtaMilter with id jkyfwfcuadqa", details = (null), elapsed = 0ms
benno-milter: st_optionneg[0]: 0x42 does not fulfill protocol requirements 0x3
Stalwart Version
v0.16.x
Installation Method
Binary (Linux)
Database Backend
PostgreSQL
Blob Storage
Filesystem
Search Engine
Meilisearch
Directory Backend
LDAP
Additional Context
- Stalwart 0.16.24, own Debian 13 package (binary), PostgreSQL data store, filesystem blob store, Meilisearch, LDAP directory (Samba AD).
- Negotiation: Stalwart offers the protocol flags 0x42. benno-milter is a libmilter milter that requests SMFIP_NOCONNECT|SMFIP_NOHELO (0x3) and disconnects when they are not offered. flagsProtocol = 0x43 on the MtaMilter works around it; offering these “no-*” flags by default might be worth considering.
- Not related to #1882 (EOH omitted with NOHDRS) or #1786 (Sieve after milter), both already fixed.
I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.
on
I have searched this support forum (open and closed topics) and confirm this is not a duplicate.
on
I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.
on