X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-edit;h=1fbaf5a7d11c19e5759b8a59073de2aa7772876f;hb=68046e0fff12c35d793a7ae9f164ac415c84cc21;hp=240beb3a168ff3e6c6a35e4814b3cab144761642;hpb=77eafbd653d2efac546f2c330d8cf5e84bef2712;p=public-inbox.git
diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index 240beb3a..1fbaf5a7 100755
--- a/script/public-inbox-edit
+++ b/script/public-inbox-edit
@@ -1,5 +1,5 @@
#!/usr/bin/perl -w
-# Copyright (C) 2019-2020 all contributors
+# Copyright (C) 2019-2021 all contributors
# License: AGPL-3.0+
#
# Used for editing messages in a public-inbox.
@@ -16,11 +16,27 @@ 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";
+my @opt = qw(mid|m=s file|F=s raw C=s@);
+GetOptions($opt, @PublicInbox::AdminEdit::OPT, @opt) or die $help;
+if ($opt->{help}) { print $help; exit 0 };
+PublicInbox::Admin::do_chdir(delete $opt->{C});
my $cfg = PublicInbox::Config->new;
my $editor = $ENV{MAIL_EDITOR}; # e.g. "mutt -f"
@@ -118,7 +134,7 @@ $mids
}
my %tmpopt = (
- TEMPLATE => 'public-inbox-edit-XXXXXX',
+ TEMPLATE => 'public-inbox-edit-XXXX',
TMPDIR => 1,
SUFFIX => $opt->{raw} ? '.eml' : '.mbox',
);
@@ -168,7 +184,8 @@ retry_edit:
# rename/relink $edit_fn
open my $new_fh, '<', $edit_fn or
die "can't read edited file ($edit_fn): $!\n";
- my $new_raw = do { local $/; <$new_fh> };
+ defined(my $new_raw = do { local $/; <$new_fh> }) or die
+ "read $edit_fn: $!\n";
if (!$opt->{raw}) {
# get rid of the From we added