X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-edit;h=42f914a808d73413f12b7c3499b3b40c862c1f2c;hb=e01fc7d6c08ffaaf14406802f4085dc41f24f7e5;hp=0accd7c19e28a9126126c6ae203f762343bab319;hpb=10fad7e1cf3eb0a4874afa1cb5ddb3d75afeec7d;p=public-inbox.git diff --git a/script/public-inbox-edit b/script/public-inbox-edit index 0accd7c1..42f914a8 100755 --- a/script/public-inbox-edit +++ b/script/public-inbox-edit @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright (C) 2019 all contributors +# Copyright (C) 2019-2020 all contributors # License: AGPL-3.0+ # # Used for editing messages in a public-inbox. @@ -8,13 +8,13 @@ use strict; use warnings; use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev); use PublicInbox::AdminEdit; -use File::Temp (); +use File::Temp 0.19 (); # 0.19 for TMPDIR use PublicInbox::ContentId qw(content_id); use PublicInbox::MID qw(mid_clean mids); PublicInbox::Admin::check_require('-index'); -require PublicInbox::MIME; -require PublicInbox::InboxWritable; -require PublicInbox::Import; +use PublicInbox::MIME; +use PublicInbox::InboxWritable; +use PublicInbox::Import; my $usage = "$0 -m MESSAGE_ID [--all] [INBOX_DIRS]"; my $opt = { verbose => 1, all => 0, -min_inbox_version => 2, raw => 0 }; @@ -22,12 +22,11 @@ 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 $cfg = PublicInbox::Config->new; my $editor = $ENV{MAIL_EDITOR}; # e.g. "mutt -f" unless (defined $editor) { my $k = 'publicinbox.mailEditor'; - if (my $cfg = PublicInbox::Admin::config()) { - $editor = $cfg->{lc($k)}; - } + $editor = $cfg->{lc($k)} if $cfg; unless (defined $editor) { warn "\`$k' not configured, trying \`git var GIT_EDITOR'\n"; chomp($editor = `git var GIT_EDITOR`); @@ -41,7 +40,7 @@ if (defined $mid && defined $file) { die "the --mid and --file options are mutually exclusive\n"; } -my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt); +my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg); PublicInbox::AdminEdit::check_editable(\@ibxs); my $found = {}; # cid => [ [ibx, smsg] [, [ibx, smsg] ] ] @@ -58,7 +57,7 @@ sub find_mid ($$$) { my $tuple = [ $ibx, $smsg ]; push @{$found->{$cid} ||= []}, $tuple } - delete @$ibx{qw(over mm git search)}; # cleanup + PublicInbox::InboxWritable::cleanup($ibx); } $found; } @@ -93,9 +92,8 @@ Multiple messages with different content found matching warn "Will edit all of them\n"; } } else { - open my $fh, '<', $file or die "open($file) failed: $!"; - my $orig = do { local $/; <$fh> }; - my $mime = PublicInbox::MIME->new(\$orig); + my $mime = PublicInbox::InboxWritable::mime_from_path($file) or + die "open($file) failed: $!"; my $mids = mids($mime->header_obj); find_mid($found, $_, \@ibxs) for (@$mids); # populates $found my $cid = content_id($mime); @@ -132,7 +130,7 @@ foreach my $to_edit (values %$found) { my $edit_fn = $edit_fh->filename; my ($ibx, $smsg) = @{$to_edit->[0]}; my $old_raw = $ibx->msg_by_smsg($smsg); - delete @$ibx{qw(over mm git search)}; # cleanup + PublicInbox::InboxWritable::cleanup($ibx); my $tmp = $$old_raw; if (!$opt->{raw}) {