]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/bugreport.cgi
switch STDOUT to raw first, then use encoding(UTF-8)
[debbugs.git] / cgi / bugreport.cgi
index 0a66311f71909229ddeb7f2bf8d5ac03c5cbfe3c..70f42292644f437e1284a6ba0aee2eeb5aabb635 100755 (executable)
@@ -8,8 +8,6 @@ BEGIN{
     delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
 }
 
-# STDOUT should be using the utf8 io layer
-binmode(STDOUT,':utf8');
 
 use POSIX qw(strftime);
 use MIME::Parser;
@@ -38,6 +36,8 @@ use List::Util qw(max);
 
 use CGI::Simple;
 my $q = new CGI::Simple;
+# STDOUT should be using the utf8 io layer
+binmode(STDOUT,':raw:encoding(UTF-8)');
 
 my %param = cgi_parameters(query => $q,
                           single => [qw(bug msg att boring terse),
@@ -171,6 +171,7 @@ if (defined($msg) and ($msg-1) <= $#records) {
 }
 my @log;
 if ( $mbox ) {
+     binmode(STDOUT,":raw");
      my $date = strftime "%a %b %d %T %Y", localtime;
      if (@records > 1) {
         print $q->header(-type => "text/plain",
@@ -223,11 +224,11 @@ END
          # we want to include control messages anyway
          my $record_wanted_anyway = 0;
          my ($msg_id) = $record->{text} =~ /^Message-Id:\s+<(.+)>/im;
-         next if exists $seen_message_ids{$msg_id};
-         next if $msg_id =~/handler\..+\.ack(?:info|done)?\@/;
+         next if defined $msg_id and exists $seen_message_ids{$msg_id};
+         next if defined $msg_id and $msg_id =~/handler\..+\.ack(?:info|done)?\@/;
          $record_wanted_anyway = 1 if $record->{text} =~ /^Received: \(at control\)/;
          next if not $boring and not $record->{type} eq $wanted_type and not $record_wanted_anyway and @records > 1;
-         $seen_message_ids{$msg_id} = 1;
+         $seen_message_ids{$msg_id} = 1 if defined $msg_id;
          my @lines = split( "\n", $record->{text}, -1 );
          if ( $lines[ 1 ] =~ m/^From / ) {
               my $tmp = $lines[ 0 ];
@@ -245,6 +246,7 @@ END
 
 else {
      if (defined $att and defined $msg and @records) {
+        binmode(STDOUT,":raw");
          $msg_num++;
          print handle_email_message($records[0]->{text},
                                     ref => $ref,