X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=script%2Fpublic-inbox-edit;h=2a9f0531f7377dfc4f2c02a995c7133eeb579fdd;hb=48d4fdb2acbf8cf05dcb357df53b0d658f88fe39;hp=c98840531fd674c1716aeb0a1aed0b77746d725f;hpb=04d0b9c097cc8f6d5868c4e072710baaf870f99c;p=public-inbox.git diff --git a/script/public-inbox-edit b/script/public-inbox-edit index c9884053..2a9f0531 100755 --- a/script/public-inbox-edit +++ b/script/public-inbox-edit @@ -8,7 +8,7 @@ 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 (); use PublicInbox::ContentId qw(content_id); use PublicInbox::MID qw(mid_clean mids); PublicInbox::Admin::check_require('-index'); @@ -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}) {