[rt-devel] RT3: mail UTF-8 automatic conversion and GPG verification

Guillaume Perréal perreal at lyon.cemagref.fr
Wed Aug 27 12:05:41 EDT 2003


Jesse Vincent wrote :

>I'd love to see your changes. Also, with your changes, does RT still
>pass a "make regression"? 
>
Modified rt-3-0-5pre4 fails one test, concerning a nested rfc822 message :

ok 943 - Loaded nested-rfc-822 to test
ok 944 - It is a mixed multipart
ok 945 - found ticket 29
not ok 946
#     Failed test (/home/rt3-devel/lib/t/04_send_email.pl at line 370)
#          got: '[Jonas Liljegren] Re: [Para] =?iso-8859-1?q?Niv=E5er=3F?='
#     expected: '[Jonas Liljegren] Re: [Para] Niv?r?'
ok 947 - We recorded the content type right
ok 948 - Has one attachment, presumably a text-plain and a message RFC 822 and another plain

I join a diff of my changes. Maybe someone could tell me if I made an 
obvious error...

Thanks.
--
Guillaume Perréal.
-------------- next part --------------
diff -ur rt-3-0-5pre4-orig/lib/RT/EmailParser.pm rt-3-0-5pre4/lib/RT/EmailParser.pm
--- rt-3-0-5pre4-orig/lib/RT/EmailParser.pm	2003-08-24 23:16:21.000000000 +0200
+++ rt-3-0-5pre4/lib/RT/EmailParser.pm	2003-08-27 17:41:08.000000000 +0200
@@ -275,10 +275,19 @@
     my $self = shift;
 
     #Now we've got a parsed mime object. 
-
-    # try to convert text parts into utf-8 charset
-    RT::I18N::SetMIMEEntityToEncoding($self->{'entity'}, 'utf-8');
-
+    
+    # We do not want to modify the body because it will broke some
+    # OpenPGP/SMIME signatures but main headers are never included in signed
+    # data (as they are modified by every MTA that handles the message), so we
+    # can work on this. Body encoding translation are postponed after email
+    # authentication.
+    
+    # Force headers to UTF-8 charset
+    RT::I18N::SetMIMEHeadToEncoding(
+	$self->Head,
+	RT::I18N::_FindOrGuessCharset($self->Entity) => 'utf-8',
+	1
+    );
 
     # Unfold headers that are have embedded newlines
     $self->Head->unfold;
diff -ur rt-3-0-5pre4-orig/lib/RT/Interface/Email.pm rt-3-0-5pre4/lib/RT/Interface/Email.pm
--- rt-3-0-5pre4-orig/lib/RT/Interface/Email.pm	2003-08-24 23:16:21.000000000 +0200
+++ rt-3-0-5pre4/lib/RT/Interface/Email.pm	2003-08-26 15:18:31.000000000 +0200
@@ -416,6 +416,7 @@
 
     my $MessageId = $head->get('Message-Id')
       || "<no-message-id-" . time . rand(2000) . "\@.$RT::Organization>";
+    chomp $MessageId;
 
     #Pull apart the subject line
     my $Subject = $head->get('Subject') || '';
@@ -456,6 +457,7 @@
     for (@RT::MailPlugins) {
         my $Code;
         my $NewAuthStat;
+	my $NewCurrentUser;  
         if ( ref($_) eq "CODE" ) {
             $Code = $_;
         }
@@ -473,17 +475,27 @@
             }
         }
 
-        ( $CurrentUser, $NewAuthStat ) = $Code->( Message     => $Message,
+        ( $NewCurrentUser, $NewAuthStat ) = $Code->( Message     => $Message,
                                                   CurrentUser => $CurrentUser,
                                                   AuthLevel   => $AuthStat,
                                                   Action => $args{'action'},
                                                   Ticket => $SystemTicket,
-                                                  Queue  => $SystemQueueObj );
+                                                  Queue  => $SystemQueueObj,
+						  # Give more args than from original gateway:
+						  # - original, untouched message (for signature verification)
+						  # passed as a ref to save memory (don't know how perl could optimize this)
+						  RawMessage => \$args{'message'},
+						  # - save plug-ins from extracting these:
+						  ErrorsTo  => $ErrorsTo,
+						  Subject   => $Subject,
+						  MessageId => $MessageId,
+						  );
 
 	# If a module returns a "-1" then we discard the ticket, so.
         $AuthStat = -1 if $NewAuthStat == -1;
         # You get the highest level of authentication you were assigned.
-        $AuthStat = $NewAuthStat if $NewAuthStat > $AuthStat;
+	# and only erase $CurrentUser if new level is equal or greater than the old one.
+        ($AuthStat, $CurrentUser) = ($NewAuthStat, $NewCurrentUser) if $NewAuthStat >= $AuthStat;
         last if $AuthStat == -1;
     }
 
@@ -523,6 +535,9 @@
     }
 
     # }}}
+    
+    # Ok, now we can convert the full message to UTF-8
+    RT::I18N::SetMIMEEntityToUTF8($Message);
 
     # {{{ Lets check for mail loops of various sorts.
     my $IsAutoGenerated = CheckForAutoGenerated($head);


More information about the Rt-devel mailing list