X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=rt%2Flib%2FRT%2FTemplate.pm;h=a6c0f7d0b290bba5951a83ce1135f80435d9074b;hb=ed1f84b4e8f626245995ecda5afcf83092c153b2;hp=fd4b511e9fefd7999df54859db8c983a0d7b9ec2;hpb=3d0a1bb06b895c5be6e3f0517d355442a6b1e125;p=freeside.git diff --git a/rt/lib/RT/Template.pm b/rt/lib/RT/Template.pm index fd4b511e9..a6c0f7d0b 100755 --- a/rt/lib/RT/Template.pm +++ b/rt/lib/RT/Template.pm @@ -2,7 +2,7 @@ # # COPYRIGHT: # -# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC +# This software is Copyright (c) 1996-2014 Best Practical Solutions, LLC # # # (Except where explicitly superseded by other copyright notices) @@ -256,7 +256,7 @@ sub Create { $args{'Queue'} = $QueueObj->Id; } - my $result = $self->SUPER::Create( + my ( $result, $msg ) = $self->SUPER::Create( Content => $args{'Content'}, Queue => $args{'Queue'}, Description => $args{'Description'}, @@ -264,7 +264,11 @@ sub Create { Type => $args{'Type'}, ); - return ($result); + if ( wantarray ) { + return ( $result, $msg ); + } else { + return ( $result ); + } } @@ -303,10 +307,9 @@ sub IsEmpty { Returns L object parsed using L method. Returns undef if last call to L failed or never be called. -Note that content of the template is UTF-8, but L is not -good at handling it and all data of the entity should be treated as -octets and converted to perl strings using Encode::decode_utf8 or -something else. +Note that content of the template is characters, but the contents of all +L objects (including the one returned by this function, +are bytes in UTF-8. =cut @@ -380,8 +383,8 @@ sub _Parse { ### Should we forgive normally-fatal errors? $parser->ignore_errors(1); - # MIME::Parser doesn't play well with perl strings - utf8::encode($content); + # Always provide bytes, not characters, to MIME objects + $content = Encode::encode( 'UTF-8', $content ); $self->{'MIMEObj'} = eval { $parser->parse_data( \$content ) }; if ( my $error = $@ || $parser->last_error ) { $RT::Logger->error( "$error" ); @@ -466,6 +469,12 @@ sub _ParseContentPerl { TYPE => 'STRING', SOURCE => $args{Content}, ); + my ($ok) = $template->compile; + unless ($ok) { + $RT::Logger->error("Template parsing error in @{[$self->Name]} (#@{[$self->id]}): $Text::Template::ERROR"); + return ( undef, $self->loc('Template parsing error: [_1]', $Text::Template::ERROR) ); + } + my $is_broken = 0; my $retval = $template->fill_in( HASH => $args{TemplateArgs}, @@ -592,17 +601,17 @@ sub _DowngradeFromHTML { require HTML::FormatText; require HTML::TreeBuilder; - require Encode; - # need to decode_utf8, see the doc of MIMEObj method + # MIME objects are always bytes, not characters my $tree = HTML::TreeBuilder->new_from_content( - Encode::decode_utf8($new_entity->bodyhandle->as_string) + Encode::decode( 'UTF-8', $new_entity->bodyhandle->as_string) ); - $new_entity->bodyhandle(MIME::Body::InCore->new( - \(scalar HTML::FormatText->new( - leftmargin => 0, - rightmargin => 78, - )->format( $tree )) - )); + my $text = HTML::FormatText->new( + leftmargin => 0, + rightmargin => 78, + )->format( $tree ); + $text = Encode::encode( "UTF-8", $text ); + + $new_entity->bodyhandle(MIME::Body::InCore->new( \$text )); $tree->delete; $orig_entity->add_part($new_entity, 0); # plain comes before html