Subject: | binary data incorrectly encoded into quoted-printable |
MIME::Body produces incorrect quoted-printable encoding if the body is non-text data.
According to RFC2045 (rule 4) \015 and \012 bytes (CR and LF) of non-text data should be encoded as all other nonprintable bytes (=0D, =0A), but input data encoded as a text chunk - leaving "\n" untouched.
It leads to data corruption when encoding on Unix binary data aimed to Win
for example. Byte \012 from the source data stream will be two byte sequence at the destination.
We've encountered such a case on a real mail after mimedefang processing, using MIME-tools, which in turn uses MIME::Base64
Actually it's rather a MIME::Base64 issue. I posted it there too (#7456).
IMHO the easiest solution is always encoding input as a binary stream.
It should work fine for both text and binary data, but actually such a approach is not thoroughly RFC-compliant.
In this case there is no need to modify MIME-tools modules.
I guess that to perfectly adhere to the RFC 2045, text and non-text input data should be processed in different ways (rule 4), so another parameter indicating data type is necessary when making actual encoding(i think that guessing data type in the module is not the right thing).
In this case some MIME-tools modules should be modified too.
Suggested patch is attached. In this case encode_qp (from MIME::Base64) will get up to 3 input parameters: data, eol, and flag indicating whether the input data stream is a text.
Message body not shown because it is not plain text.