From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7932A1F462; Mon, 10 Jun 2019 18:17:08 +0000 (UTC) Date: Mon, 10 Jun 2019 18:17:08 +0000 From: "Eric Wong (Contractor, The Linux Foundation)" To: meta@public-inbox.org Subject: [PATCH 13/11] edit: drop unwanted headers before noop check Message-ID: <20190610181708.mg2aiazd5adolsn6@dcvr> References: <20190609025147.24966-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190609025147.24966-1-e@80x24.org> List-Id: 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 | 6 ++++++ t/edit.t | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/script/public-inbox-edit b/script/public-inbox-edit index 7a534cc..16d7852 100755 --- a/script/public-inbox-edit +++ b/script/public-inbox-edit @@ -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; diff --git a/t/edit.t b/t/edit.t index 61e90f2..6b4e35c 100644 --- 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`; -- EW