Closed jbalazerpfpt closed 1 year ago
RFC5322 has replaced 2822. https://www.rfc-editor.org/rfc/rfc5322#section-3.2.2 When you look at the headers, they often use tabs where a blank is sufficient, even in Subject folding. So reality differs from the intention of CFWS. That's why I changed the output a bit. But, I took that part of your changes.
Some applications sometimes produce lines which are too long. (Old) equipment breaks those lines into
separate lines, which leads to \r\n
without following white-space.
The last paragraph says:
Runs of FWS, comment, or CFWS that occur between lexical tokens in a structured header field are semantically interpreted as a single space character.
So, I do hope a change from 'space' into retaining the white-space in the last change does not break people's code.
You say "This changes the message, with potential consequences.". Still, after your changes, the message is still changed on leading and trailing white-spaces. So: why is that change acceptable?
This horrible
+ # remove trailing white space (optimized)
+ $body = ($body =~ m/(\S(?:.*\S)?)/)[0] // '';
is claimed to be faster than:
- for($body) { s/^\s+//; s/\s$// }
I would like to see proof of that, before I add such horrible construct. Assuming that the line change is rarely applied.
The slowdown seen in s/\s$//
was only seen in multi-threaded applications, so it may be a bug in Perl itself. I'm hearing that the issue may already be fixed in the latest version of Perl.
Per RFC 2822 section 3.2.3, a header field can be folded by inserting CRLF before a white space character - a space or a tab. And to unfold a folded field, the CRLF should be removed. Mail-Message 3.x introduces a bug in the unfolding of folded header fields: if the folding white space is CRLF followed by a tab character, the unfolding would convert the tab to a space. This changes the message, with potential consequences. Header unfolding should remove the CRLF without changing the white space character that follows it.
I have fixes here for three files with the bug. The accompanying stripping of leading or trailing white space has also been rewritten in an optimized fashion that works without backtracking.
The original regex substitutions would also replace a CRLF that is NOT followed by white space. It is unclear to me why they would do that, since a CRLF is only allowed in the header field when it is part of folding white space. Nevertheless, I have preserved that behavior with explicit
s/\r?\n/ /g
substitutions. Perhaps they are unnecessary.