Subject: | Don't encode charset for attachments |
Hello,
This is follow-up to #68965, sorry if this comes 2nd time, I'm not
sure it arrived before...
Your fix seems to help a bit, but there is something else in the way.
I tried to investigate a bit and found out that Courriel::Part::Single
in _build_encoded_content_ref is trying first to encode content into
us-ascii (default charset) and then to base64-encode it. This is
probably OK with textual data (since it's in Perl's internal format
and should be dumped to something reasonable, e.g. UTF8). But all
attachments are just unknown (binary?) data read from disk and
shouldn't be encoded in any way.
Well that's probably enough of reasoning, this seems to solve all my
problems:
$ diff -urN Courriel/Part/Single.pm{.orig,}
--- Courriel/Part/Single.pm.orig 2011-06-23 00:28:08.295983349 +0200
+++ Courriel/Part/Single.pm 2011-06-23 00:43:38.063858612 +0200
@@ -161,10 +161,14 @@
my $encoding = $self->encoding();
- my $bytes = encode(
- $self->content_type()->charset(),
- $self->content(),
- );
+ my $bytes = $self->content();
+
+ if( ! $self->is_attachment()){
+ $bytes = encode(
+ $self->content_type()->charset(),
+ $self->content(),
+ );
+ }
return \$bytes if $unencoded{ lc $encoding };
With this change I am able to attach any file (test program below),
send it via few servers and correctly decode afterwards. I tested few
small text files, some UTF8-encoded text files, some binaries from my
system... everything worked :)
Test program:
#!/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/bash",
mime_type => "application/octet-stream",
),
);
write_file("email", $e->as_string);
Please look at the diff, what do you think?
Thank you
ico