Subject: | Wrong attachment encoding |
Date: | Tue, 21 Jun 2011 02:06:16 +0200 |
To: | bug-Courriel [...] rt.cpan.org, Ico <ico [...] petrzalka.net> |
From: | icovnik <icovnik [...] gmail.com> |
When I tried to send some binary attachments (some PDFs, then few
tests with my linux' system binaries...) I found the attachments
somehow wrong encoded. When I create some really simple email message
with some binary attachment, the resulting email has improperly
base64-encoded attachments. Encoded attachments from resulting email
differs from output from uuencode and Perl's MIME::Base64 (both
produced the same results). When I receive email produced this way,
then save attachment to disk, the resulting file is different from the
source. When I replace the original attachment with MIME::Base64's
result, the received file is the same as the original.
The simplest test case to produce malformed attachment:
#!/usr/bin/env perl
use Courriel::Builder;
use File::Slurp qw(write_file);
my $e = build_email(
subject("x"),
from('x@y.z'),
to('x@y.z'),
plain_body("b"),
attach(
file => "/bin/dd",
mime_type => "application/octet-stream",
),
);
write_file("email", $e->as_string);
And how to "fix" the error (I don't propose to fix this bug like this,
just to show the case :) ):
#!/usr/bin/env perl
use Courriel::Builder;
use File::Slurp qw(write_file read_file);
use MIME::Base64;
my $e = build_email(
subject("x"),
from('x@y.z'),
to('x@y.z'),
plain_body("b"),
attach(
file => "/bin/dd",
mime_type => "application/octet-stream",
),
);
my $d = $e->as_string;
my $enc = encode_base64(read_file("/bin/dd"));
$enc =~ s/\n/\r\n/g;
$d =~ s{octet-stream\r\n\r\n.*?\r\n\r\n}{octet-stream\r\n\r\n$enc\r\n}s;
write_file("email2", $d);
Of course, in the resulting email there should be also a small fix of
boundary definition (see
http://rt.cpan.org/Ticket/Display.html?id=68964 ).
Some info about my system:
- perl 5, version 12, subversion 3 (v5.12.3) built for i686-linux;
built by perlbrew
- Courriel 0.12, installed on 2011-06-20 by cpanm with no problems
- OS: Slackware Linux, kernel 2.6.32.7 32bit, gcc 4.3.3