unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/4] mail_diff: match ContentHash EOL and EOM behavior more closely
Date: Tue, 25 Apr 2023 10:50:50 +0000	[thread overview]
Message-ID: <20230425105052.3921780-3-e@80x24.org> (raw)
In-Reply-To: <20230425105052.3921780-1-e@80x24.org>

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 | 2 +-
 lib/PublicInbox/MailDiff.pm    | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/ContentHash.pm b/lib/PublicInbox/ContentHash.pm
index a4f6196f..fc94257c 100644
--- a/lib/PublicInbox/ContentHash.pm
+++ b/lib/PublicInbox/ContentHash.pm
@@ -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 {
diff --git a/lib/PublicInbox/MailDiff.pm b/lib/PublicInbox/MailDiff.pm
index 7511144c..d9733ed4 100644
--- a/lib/PublicInbox/MailDiff.pm
+++ b/lib/PublicInbox/MailDiff.pm
@@ -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 $!";

  parent reply	other threads:[~2023-04-25 10:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 10:50 [PATCH 0/4] mail diff updates Eric Wong
2023-04-25 10:50 ` [PATCH 1/4] mid+contenthash: eliminate needless local variable captures Eric Wong
2023-04-25 10:50 ` Eric Wong [this message]
2023-04-25 10:50 ` [PATCH 3/4] mail_diff: show headers differences in WWW /$MSGID/d/ view Eric Wong
2023-04-25 10:50 ` [PATCH 4/4] content_digest_dbg: improve display of To:/Cc: diffs Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230425105052.3921780-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).