]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-edit
edit+purge: support `--help' and `-h' like other commands
[public-inbox.git] / script / public-inbox-edit
index 2d3c4af4d38827f1c3068190b38fa787c2aad5eb..a70614fc2a4074e1c35485a2a290ddefe7ab0249 100755 (executable)
@@ -16,11 +16,26 @@ use PublicInbox::Eml;
 use PublicInbox::InboxWritable qw(eml_from_path);
 use PublicInbox::Import;
 
-my $usage = "$0 -m MESSAGE_ID [--all] [INBOX_DIRS]";
+my $help = <<'EOF';
+usage: public-inbox-edit -m MESSAGE-ID [--all] [INBOX_DIRS]
+
+  destructively edit messages in a public inbox
+
+options:
+
+  --all               edit all configured inboxes
+  -m MESSAGE-ID       edit the message with a given Message-ID
+  -F FILE             edit the message matching the contents of FILE
+  --force             forcibly edit even if Message-ID is ambiguous
+  --raw               do not perform "From " line escaping
+
+See public-inbox-edit(1) man page for full documentation.
+EOF
+
 my $opt = { verbose => 1, all => 0, -min_inbox_version => 2, raw => 0 };
 my @opt = qw(mid|m=s file|F=s raw);
-GetOptions($opt, @PublicInbox::AdminEdit::OPT, @opt) or
-       die "bad command-line args\n$usage\n";
+GetOptions($opt, @PublicInbox::AdminEdit::OPT, @opt) or die $help;
+if ($opt->{help}) { print $help; exit 0 };
 
 my $cfg = PublicInbox::Config->new;
 my $editor = $ENV{MAIL_EDITOR}; # e.g. "mutt -f"
@@ -93,7 +108,7 @@ Multiple messages with different content found matching
        }
 } else {
        my $eml = eml_from_path($file) or die "open($file) failed: $!";
-       my $mids = mids($eml->header_obj);
+       my $mids = mids($eml);
        find_mid($found, $_, \@ibxs) for (@$mids); # populates $found
        my $chash = content_hash($eml);
        my $to_edit = $found->{$chash};
@@ -214,9 +229,9 @@ W: possible message boundary splitting error
 
        # allow changing Received: and maybe other headers which can
        # contain sensitive info.
-       my $nhdr = $new_mime->header_obj;
-       my $ohdr = $old_mime->header_obj;
-       if (($nhdr->as_string eq $ohdr->as_string) &&
+       my $nhdr = $new_mime->header_obj->as_string;
+       my $ohdr = $old_mime->header_obj->as_string;
+       if (($nhdr eq $ohdr) &&
            (content_hash($new_mime) eq content_hash($old_mime))) {
                warn "No change detected to:\n", show_cmd($ibx, $smsg);