[Rt-commit] rt branch, decode_words_rework, updated. rt-3.8.7-372-g5b9cc9c

Ruslan Zakirov ruz at bestpractical.com
Wed Apr 28 11:31:27 EDT 2010


The branch, decode_words_rework has been updated
       via  5b9cc9cc62de3434a2034a173529caa44b931b60 (commit)
       via  6f79935cf4954945b4e665de32c2b3c0beba1268 (commit)
       via  6eff0bf322514d17aad350fe6f8feb3a127f1500 (commit)
       via  01fa70cbbec4fc5914b1978c693d459b40266f23 (commit)
       via  8d1edfb9c65950a1e128c763a5cfa4011e1523e5 (commit)
       via  ceae04d45e780051107bd12f012e47281cd65807 (commit)
      from  725318d62ce99aee6fe4eeb0a151fb9315d12b34 (commit)

Summary of changes:
 lib/RT/I18N.pm |   31 +++++++++++++++++++------------
 1 files changed, 19 insertions(+), 12 deletions(-)

- Log -----------------------------------------------------------------
commit ceae04d45e780051107bd12f012e47281cd65807
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Apr 28 03:21:03 2010 +0400

    don't use @_, but 'my @list', very confusing

diff --git a/lib/RT/I18N.pm b/lib/RT/I18N.pm
index 7f56886..e52db2c 100755
--- a/lib/RT/I18N.pm
+++ b/lib/RT/I18N.pm
@@ -311,17 +311,18 @@ sub DecodeMIMEWordsToEncoding {
     my $str = shift;
     my $enc = shift;
 
-    @_ = $str =~ m/(.*?)=\?([^?]+)\?([QqBb])\?([^?]+)\?=([^=]*)/gcs;
-    return ($str) unless (@_);
+    my @list = $str =~ m/(.*?)=\?([^?]+)\?([QqBb])\?([^?]+)\?=([^=]*)/gcs;
+    return ($str) unless (@list);
 
     # add everything that hasn't matched to the end of the latest
     # string in array this happen when we have 'key="=?encoded?="; key="plain"'
-    $_[-1] .= substr($str, pos $str);
+    $list[-1] .= substr($str, pos $str);
 
     $str = "";
-    while (@_) {
+    while (@list) {
 	my ($prefix, $charset, $encoding, $enc_str, $trailing) =
-	    (shift, shift, lc shift, shift, shift);
+            splice @list, 0, 5;
+        $encoding = lc $encoding;
 
         $trailing =~ s/\s?\t?$//;               # Observed from Outlook Express
 

commit 8d1edfb9c65950a1e128c763a5cfa4011e1523e5
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Apr 28 03:22:41 2010 +0400

    pass rest from DecodeMIMEWordsToUTF8 further and use explicit return

diff --git a/lib/RT/I18N.pm b/lib/RT/I18N.pm
index e52db2c..bdb7416 100755
--- a/lib/RT/I18N.pm
+++ b/lib/RT/I18N.pm
@@ -304,7 +304,7 @@ tried.  Maybe it's ok now.
 
 sub DecodeMIMEWordsToUTF8 {
     my $str = shift;
-    DecodeMIMEWordsToEncoding($str, 'utf-8');
+    return DecodeMIMEWordsToEncoding($str, 'utf-8', @_);
 }
 
 sub DecodeMIMEWordsToEncoding {

commit 01fa70cbbec4fc5914b1978c693d459b40266f23
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Apr 28 03:44:10 2010 +0400

    localize $@ as we don't throw it further

diff --git a/lib/RT/I18N.pm b/lib/RT/I18N.pm
index bdb7416..b515f1b 100755
--- a/lib/RT/I18N.pm
+++ b/lib/RT/I18N.pm
@@ -340,7 +340,8 @@ sub DecodeMIMEWordsToEncoding {
 
 	# now we have got a decoded subject, try to convert into the encoding
 	unless ($charset eq $enc) {
-	    eval { Encode::from_to($enc_str, $charset,  $enc) };
+            local $@;
+	    eval { Encode::from_to($enc_str, $charset, $enc) };
 	    if ($@) {
 		$charset = _GuessCharset( $enc_str );
 		Encode::from_to($enc_str, $charset, $enc);

commit 6eff0bf322514d17aad350fe6f8feb3a127f1500
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Apr 28 03:47:49 2010 +0400

    $enc and $encoding are confusing => s/enc/to_charset/

diff --git a/lib/RT/I18N.pm b/lib/RT/I18N.pm
index b515f1b..5c6cd6d 100755
--- a/lib/RT/I18N.pm
+++ b/lib/RT/I18N.pm
@@ -309,7 +309,7 @@ sub DecodeMIMEWordsToUTF8 {
 
 sub DecodeMIMEWordsToEncoding {
     my $str = shift;
-    my $enc = shift;
+    my $to_charset = shift;
 
     my @list = $str =~ m/(.*?)=\?([^?]+)\?([QqBb])\?([^?]+)\?=([^=]*)/gcs;
     return ($str) unless (@list);
@@ -339,12 +339,12 @@ sub DecodeMIMEWordsToEncoding {
 	}
 
 	# now we have got a decoded subject, try to convert into the encoding
-	unless ($charset eq $enc) {
+	unless ($charset eq $to_charset) {
             local $@;
-	    eval { Encode::from_to($enc_str, $charset, $enc) };
+	    eval { Encode::from_to($enc_str, $charset, $to_charset) };
 	    if ($@) {
 		$charset = _GuessCharset( $enc_str );
-		Encode::from_to($enc_str, $charset, $enc);
+		Encode::from_to($enc_str, $charset, $to_charset);
 	    }
 	}
 

commit 6f79935cf4954945b4e665de32c2b3c0beba1268
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Apr 28 18:37:12 2010 +0400

    DecodeMIMEWordsToEncoding: apply quoting trick only to some fields
    
    take name of header field as third argument

diff --git a/lib/RT/I18N.pm b/lib/RT/I18N.pm
index 5c6cd6d..c30d600 100755
--- a/lib/RT/I18N.pm
+++ b/lib/RT/I18N.pm
@@ -310,6 +310,7 @@ sub DecodeMIMEWordsToUTF8 {
 sub DecodeMIMEWordsToEncoding {
     my $str = shift;
     my $to_charset = shift;
+    my $field = shift || '';
 
     my @list = $str =~ m/(.*?)=\?([^?]+)\?([QqBb])\?([^?]+)\?=([^=]*)/gcs;
     return ($str) unless (@list);
@@ -364,7 +365,10 @@ sub DecodeMIMEWordsToEncoding {
         # Some _other_ MUAs encode quotes _already_, and double quotes
         # confuse us a lot, so only quote it if it isn't quoted
         # already.
-        $enc_str = qq{"$enc_str"} if $enc_str =~ /[,;]/ and $enc_str !~ /^".*"$/;
+        $enc_str = qq{"$enc_str"}
+            if $enc_str =~ /[,;]/
+            and $enc_str !~ /^".*"$/
+            and (!$field || $field =~ /^(?:To$|From$|B?Cc$|Content-)/i);
 
 	$str .= $prefix . $enc_str . $trailing;
     }

commit 5b9cc9cc62de3434a2034a173529caa44b931b60
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Apr 28 18:39:12 2010 +0400

    pass header name into DecodeMIMEWordsTo*

diff --git a/lib/RT/I18N.pm b/lib/RT/I18N.pm
index c30d600..48dee4c 100755
--- a/lib/RT/I18N.pm
+++ b/lib/RT/I18N.pm
@@ -508,7 +508,8 @@ sub SetMIMEHeadToEncoding {
                     }
                 }
             }
-            $value = DecodeMIMEWordsToEncoding( $value, $enc ) unless $preserve_words;
+            $value = DecodeMIMEWordsToEncoding( $value, $enc, $tag )
+                unless $preserve_words;
             $head->add( $tag, $value );
         }
     }

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


More information about the Rt-commit mailing list