]> git.donarmstrong.com Git - debbugs.git/commitdiff
convert to perl's internal utf8 in reply_headers
authorDon Armstrong <don@donarmstrong.com>
Sun, 25 Jun 2017 17:34:14 +0000 (10:34 -0700)
committerDon Armstrong <don@donarmstrong.com>
Sun, 25 Jun 2017 17:34:14 +0000 (10:34 -0700)
This fixes mojibake in the reply-to links

Debbugs/Mail.pm

index 0a227b6aeaa944adb242047daabda85169418f17..e4c8bf7da825e53ce64b3f0849079237e07745fa 100644 (file)
@@ -49,7 +49,7 @@ use Debbugs::MIME qw(encode_rfc1522);
 use Debbugs::Config qw(:config);
 use Params::Validate qw(:types validate_with);
 use Encode qw(encode is_utf8);
-use Debbugs::UTF8 qw(encode_utf8_safely);
+use Debbugs::UTF8 qw(encode_utf8_safely convert_to_utf8);
 
 use Debbugs::Packages;
 
@@ -450,9 +450,16 @@ sub reply_headers{
     my $body = "On $date $who wrote:\n";
     my $i = 60;
     my $b_h;
+    # Default to UTF-8.
+    my $charset="utf-8";
     ## find the first part which has a defined body handle and appears
     ## to be text
     if (defined $entity->bodyhandle) {
+       my $this_charset =
+           $entity->head->mime_attr("content-type.charset");
+       $charset = $this_charset if
+           defined $this_charset and
+           length $this_charset;
         $b_h = $entity->bodyhandle;
     } elsif ($entity->parts) {
         my @parts = $entity->parts;
@@ -462,6 +469,11 @@ sub reply_headers{
             }
             if (defined $part->bodyhandle and
                 $part->effective_type =~ /text/) {
+               my $this_charset =
+                   $part->head->mime_attr("content-type.charset");
+               $charset =  $this_charset if
+                   defined $this_charset and
+                   length $this_charset;
                 $b_h = $part->bodyhandle;
                 last;
             }
@@ -473,7 +485,7 @@ sub reply_headers{
             while (defined($_ = $IO->getline)) {
                 $i--;
                 last if $i < 0;
-                $body .= '> '. $_;
+                $body .= '> '. convert_to_utf8($_,$charset);
             }
             $IO->close();
         };