Skip to content

fix: normalize folded headers before SMTP send#249

Open
rawvoid wants to merge 1 commit into
vert-x3:masterfrom
rawvoid:fix/folded-header-crlf
Open

fix: normalize folded headers before SMTP send#249
rawvoid wants to merge 1 commit into
vert-x3:masterfrom
rawvoid:fix/folded-header-crlf

Conversation

@rawvoid
Copy link
Copy Markdown

@rawvoid rawvoid commented Apr 17, 2026

Summary

This fixes folded header values being sent with bare LF during SMTP DATA.

How To Reproduce

  1. Create a message with a non-ASCII subject long enough to be folded, for example Unicode folding test ⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐⭐.
  2. Send it to a strict SMTP server that rejects bare LF in the DATA payload.
  3. Before this change, the subject folding generated embedded in the header value, and SMTPSendMail appended " " only at the end of the full header line.
  4. The wire payload therefore contained bare LF inside the folded Subject header, and the server could reject the message during DATA.

Fix

  • Normalize embedded header line breaks to CRLF before writing headers to the SMTP socket.
  • Use the same normalized header representation for DKIM copied headers and header canonicalization, so signing stays aligned with the transmitted message.
  • Add a regression test that sends a folded Unicode subject through the existing strict bare-LF test fixture.

Standards Basis

  • RFC 5321 requires SMTP clients to use CRLF as the line terminator and not transmit bare CR or LF in message text.
  • RFC 5322 requires header fields to be terminated by CRLF, and header folding is defined as inserting CRLF before whitespace.

Verification

  • mvn -q -Dtest=MailHeaderLineBreakTest,MailSubjectTest,DKIMSignerTest test
  • mvn -q -Dtest=MailWithDKIMSignTest#testMailSimpleSimplePlain+testMailRelaxedRelaxedPlain,DKIMSignerTest test

@tsegismont
Copy link
Copy Markdown
Member

Thanks for sharing this PR. Have you signed the Eclipse Contributor Agreement and signed-off your commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants