X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-edit;h=ae5d82893e281b5e2f79ef0d266a0221e0d29721;hb=c29b2b7ded47def906cf00e3baad65c102304120;hp=c98840531fd674c1716aeb0a1aed0b77746d725f;hpb=04d0b9c097cc8f6d5868c4e072710baaf870f99c;p=public-inbox.git
diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index c9884053..ae5d8289 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 qw(tempfile);
+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 = eval { 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;
}
@@ -120,13 +119,19 @@ $mids
$found = { $cid => $to_edit };
}
-my $tmpl = 'public-inbox-edit-XXXXXX';
+my %tmpopt = (
+ TEMPLATE => 'public-inbox-edit-XXXXXX',
+ TMPDIR => 1,
+ SUFFIX => $opt->{raw} ? '.eml' : '.mbox',
+);
+
foreach my $to_edit (values %$found) {
- my ($edit_fh, $edit_fn) = tempfile($tmpl, TMPDIR => 1, UNLINK => 1);
+ my $edit_fh = File::Temp->new(%tmpopt);
$edit_fh->autoflush(1);
+ 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}) {