]> Sergey Matveev's repositories - public-inbox.git/commitdiff
edit: drop unwanted headers before noop check
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Mon, 10 Jun 2019 18:09:27 +0000 (18:09 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Mon, 10 Jun 2019 18:15:40 +0000 (18:15 +0000)
mutt will set Content-Length, Lines, and Status headers
unconditionally, so we need to account for that before
doing header comparisons to avoid making expensive changes
when noop edits are made.

script/public-inbox-edit
t/edit.t

index 7a534cc2b094bc5f796a34aec32ce76dbda0a48a..16d785294f49bcb79a62620af2a5548437ba508c 100755 (executable)
@@ -14,6 +14,7 @@ use PublicInbox::MID qw(mid_clean mids);
 PublicInbox::Admin::check_require('-index');
 require PublicInbox::MIME;
 require PublicInbox::InboxWritable;
+require PublicInbox::Import;
 
 my $usage = "$0 -m MESSAGE_ID [--all] [INBOX_DIRS]";
 my $opt = { verbose => 1, all => 0, -min_inbox_version => 2, raw => 0 };
@@ -197,6 +198,11 @@ W: possible message boundary splitting error
        my $new_mime = PublicInbox::MIME->new(\$new_raw);
        my $old_mime = PublicInbox::MIME->new($old_raw);
 
+       # make sure we don't compare unwanted headers, since mutt adds
+       # Content-Length, Status, and Lines headers:
+       PublicInbox::Import::drop_unwanted_headers($new_mime);
+       PublicInbox::Import::drop_unwanted_headers($old_mime);
+
        # allow changing Received: and maybe other headers which can
        # contain sensitive info.
        my $nhdr = $new_mime->header_obj;
index 61e90f2f138e880aaad46ce6ead3c9550823ffc5..6b4e35c3a7751a9575a38f1aa3dacd6fd77cb07b 100644 (file)
--- a/t/edit.t
+++ b/t/edit.t
@@ -79,6 +79,24 @@ $t = 'no-op -m MESSAGE_ID'; {
        is($after, $before, 'git head unchanged');
 }
 
+$t = 'no-op -m MESSAGE_ID w/Status: header'; { # because mutt does it
+       $in = $out = $err = '';
+       my $before = `git $__git_dir rev-parse HEAD`;
+       local $ENV{MAIL_EDITOR} =
+                       "$^X -i -p -e 's/^Subject:.*/Status: RO\\n\$&/'";
+       $cmd = [ "$cmd_pfx-edit", "-m$mid", $mainrepo ];
+       ok(run($cmd, \$in, \$out, \$err), "$t succeeds");
+       my $prev = $cur;
+       $cur = PublicInbox::MIME->new($ibx->msg_by_mid($mid));
+       is_deeply($cur, $prev, "$t makes no change");
+       like($cur->header('Subject'), qr/boolean prefix/,
+               "$t does not change message");
+       is($cur->header('Status'), undef, 'Status header not added');
+       like($out, qr/NONE/, 'noop shows NONE');
+       my $after = `git $__git_dir rev-parse HEAD`;
+       is($after, $before, 'git head unchanged');
+}
+
 $t = '-m MESSAGE_ID can change Received: headers'; {
        $in = $out = $err = '';
        my $before = `git $__git_dir rev-parse HEAD`;