Assume that an email has the following header field:
To: =?utf-8?q?Foo_Bar?= <1234567890123456789012345678901234567890123456789012345678901234@abcdefghiabcdefghiabcdefghiabcdefghiabcdefghiabcdefghiabcdefghi.com>
Is there a way to fold the header
- in full accordance with RFC 5322
- such that the email is still accepted by commonly used MTAs, and
- no line exceeds a length of 78 characters?
I am aware that the hard limit on line length is 998 chars, but I wonder if it is possible to also fulfill all SHOULD-requirements. If I understand the Augmented Backus-Naur Form
domain-literal = [CFWS] "[" *([FWS] dtext) [FWS] "]" [CFWS]
dtext = %d33-90 / ; Printable US-ASCII
%d94-126 / ; characters not including
obs-dtext ; "[", "]", or "\"
in section 3.4.1 correctly, one can insert folding whitespace into domain literals, and the following should be valid:
To: =?utf-8?q?Foo_Bar?=
<1234567890123456789012345678901234567890123456789012345678901234@abcdefgh
iabcdefghiabcdefghiabcdefghiabcdefghiabcdefghiabcdefghi.com>
However, this is rejected by recent versions of postfix and exim:
501: <1234567890123456789012345678901234567890123456789012345678901234@abcdefgh: '>' missing at end of address
Either both MTAs are broken (which seems highly unlikely), or my interpretation of the RFC is wrong.
Addendum in case someone runs into similar problems:
Before posting the question, I actually tried to fold at @
and .
as shown in the RFC-conformant example by jstedfast, but got the same error message. As it turns out, this was not the fault of the MTA but of the SMTP client library I used, which extracted the recipient addresses from the header for generating RCPT TO:
commands for SMTP and failed to filter out the line breaks.