]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-edit
replace most uses of PublicInbox::MIME with Eml
[public-inbox.git] / script / public-inbox-edit
index b437b3c0ac1f23c3408bb33e384b61623d5cea7c..e895a228386e9f58cbeff6b42dba4daa4d877d71 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/perl -w
-# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+# Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 #
 # 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::Eml;
+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,7 +22,7 @@ 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 $cfg = PublicInbox::Config->new;
 my $editor = $ENV{MAIL_EDITOR}; # e.g. "mutt -f"
 unless (defined $editor) {
        my $k = 'publicinbox.mailEditor';
@@ -52,12 +52,12 @@ sub find_mid ($$$) {
                my ($id, $prev);
                while (my $smsg = $over->next_by_mid($mid, \$id, \$prev)) {
                        my $ref = $ibx->msg_by_smsg($smsg);
-                       my $mime = PublicInbox::MIME->new($ref);
+                       my $mime = PublicInbox::Eml->new($ref);
                        my $cid = content_id($mime);
                        my $tuple = [ $ibx, $smsg ];
                        push @{$found->{$cid} ||= []}, $tuple
                }
-               delete @$ibx{qw(over mm git search)}; # cleanup
+               PublicInbox::InboxWritable::cleanup($ibx);
        }
        $found;
 }
@@ -92,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);
@@ -131,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}) {
@@ -206,8 +205,8 @@ W: possible message boundary splitting error
                $new_raw =~ s/^>(>*From )/$1/gm;
        }
 
-       my $new_mime = PublicInbox::MIME->new(\$new_raw);
-       my $old_mime = PublicInbox::MIME->new($old_raw);
+       my $new_mime = PublicInbox::Eml->new(\$new_raw);
+       my $old_mime = PublicInbox::Eml->new($old_raw);
 
        # make sure we don't compare unwanted headers, since mutt adds
        # Content-Length, Status, and Lines headers: