]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
mail_diff: match ContentHash EOL and EOM behavior more closely
authorEric Wong <e@80x24.org>
Tue, 25 Apr 2023 10:50:50 +0000 (10:50 +0000)
committerEric Wong <e@80x24.org>
Tue, 25 Apr 2023 20:51:33 +0000 (20:51 +0000)
ContentHash currently doesn't convert CRCRLF to LF.  Perhaps it
should, but for now, have diff behavior match the actual
comparison behavior used for dedupe and omit all trailing
whitespace for diff.

lib/PublicInbox/ContentHash.pm
lib/PublicInbox/MailDiff.pm

index a4f6196f8f686ae6096913f4ee305979dad74687..fc94257c7c243a378b18ae81f04be06b1c3bb0cb 100644 (file)
@@ -45,7 +45,7 @@ sub content_dig_i {
        my $ct = $part->content_type || 'text/plain';
        my ($s, undef) = msg_part_text($part, $ct);
        if (defined $s) {
-               $s =~ s/\r\n/\n/gs;
+               $s =~ s/\r\n/\n/gs; # TODO: consider \r+\n to match View
                $s =~ s/\s*\z//s;
                utf8::encode($s);
        } else {
index 7511144c6419e235e7b2e63f5a81f64fa3fed6a0..d9733ed40a482d5776a986d40bc03ad9c1120bf9 100644 (file)
@@ -11,7 +11,7 @@ use PublicInbox::GitAsyncCat;
 sub write_part { # Eml->each_part callback
        my ($ary, $self) = @_;
        my ($part, $depth, $idx) = @$ary;
-       if ($idx ne '1' || $self->{-raw_hdr}) {
+       if ($idx ne '1' || $self->{-raw_hdr}) { # lei mail-diff --raw-header
                open my $fh, '>', "$self->{curdir}/$idx.hdr" or die "open: $!";
                print $fh ${$part->{hdr}} or die "print $!";
                close $fh or die "close $!";
@@ -20,7 +20,8 @@ sub write_part { # Eml->each_part callback
        my ($s, $err) = msg_part_text($part, $ct);
        my $sfx = defined($s) ? 'txt' : 'bin';
        $s //= $part->body;
-       $s =~ s/\r+\n/\n/sg;
+       $s =~ s/\r\n/\n/gs; # TODO: consider \r+\n to match View
+       $s =~ s/\s*\z//s;
        open my $fh, '>:utf8', "$self->{curdir}/$idx.$sfx" or die "open: $!";
        print $fh $s or die "print $!";
        close $fh or die "close $!";