Skip Menu |

This queue is for tickets about the Courriel CPAN distribution.

Report information
The Basics
Id: 69085
Status: resolved
Priority: 0/
Queue: Courriel

People
Owner: Nobody in particular
Requestors: ico [...] petrzalka.net
icovnik [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.13
Fixed in: 0.14



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
CC: Ico <ico [...] petrzalka.net>
Subject: Don't encode charset for attachments
Date: Fri, 24 Jun 2011 11:33:10 +0200
To: bug-Courriel [...] rt.cpan.org
From: icovnik <icovnik [...] gmail.com>
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
Subject: Re: [rt.cpan.org #69148] Don't encode charset for attachments
Date: Tue, 28 Jun 2011 14:05:18 -0500 (CDT)
To: ico via RT <bug-Courriel [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Tue, 28 Jun 2011, ico via RT wrote: Show quoted text
> $ 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(), > + ); > + }
What version are you looking at? This code has changed in 0.14, so I think you're looking at something earlier. Thanks, -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
From: ico [...] petrzalka.net
On Tue Jun 28 15:05:27 2011, autarch@urth.org wrote: Show quoted text
> On Tue, 28 Jun 2011, ico via RT wrote: >
> > $ 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(), > > + ); > > + }
> > What version are you looking at? This code has changed in 0.14, so I > think > you're looking at something earlier.
Yes you're right. I reporeted the same thing twice - first by email (but that didn't work, or it looked like it didn't work), then directly in RT. 2 days after that the email arrived and created another ticket #69085. I am sorry for the duplication. The original bug report was for version 0.13. Now I tested the new version 0.15 and your code fixed all my failing code with attachments. Please close this bug #69148 and also the copy #69085 as fixed. Thank you. ico