[Rt-commit] r13513 - in rt/3.8/trunk: . lib/RT

ruz at bestpractical.com ruz at bestpractical.com
Fri Jun 20 23:55:18 EDT 2008


Author: ruz
Date: Fri Jun 20 23:55:18 2008
New Revision: 13513

Modified:
   rt/3.8/trunk/   (props changed)
   rt/3.8/trunk/lib/RT/Action/SendEmail.pm
   rt/3.8/trunk/lib/RT/Template_Overlay.pm

Log:
merge non-ascii subject branch

 r13513 at cubic-pc (orig r13469):  ruz | 2008-06-20 23:45:42 +0400
 * branch to fix problems with non-ascii subjects, subject tags, templates
 r13552 at cubic-pc (orig r13508):  ruz | 2008-06-21 07:13:04 +0400
 * minor
 r13553 at cubic-pc (orig r13509):  ruz | 2008-06-21 07:16:23 +0400
 * ok, MIME::Parser is not aware about perl strings, so we use octets.
   What means that we must treat MIME's content as octets everywhere
   and use Encode::decode_utf8
 r13554 at cubic-pc (orig r13510):  ruz | 2008-06-21 07:18:31 +0400
 * data in template's MIME entity is not always perl string, so
   we must decode it first before using
 r13555 at cubic-pc (orig r13511):  ruz | 2008-06-21 07:23:01 +0400
 * add docs
 r13556 at cubic-pc (orig r13512):  ruz | 2008-06-21 07:23:34 +0400
 * minor


Modified: rt/3.8/trunk/lib/RT/Action/SendEmail.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Action/SendEmail.pm	(original)
+++ rt/3.8/trunk/lib/RT/Action/SendEmail.pm	Fri Jun 20 23:55:18 2008
@@ -889,15 +889,16 @@
 
     chomp $val;
     chomp $field;
-    $self->TemplateObj->MIMEObj->head->fold_length( $field, 10000 );
-    $self->TemplateObj->MIMEObj->head->replace( $field, $val );
-    return $self->TemplateObj->MIMEObj->head->get($field);
+    my $head = $self->TemplateObj->MIMEObj->head;
+    $head->fold_length( $field, 10000 );
+    $head->replace( $field, $val );
+    return $head->get($field);
 }
 
 =head2 SetSubject
 
-This routine sets the subject. it does not add the rt tag. that gets done elsewhere
-If $self->{'Subject'} is already defined, it uses that. otherwise, it tries to get
+This routine sets the subject. it does not add the rt tag. That gets done elsewhere
+If subject is already defined via template, it uses that. otherwise, it tries to get
 the transaction's subject.
 
 =cut 
@@ -937,9 +938,10 @@
 sub SetSubjectToken {
     my $self = shift;
 
-    $self->TemplateObj->MIMEObj->head->replace(
+    my $head = $self->TemplateObj->MIMEObj->head;
+    $head->replace(
         Subject => RT::Interface::Email::AddSubjectTag(
-            $self->TemplateObj->MIMEObj->head->get('Subject'),
+            Encode::decode_utf8( $head->get('Subject') ),
             $self->TicketObj,
         ),
     );
@@ -1041,17 +1043,16 @@
     my $self = shift;
     my ( $field, $enc ) = ( shift, shift );
 
-    if ( $field eq 'From' and RT->Config->Get('SMTPFrom') ) {
-        $self->TemplateObj->MIMEObj->head->replace( $field,
-            RT->Config->Get('SMTPFrom') );
+    my $head = $self->TemplateObj->MIMEObj->head;
+
+    if ( lc($field) eq 'from' and RT->Config->Get('SMTPFrom') ) {
+        $head->replace( $field, RT->Config->Get('SMTPFrom') );
         return;
     }
 
-    my $value = $self->TemplateObj->MIMEObj->head->get($field);
-
+    my $value = $head->get( $field );
     $value = $self->MIMEEncodeString( $value, $enc );
-
-    $self->TemplateObj->MIMEObj->head->replace( $field, $value );
+    $head->replace( $field, $value );
 
 }
 

Modified: rt/3.8/trunk/lib/RT/Template_Overlay.pm
==============================================================================
--- rt/3.8/trunk/lib/RT/Template_Overlay.pm	(original)
+++ rt/3.8/trunk/lib/RT/Template_Overlay.pm	Fri Jun 20 23:55:18 2008
@@ -272,6 +272,11 @@
 Returns L<MIME::Entity> object parsed using L</Parse> method. Returns
 undef if last call to L</Parse> failed or never be called.
 
+Note that content of the template is UTF-8, but L<MIME::Parser> 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.
+
 =cut
 
 sub MIMEObj {
@@ -351,7 +356,9 @@
 
     ### Should we forgive normally-fatal errors?
     $parser->ignore_errors(1);
-    $self->{'MIMEObj'} = eval { $parser->parse_data($content) };
+    # MIME::Parser doesn't play well with perl strings
+    utf8::encode($content);
+    $self->{'MIMEObj'} = eval { $parser->parse_data( \$content ) };
     if ( my $error = $@ || $parser->last_error ) {
         $RT::Logger->error( "$error" );
         return ( 0, $error );
@@ -425,8 +432,6 @@
     );
     return ( undef, $self->loc('Template parsing error') ) if $is_broken;
 
-    # MIME::Parser has problems dealing with high-bit utf8 data.
-    Encode::_utf8_off($retval);
     return ($retval);
 }
 


More information about the Rt-commit mailing list