Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Catalyst-View-Email CPAN distribution.

Report information
The Basics
Id:
56391
Status:
resolved
Priority:
Low/Low

People
Owner:
devin.austin [...] gmail.com
Requestors:
gernotk [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
(no value)
Broken in:
(no value)
Fixed in:
(no value)



Subject: Catalyst::View::Email::Template: Body of MIME-Parts not encoded properly
Date: Thu, 08 Apr 2010 16:08:23 +0200
To: bug-Catalyst-View-Email@rt.cpan.org
From: Gernot Kieseritzky <gernotk@gmail.com>
In 'C::V::Email::Template::generate_part' the result of '$output = $view->render' is passed to 'Email::MIME->create' without character set encoding although '$output' is a Perl string and therefore not encoded. I suggest the following patch: @@ -227,5 +227,5 @@ return Email::MIME->create( attributes => $e_m_attrs, - body => $output, + body_str => $output ); } 'body_str' will trigger the 'body_str'-setter in Email::MIME and encode the message body according to the specified character set. There is also a related issue. As of version 0.27 C::V::Email neither supports specifying a transfer encoding type nor recognizes a default transfer encoding: It always assumes 7-bit ASCII. However, if 'body' contains characters > 128 they must be encoded using 'quoted_printable', 'base64' or '8bit' as is actually supported by Email::MIME. I suggest therefore the following patch: @@ -274,4 +274,5 @@ $mime{attributes}->{content_type} = $email->{content_type} if $email->{content_type}; + if ( $mime{attributes} and not $mime{attributes}->{charset} @@ -281,4 +282,7 @@ } + $mime{attributes}->{encoding} = $email->{encoding} + if $email->{encoding}; + my $message = $self->generate_message( $c, \%mime ); @@ -309,4 +313,5 @@ my $default_content_type = $self->default->{content_type}; my $default_charset = $self->default->{charset}; + my $default_encoding = $self->default->{encoding}; my $e_m_attrs = {}; @@ -339,4 +344,22 @@ } + if ( exists $attrs->{encoding} + && defined $attrs->{encoding} + && $attrs->{encoding} ne '' ) + { + $c->log->debug( + 'C::V::Email uses specified encoding ' + . $attrs->{encoding} + . '.' ) + if $c->debug; + $e_m_attrs->{encoding} = $attrs->{encoding}; + } + elsif ( defined $default_encoding && $default_encoding ne '' ) { + $c->log->debug( + "C::V::Email uses default encoding $default_encoding.") + if $c->debug; + $e_m_attrs->{encoding} = $default_encoding; + } + return $e_m_attrs; } Thanks, Gernot Kieseritzky
On Thu Apr 08 10:08:40 2010, gernotk@gmail.com wrote:
Show quoted text
> In 'C::V::Email::Template::generate_part' the result of '$output = > $view->render' is passed to 'Email::MIME->create' without character set > encoding although '$output' is a Perl string and therefore not encoded. > I suggest the following patch: > > @@ -227,5 +227,5 @@ > return Email::MIME->create( > attributes => $e_m_attrs, > - body => $output, > + body_str => $output > ); > } > > 'body_str' will trigger the 'body_str'-setter in Email::MIME and encode > the message body according to the specified character set. > > There is also a related issue. As of version 0.27 C::V::Email neither > supports specifying a transfer encoding type nor recognizes a default > transfer encoding: It always assumes 7-bit ASCII. However, if 'body' > contains characters > 128 they must be encoded using 'quoted_printable', > 'base64' or '8bit' as is actually supported by Email::MIME. > > I suggest therefore the following patch: > > @@ -274,4 +274,5 @@ > $mime{attributes}->{content_type} = $email->{content_type} > if $email->{content_type}; > + > if ( $mime{attributes} > and not $mime{attributes}->{charset} > @@ -281,4 +282,7 @@ > } > > + $mime{attributes}->{encoding} = $email->{encoding} > + if $email->{encoding}; > + > my $message = $self->generate_message( $c, \%mime ); > > @@ -309,4 +313,5 @@ > my $default_content_type = $self->default->{content_type}; > my $default_charset = $self->default->{charset}; > + my $default_encoding = $self->default->{encoding}; > > my $e_m_attrs = {}; > @@ -339,4 +344,22 @@ > } > > + if ( exists $attrs->{encoding} > + && defined $attrs->{encoding} > + && $attrs->{encoding} ne '' ) > + { > + $c->log->debug( > + 'C::V::Email uses specified encoding ' > + . $attrs->{encoding} > + . '.' ) > + if $c->debug; > + $e_m_attrs->{encoding} = $attrs->{encoding}; > + } > + elsif ( defined $default_encoding && $default_encoding ne '' ) { > + $c->log->debug( > + "C::V::Email uses default encoding $default_encoding.") > + if $c->debug; > + $e_m_attrs->{encoding} = $default_encoding; > + } > + > return $e_m_attrs; > } > > Thanks, > Gernot Kieseritzky >
Hi, Thanks for the patches, can I get test cases for these so I can patch and put together another dist? Thanks, -Devin
Test and patch for handling encoding and charset, if set. To avoid wide chars print. Tested for backward compatiblity.
Subject: encoding.patch
Index: t/08encoding.t =================================================================== --- t/08encoding.t (Revision 0) +++ t/08encoding.t (Revision 0) @@ -0,0 +1,27 @@ +use strict; +use warnings; + +BEGIN { $ENV{EMAIL_SENDER_TRANSPORT} = 'Print' } +use Test::More; +use Test::Warn; + +use Test::Requires { + 'Catalyst::View::TT' => '0.31', +}; +use Email::Sender::Simple; +use FindBin; +use lib "$FindBin::Bin/lib"; + +use_ok('Catalyst::Test', 'TestApp'); + +my $response; +my $time = time; + +# Testk without wide chars +warning_is { $response = request("/template_email?time=$time") } [],"Without wide chars?" ; + +# Test with unicode chars +warning_is { $response = request("/template_email_utf8?time=$time") } [],"With wide chars" ; + + +done_testing(); Index: t/root/text_html/test_utf8.tt =================================================================== --- t/root/text_html/test_utf8.tt (Revision 0) +++ t/root/text_html/test_utf8.tt (Revision 0) @@ -0,0 +1,7 @@ +<html> + <body> + <h1>Look at my style</h1> + <p>I was sent to <em>[% $stash_key.to %]</em> on [% time %] with some unicode characters ✈ ✉ ✔ inline and some in the stash [% chars %]</p> + </body> +</html> + Index: t/lib/TestApp/Controller/Root.pm =================================================================== --- t/lib/TestApp/Controller/Root.pm (Revision 13873) +++ t/lib/TestApp/Controller/Root.pm (Arbeitskopie) @@ -3,6 +3,8 @@ use base qw(Catalyst::Controller); +use Encode; + sub default : Private { my ( $self, $c ) = @_; @@ -86,6 +88,47 @@ } } +sub template_email_utf8 : Global('template_email_utf8') { + my ($self, $c, @args) = @_; + + $c->stash->{time} = $c->req->params->{time} || time; + + $c->stash->{chars} = decode('utf-8', "✔ ✈ ✉"); + + $c->stash->{email} = { + to => 'test-email@example.com', + from => 'no-reply@example.com', + subject => 'Just a test', + content_type => 'multipart/alternative', + templates => [ + { + template => 'text_plain/test.tt', + content_type => 'text/plain', + charset => 'utf-8', + encoding => 'quoted-printable', + }, + { + view => 'TT', + template => 'text_html/test_utf8.tt', + content_type => 'text/html', + charset => 'utf-8', + encoding => 'quoted-printable', + }, + ], + }; + + $c->forward('TestApp::View::Email::Template'); + + if ( scalar( @{ $c->error } ) ) { + $c->res->status(500); + $c->res->body('Template Email Failed'); + } else { + $c->res->body('Template Email Ok'); + } +} + + + sub template_email_app_config : Global('template_email_app_config') { my ($self, $c, @args) = @_; Index: lib/Catalyst/View/Email.pm =================================================================== --- lib/Catalyst/View/Email.pm (Revision 13873) +++ lib/Catalyst/View/Email.pm (Arbeitskopie) @@ -280,6 +280,9 @@ $mime{attributes}->{charset} = $self->{default}->{charset}; } + $mime{attributes}->{encoding} = $email->{encoding} + if $email->{encoding}; + my $message = $self->generate_message( $c, \%mime ); if ($message) { @@ -307,7 +310,8 @@ my ( $self, $c, $attrs ) = @_; my $default_content_type = $self->default->{content_type}; - my $default_charset = $self->default->{charset}; + my $default_charset = $self->default->{charset}; + my $default_encoding = $self->default->{encoding}; my $e_m_attrs = {}; @@ -338,6 +342,24 @@ $e_m_attrs->{charset} = $default_charset; } + if ( exists $attrs->{encoding} + && defined $attrs->{encoding} + && $attrs->{encoding} ne '' ) + { + $c->log->debug( + 'C::V::Email uses specified encoding ' + . $attrs->{encoding} + . '.' ) + if $c->debug; + $e_m_attrs->{encoding} = $attrs->{encoding}; + } + elsif ( defined $default_encoding && $default_encoding ne '' ) { + $c->log->debug( + "C::V::Email uses default encoding $default_encoding.") + if $c->debug; + $e_m_attrs->{encoding} = $default_encoding; + } + return $e_m_attrs; } Index: lib/Catalyst/View/Email/Template.pm =================================================================== --- lib/Catalyst/View/Email/Template.pm (Revision 13873) +++ lib/Catalyst/View/Email/Template.pm (Arbeitskopie) @@ -167,7 +167,7 @@ my $template_prefix = $self->template_prefix; my $default_view = $self->default->{view}; my $default_content_type = $self->default->{content_type}; - my $default_charset = $self->default->{charset}; + my $default_charset = $self->default->{charset}; my $view; @@ -224,10 +224,23 @@ croak $output->can('as_string') ? $output->as_string : $output; } - return Email::MIME->create( - attributes => $e_m_attrs, - body => $output, - ); + if ( exists $e_m_attrs->{encoding} + && defined $e_m_attrs->{encoding} + && exists $e_m_attrs->{charset} + && defined $e_m_attrs->{charset} ) { + + return Email::MIME->create( + attributes => $e_m_attrs, + body_str => $output, + ); + + } else { + + return Email::MIME->create( + attributes => $e_m_attrs, + body => $output, + ); + } } =item process @@ -268,7 +281,8 @@ template => $part->{template}, content_type => $part->{content_type}, charset => $part->{charset}, - } + encoding => $part->{encoding}, + } ); } } Index: META.yml =================================================================== --- META.yml (Revision 13873) +++ META.yml (Arbeitskopie) @@ -6,10 +6,11 @@ build_requires: ExtUtils::MakeMaker: 6.42 Test::More: 0 + Test::Requires: 0 configure_requires: ExtUtils::MakeMaker: 6.42 distribution_type: module -generated_by: 'Module::Install version 0.97' +generated_by: 'Module::Install version 1.00' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -22,31 +23,29 @@ provides: Catalyst::Helper::View::Email: file: lib/Catalyst/Helper/View/Email.pm - version: 0.28 + version: 0.30 Catalyst::Helper::View::Email::Template: file: lib/Catalyst/Helper/View/Email/Template.pm - version: 0.28 + version: 0.30 Catalyst::View::Email: file: lib/Catalyst/View/Email.pm - version: 0.28 + version: 0.30 Catalyst::View::Email::Template: file: lib/Catalyst/View/Email/Template.pm - version: 0.28 + version: 0.30 requires: Authen::SASL: 2.13 Catalyst: 5.7 - Catalyst::View::Mason: 0.18 - Catalyst::View::TT: 0.31 Email::MIME: 1.859 Email::MIME::Creator: 1.455 Email::Sender::Simple: 0.100110 MIME::Base64: 3.08 Moose: 0.93 - Test::More: 0 + Test::More: 0.88 parent: 0.223 resources: IRC: irc://irc.perl.org/#catalyst MailingList: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst license: http://dev.perl.org/licenses/ repository: http://dev.catalyst.perl.org/repos/Catalyst/Catalyst-View-Email/ -version: 0.28 +version: 0.30
On Mon Dec 20 08:36:29 2010, JEGADE wrote:
Show quoted text
> Test and patch for handling encoding and charset, if set. To avoid wide > chars print. Tested for backward compatiblity. >
This has been applied.


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.