Skip Menu |

This queue is for tickets about the MIME-tools CPAN distribution.

Report information
The Basics
Id: 7457
Status: resolved
Priority: 0/
Queue: MIME-tools

Owner: Nobody in particular
Requestors: ak2 [...]

Bug Information
Severity: Important
Broken in: 6.200_02
Fixed in: 5.416


Subject: binary data incorrectly encoded into quoted-printable
Download (untitled) / with headers
text/plain 1.4k
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.
Download MIME-tools-6.200_02.patch.gz
application/x-gzip-compressed 850b

Message body not shown because it is not plain text.

From: ak2 [...]
Download (untitled) / with headers
text/plain 335b
MIME::Base64 has been corrected (binmode.patch). encode_qp since version 3.02 takes up 3 args. Third arg is a flag indicating binary mode. Since the flag meaning is inverted comparing to the MIME::Base64 patch suggested originally, the corresponding MIME-tools patch should be modified also. Attached is corrected MIME-tools patch.
diff -u -r MIME-tools-6.200_02.orig/lib/MIME/Decoder/ MIME-tools-6.200_02/lib/MIME/Decoder/ --- MIME-tools-6.200_02.orig/lib/MIME/Decoder/ Wed Jun 4 22:54:02 2003 +++ MIME-tools-6.200_02/lib/MIME/Decoder/ Wed Aug 25 16:30:52 2004 @@ -71,7 +71,7 @@ # grow beyond 76 characters! # sub encode_qp_really { - my $enc = encode_qp($_[0]); + my $enc = encode_qp(shift, undef, not shift); if (length($enc) < 74) { $enc =~ s/^\.$/=2E/g; # force encoding of /^\.$/ $enc =~ s/^From /=46rom /g; # force encoding of /^From / @@ -98,11 +98,11 @@ # encode_it IN, OUT # sub encode_it { - my ($self, $in, $out) = @_; + my ($self, $in, $out, $textual_type) = @_; local($_); while (defined($_ = $in->getline)) { - $out->print(encode_qp_really($_)); + $out->print(encode_qp_really($_, $textual_type)); } 1; } diff -u -r MIME-tools-6.200_02.orig/lib/MIME/ MIME-tools-6.200_02/lib/MIME/ --- MIME-tools-6.200_02.orig/lib/MIME/ Sat Jun 7 04:41:38 2003 +++ MIME-tools-6.200_02/lib/MIME/ Tue Aug 24 16:37:20 2004 @@ -248,14 +248,14 @@ =cut sub encode { - my ($self, $in, $out) = @_; + my ($self, $in, $out, $textual_type) = @_; ### Coerce old-style filehandles to legit objects, and do it! $in = wraphandle($in); $out = wraphandle($out); ### Invoke back-end method to do the work: - $self->encode_it($in, $out) || + $self->encode_it($in, $out, $self->encoding eq 'quoted-printable' ? ($textual_type) : ()) || die "".$self->encoding." encoding failed\n"; } diff -u -r MIME-tools-6.200_02.orig/lib/MIME/ MIME-tools-6.200_02/lib/MIME/ --- MIME-tools-6.200_02.orig/lib/MIME/ Fri Jun 27 22:54:30 2003 +++ MIME-tools-6.200_02/lib/MIME/ Tue Aug 24 16:55:08 2004 @@ -1935,7 +1935,7 @@ ### Output the body: my $IO = $self->open("r") || die "open body: $!"; - $decoder->encode($IO, $out) || die "encoding failed\n"; + $decoder->encode($IO, $out, textual_type($self->head->mime_type) ? 1 : 0) || die "encoding failed\n"; $IO->close; 1; }

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to