]> Sergey Matveev's repositories - public-inbox.git/commitdiff
import: normalize body by stripping trailing newlines
authorEric Wong <e@80x24.org>
Thu, 12 May 2016 09:06:28 +0000 (09:06 +0000)
committerEric Wong <e@80x24.org>
Thu, 12 May 2016 09:06:28 +0000 (09:06 +0000)
Mbox formatters may add extra newlines at the end of the
message, and that's not relevant for comparing messages
for deletion.

lib/PublicInbox/Import.pm

index 5a3c58510cef977fbb97ed4dc86c6a6dcca28f7b..1f52a0cc80f9eddd40a8e16f7b44496a4085b005 100644 (file)
@@ -65,6 +65,13 @@ sub now2822 () {
                $day, $t[3], $mon, $t[5] + 1900, $t[2], $t[1], $t[0]);
 }
 
+sub norm_body ($) {
+       my ($mime) = @_;
+       my $b = $mime->body_raw;
+       $b =~ s/(\r?\n)+\z//s;
+       $b
+}
+
 # returns undef on non-existent
 # ('MISMATCH', msg) on mismatch
 # (:MARK, msg) on success
@@ -106,7 +113,7 @@ sub remove {
        die "bad read on final byte: <$lf>" if $lf ne "\n";
        my $cur = Email::MIME->new($buf);
        if ($cur->header('Subject') ne $mime->header('Subject') ||
-                       $cur->body ne $mime->body) {
+                       norm_body($cur) ne norm_body($mime)) {
                return ('MISMATCH', $cur);
        }