mhonarc-commits
[Top] [All Lists]

CVS: mhonarc/MHonArc/lib readmail.pl,2.38,2.39

2011-01-01 16:33:22
Update of mhonarc/MHonArc/lib
Modified Files:
	readmail.pl 
Log Message:
Bug #20074: Text-encoding/decoding of non-ASCII encoded
header text is now a post-processing after raw parsing
of header is done.  This way, the decoding function works
against an unfolded string, so handling of whitespace between
two encoded atoms is handled correctly.


======================================================================
FILE: mhonarc/MHonArc/lib/readmail.pl
<http://www.mhonarc.org/cgi-bin/viewcvs.cgi/*checkout*/mhonarc/MHonArc/lib/readmail.pl?rev=2.39>

<http://www.mhonarc.org/cgi-bin/viewcvs.cgi/mhonarc/MHonArc/lib/readmail.pl.diff?r1=2.38&r2=2.39&diff_format=h>
--- readmail.pl	20 Dec 2005 20:54:50 -0000	2.38
+++ readmail.pl	1 Jan 2011 22:33:19 -0000	2.39
@@ -843,6 +843,4 @@
     my($value, $tmp, $pos);
 
-    my $encfunc = load_textencoder();
-
     ## Read a line at a time.
     for ($pos=0; $pos >= 0; ) {
@@ -861,11 +859,4 @@
         }
 
-        ## Decode text if requested
-        if (defined($encfunc)) {
-            $tmp = &MAILdecode_1522_str($tmp,TEXT_ENCODE);
-        } elsif ($DecodeHeader) {
-            $tmp = &MAILdecode_1522_str($tmp,JUST_DECODE);
-        }
-
         ## Check for continuation of a field
         if ($tmp =~ /^\s/) {
@@ -884,4 +875,5 @@
         }
     }
+    decode_1522_fields($fields);
     ($fields, $header);
 }
@@ -898,6 +890,4 @@
     my $encode = shift;
 
-    my $encfunc = load_textencoder();
-
     my $label  = '';
     my $header = '';
@@ -913,11 +903,4 @@
         $tmp =~ s/[\r\n]//g;
 
-        ## Decode text if requested
-        if (defined($encfunc)) {
-            $tmp = &MAILdecode_1522_str($tmp,TEXT_ENCODE);
-        } elsif ($DecodeHeader) {
-            $tmp = &MAILdecode_1522_str($tmp,JUST_DECODE);
-        }
-
         ## Check for continuation of a field
         if ($tmp =~ /^\s/) {
@@ -936,4 +919,5 @@
         }
     }
+    decode_1522_fields($fields);
     ($fields, $header);
 }
@@ -1409,4 +1393,23 @@
 ##---------------------------------------------------------------------------##
 
+sub decode_1522_fields {
+  my $fields  = shift;
+  my $encfunc = load_textencoder();
+  my $mode    = defined($encfunc)
+                  ? TEXT_ENCODE : ($DecodeHeader ? JUST_DECODE : -1);
+  if ($mode == -1) {
+    return $fields;
+  }
+  my ($label, $value, $v);
+  while (($label, $value) = each %$fields) {
+    foreach $v (@$value) {
+      $v = &MAILdecode_1522_str($v, $mode);
+    }
+  }
+  $fields;
+}
+
+##---------------------------------------------------------------------------##
+
 sub dump_header {
     my $fh      = shift;

---------------------------------------------------------------------
To sign-off this list, send email to majordomo(_at_)mhonarc(_dot_)org with the
message text UNSUBSCRIBE MHONARC-COMMITS