Subject: | MIME-Q / _header_to_list interaction produces broken headers |
Some of my email is being rejected by SES (AWS Simple Email Service)
with an error of "Domain contains whitespace or control."
It turns out that some mail is ultimately being submitted with headers
like "From: Really Long Name\n\x20<source@example.\x20com>", which
results from this series of events:
1. Call Email::MIME->create with From => '...' containing no newlines or
spaces within the angle brackets.
2. The creation process builds up a text header, using MIME-Q encoding,
which for certain lengths of From value, triggers a fold inside the
addr-spec.
3. This text header is passed into Email::Simple::Header->new which
parses it, but unfolds by removing only "\n", leaving the space in the
domain.
4. Later, when I call as_string() and the final header is constructed,
the address is split at an earlier point, and the leftover space stays
in the domain to confuse Amazon SES.
I believe SES is technically in the wrong here, but I'd prefer Email::*
to avoid generating obsolete (RFC 2822 section 4.4) output.
I think fixing issue #62913 would also fix this problem as a side effect.
The specific length of From value I'm seeing this problem with is 78
US-ASCII characters (78 bytes) which exceeds the bytes-per-line value by
less than the length of the addr-spec.
$Email::MIME::VERSION eq '1.910', $Email::Simple::VERSION eq '2.101'.
Test case:
use Email::MIME;
$m = Email::MIME->create(header_str => [
From => join(' ', qw(Initech Global Services Marketplace Group
IntelliSpam <gsmgi-spam@example.com> ))]);
print $m->as_string;