bagder: curl-www/auto summarize.pl,1.45,1.46

[email protected]
Newsgroups gmane.comp.web.curl.www.cvs
Message-ID <[email protected]>
Update of /cvsroot/curl/curl-www/auto
In directory labb:/tmp/cvs-serv26451

Modified Files:
	summarize.pl 
Log Message:
Yang Tse's patch to do better MIME printed-quotable decoding for those cases
that is needed


Index: summarize.pl
===================================================================
RCS file: /cvsroot/curl/curl-www/auto/summarize.pl,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- summarize.pl	22 Feb 2007 14:21:15 -0000	1.45
+++ summarize.pl	23 Feb 2007 22:36:12 -0000	1.46
@@ -3,6 +3,7 @@
 require "CGI.pm";
 require "../curl.pm";
 require "ccwarn.pm";
+use MIME::QuotedPrint;
 
 opendir(DIR, "inbox");
 my @logs = grep { /^inbox/ } readdir(DIR);
@@ -381,14 +382,55 @@
 
     chmod 0644, $file;
 
+    # find out if log file is quoted-printable encoded
+    my $qpencoded = 0;
+    if(open(SCAN, "<$file")) {
+        my $linecount = 0;
+        my $mimecount = 0;
+        while(<SCAN>) {
+            chomp;
+            my $line = $_;
+            $linecount++;
+            if(($mimecount == 0) &&
+               ($line =~ /testcurl: NAME =3D/)) {
+                $mimecount++;
+            }
+            if(($mimecount != 0) &&
+               ($line =~ /testcurl: [A-Z]+ =3D/)) {
+                $mimecount++;
+            }
+            if($linecount > 50) {
+                $qpencoded = 0;
+                last;
+            }
+            if($mimecount > 5) {
+                $qpencoded = 1;
+                last;
+            }
+        }
+        close(SCAN);
+    }
+
+    my $buffer = "";
+
     open(READ, "<$file");
-    while(<READ>) {
-        chomp;
-        my $line = $_;
-        # simple quoted-printable MIME-replacements
-        $line =~ s/=20/ /g;
-        $line =~ s/=46/F/g;
-        $line =~ s/=3D/=/g;
+    while(my $chunk = <READ>) {
+        my $line;
+        # decode quoted printable if encoded
+        if($qpencoded) {
+            $buffer .= decode_qp $chunk;
+            if($buffer =~ /\n/) {
+                $line = $buffer;
+                $buffer = "";
+            }
+            else {
+                next; # chunk
+            }
+        }
+        else {
+            $line = $chunk;
+        }
+        chomp $line;
 
  #       print "L: $state - $line\n";
         if($line =~ /^INPIPE: startsingle here ([0-9-]*)/) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.