about summary refs log tree commit homepage
path: root/lib/PublicInbox/MailDiff.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-01-31 10:31:57 +0000
committerEric Wong <e@80x24.org>2023-01-31 10:38:56 +0000
commit402234aa4eaf4732e5e1636099115465ec6e5c15 (patch)
treec8f5a9418eb62e750d309b4c97ead7ea6574af0d /lib/PublicInbox/MailDiff.pm
parent0746680da02f51ff3f85ebde1a3e9219d0946cf0 (diff)
downloadpublic-inbox-402234aa4eaf4732e5e1636099115465ec6e5c15.tar.gz
We need to use the utf8 layer when writing files to be diffed,
and utf8::decode the `git diff' output.  Furthermore, do the
CRLF > LF conversion early to avoid showing CRLF vs LF
differences in the diff, since that doesn't matter to MUAs
(nor our normal HTML views)
Diffstat (limited to 'lib/PublicInbox/MailDiff.pm')
-rw-r--r--lib/PublicInbox/MailDiff.pm8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/PublicInbox/MailDiff.pm b/lib/PublicInbox/MailDiff.pm
index a0ecef9f..7511144c 100644
--- a/lib/PublicInbox/MailDiff.pm
+++ b/lib/PublicInbox/MailDiff.pm
@@ -19,8 +19,10 @@ sub write_part { # Eml->each_part callback
         my $ct = $part->content_type || 'text/plain';
         my ($s, $err) = msg_part_text($part, $ct);
         my $sfx = defined($s) ? 'txt' : 'bin';
-        open my $fh, '>', "$self->{curdir}/$idx.$sfx" or die "open: $!";
-        print $fh ($s // $part->body) or die "print $!";
+        $s //= $part->body;
+        $s =~ s/\r+\n/\n/sg;
+        open my $fh, '>:utf8', "$self->{curdir}/$idx.$sfx" or die "open: $!";
+        print $fh $s or die "print $!";
         close $fh or die "close $!";
 }
 
@@ -66,9 +68,9 @@ sub next_smsg ($) {
 sub emit_msg_diff {
         my ($bref, $self) = @_; # bref is `git diff' output
         # will be escaped to `&#8226;' in HTML
+        utf8::decode($$bref);
         $self->{ctx}->{ibx}->{obfuscate} and
                 obfuscate_addrs($self->{ctx}->{ibx}, $$bref, "\x{2022}");
-        $$bref =~ s/\r+\n/\n/sg;
         print { $self->{ctx}->{zfh} } '</pre><hr><pre>' if $self->{nr} > 1;
         flush_diff($self->{ctx}, $bref);
         next_smsg($self);