[Rt-commit] rt branch, 4.0/protect-more-chars-while-decoding-headers, updated. rt-4.0.6-222-g629fdf1

Ruslan Zakirov ruz at bestpractical.com
Thu Oct 18 18:56:34 EDT 2012


The branch, 4.0/protect-more-chars-while-decoding-headers has been updated
       via  629fdf1b6a4d1e527e00360026c765642bca2c88 (commit)
      from  70b8c951f1d908798e63eea711690b8fa75873c9 (commit)

Summary of changes:
 lib/RT/I18N.pm         |  2 +-
 t/mail/mime_decoding.t | 24 ++++++++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)

- Log -----------------------------------------------------------------
commit 629fdf1b6a4d1e527e00360026c765642bca2c88
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Fri Oct 19 02:32:38 2012 +0400

    fix our magic quoting after decoding Q/B
    
    We decode and if it's special field, eg formatted field
    like to/cc/content-*, then we try to be smart and put
    quotes around decoded part. This is required to keep
    the value still valid formatted field.
    
    Variants:
    
    1) 'xxx=<q/b string>', has no any quotes
    2) 'xxx=<q/b string>', quotes are inside of encoded string
    3) 'xxx="<q/b string>"', quotes are outside
    
    This fixes third case.

diff --git a/lib/RT/I18N.pm b/lib/RT/I18N.pm
index d57e715..af6f4df 100644
--- a/lib/RT/I18N.pm
+++ b/lib/RT/I18N.pm
@@ -357,7 +357,7 @@ sub DecodeMIMEWordsToEncoding {
             # already.
             $enc_str = qq{"$enc_str"}
                 if $enc_str =~ /[()<>\[\]:;@\\,.]/
-                and $enc_str !~ /^".*"$/
+                and not (($enc_str =~ /^"/ or $prefix =~ /"$/) and ($enc_str =~ /"$/ or $trailing =~ /^"/))
                 and (!$field || $field =~ /^(?:To$|From$|B?Cc$|Content-)/i);
 
             $str .= $prefix . $enc_str . $trailing;
diff --git a/t/mail/mime_decoding.t b/t/mail/mime_decoding.t
index 7515e2c..1243dff 100644
--- a/t/mail/mime_decoding.t
+++ b/t/mail/mime_decoding.t
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use strict;
 use warnings;
-use RT::Test nodb => 1, tests => 9;
+use RT::Test nodb => 1, tests => 13;
 
 use_ok('RT::I18N');
 
@@ -13,6 +13,11 @@ diag q{'=' char in a leading part before an encoded part};
         'key="plain"; key="мой_файл.bin"',
         "right decoding"
     );
+    is(
+        RT::I18N::DecodeMIMEWordsToUTF8($str, 'content-disposition'),
+        'key="plain"; key="мой_файл.bin"',
+        "right decoding"
+    );
 }
 
 diag q{not compliant with standards, but MUAs send such field when attachment has non-ascii in name};
@@ -23,6 +28,11 @@ diag q{not compliant with standards, but MUAs send such field when attachment ha
         'attachment; filename="мой_файл.bin"',
         "right decoding"
     );
+    is(
+        RT::I18N::DecodeMIMEWordsToUTF8($str, 'content-disposition'),
+        'attachment; filename="мой_файл.bin"',
+        "right decoding"
+    );
 }
 
 diag q{'=' char in a trailing part after an encoded part};
@@ -33,6 +43,11 @@ diag q{'=' char in a trailing part after an encoded part};
         'attachment; filename="мой_файл.bin"; some_prop="value"',
         "right decoding"
     );
+    is(
+        RT::I18N::DecodeMIMEWordsToUTF8($str, 'content-disposition'),
+        'attachment; filename="мой_файл.bin"; some_prop="value"',
+        "right decoding"
+    );
 }
 
 diag q{regression test for #5248 from rt3.fsck.com};
@@ -40,7 +55,7 @@ diag q{regression test for #5248 from rt3.fsck.com};
     my $str = qq{Subject: =?ISO-8859-1?Q?Re=3A_=5BXXXXXX=23269=5D_=5BComment=5D_Frag?=}
         . qq{\n =?ISO-8859-1?Q?e_zu_XXXXXX--xxxxxx_/_Xxxxx=FCxxxxxxxxxx?=};
     is(
-        RT::I18N::DecodeMIMEWordsToUTF8($str),
+        RT::I18N::DecodeMIMEWordsToUTF8($str, 'Subject'),
         qq{Subject: Re: [XXXXXX#269] [Comment] Frage zu XXXXXX--xxxxxx / Xxxxxüxxxxxxxxxx},
         "right decoding"
     );
@@ -54,6 +69,11 @@ diag q{newline and encoded file name};
         qq{application/vnd.ms-powerpoint;\tname="Main presentation.ppt"},
         "right decoding"
     );
+    is(
+        RT::I18N::DecodeMIMEWordsToUTF8($str,'content-type'),
+        qq{application/vnd.ms-powerpoint; name="Main presentation.ppt"},
+        "right decoding"
+    );
 }
 
 diag q{rfc2231};

-----------------------------------------------------------------------


More information about the Rt-commit mailing list