Issue Description
Stalwart sends a header whose name or value is not valid UTF-8 to the milter (SMFIC_HEADER) with an empty value. The milter sees the header, but not its content.
Expected Behavior
The milter protocol carries header names and values as NUL-terminated byte strings and has no UTF-8 requirement. Postfix and Sendmail pass the raw bytes through. Stalwart should send the header bytes as received.
Actual Behavior
Tested on v1.0.0 with a minimal milter (protocol v6) that logs each frame. The message was:
From: Alice <[email protected]>
To: [email protected]
Subject: Caf\xe9 au lait <- raw ISO-8859-1 byte 0xE9
X-Ok: plain ascii
...
The milter received:
HEADER b'Subject' b''
HEADER b'X-Ok' b'plain ascii'
The delivered message still has the original Subject: Caf\xe9 au lait, so a filter scores or acts on something different from what the recipient gets. Raw 8-bit headers are not standards-conformant, but they are common in spam and in legacy mail, which is where a filter needs to see them most.
Cause
crates/smtp/src/inbound/milter/message.rs (v1.0.0, around line 271):
client.headers(message.headers().iter().map(|(k, v)| {
(
std::str::from_utf8(k).unwrap_or_default(),
std::str::from_utf8(v).unwrap_or_default(),
)
}))
unwrap_or_default() turns an invalid header into "". MilterClient::headers (client.rs:222) takes AsRef<str>, but only to call .trim().as_bytes(), so it could take &[u8] and send the bytes unchanged (trimming ASCII whitespace with trim_ascii()).
The reply direction has the same restriction. read_nul_terminated (protocol.rs:272) uses String::from_utf8(buf).ok(), so an SMFIR_ADDHEADER / SMFIR_CHGHEADER / SMFIR_INSHEADER whose value is not UTF-8 fails to parse.
Reproduction Steps
See “Actual Behaviour”
Stalwart Version
v1.x
Installation Method
Binary (Linux)
Database Backend
RocksDB
Blob Storage
RocksDB
Search Engine
Internal
Directory Backend
Internal
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