]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-edit
remove unnecessary ->header_obj calls
[public-inbox.git] / script / public-inbox-edit
index ae5d82893e281b5e2f79ef0d266a0221e0d29721..240beb3a168ff3e6c6a35e4814b3cab144761642 100755 (executable)
@@ -9,11 +9,11 @@ use warnings;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
 use PublicInbox::AdminEdit;
 use File::Temp 0.19 (); # 0.19 for TMPDIR
-use PublicInbox::ContentId qw(content_id);
+use PublicInbox::ContentHash qw(content_hash);
 use PublicInbox::MID qw(mid_clean mids);
 PublicInbox::Admin::check_require('-index');
-use PublicInbox::MIME;
-use PublicInbox::InboxWritable;
+use PublicInbox::Eml;
+use PublicInbox::InboxWritable qw(eml_from_path);
 use PublicInbox::Import;
 
 my $usage = "$0 -m MESSAGE_ID [--all] [INBOX_DIRS]";
@@ -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';
@@ -43,7 +43,7 @@ if (defined $mid && defined $file) {
 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, $opt, $cfg);
 PublicInbox::AdminEdit::check_editable(\@ibxs);
 
-my $found = {}; # cid => [ [ibx, smsg] [, [ibx, smsg] ] ]
+my $found = {}; # chash => [ [ibx, smsg] [, [ibx, smsg] ] ]
 
 sub find_mid ($$$) {
        my ($found, $mid, $ibxs) = @_;
@@ -52,10 +52,10 @@ 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 $cid = content_id($mime);
+                       my $mime = PublicInbox::Eml->new($ref);
+                       my $chash = content_hash($mime);
                        my $tuple = [ $ibx, $smsg ];
-                       push @{$found->{$cid} ||= []}, $tuple
+                       push @{$found->{$chash} ||= []}, $tuple
                }
                PublicInbox::InboxWritable::cleanup($ibx);
        }
@@ -92,13 +92,11 @@ 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 $mids = mids($mime->header_obj);
+       my $eml = eml_from_path($file) or die "open($file) failed: $!";
+       my $mids = mids($eml);
        find_mid($found, $_, \@ibxs) for (@$mids); # populates $found
-       my $cid = content_id($mime);
-       my $to_edit = $found->{$cid};
+       my $chash = content_hash($eml);
+       my $to_edit = $found->{$chash};
        unless ($to_edit) {
                my $nr = scalar(keys %$found);
                if ($nr > 0) {
@@ -116,7 +114,7 @@ $mids
                }
                exit 1;
        }
-       $found = { $cid => $to_edit };
+       $found = { $chash => $to_edit };
 }
 
 my %tmpopt = (
@@ -206,8 +204,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:
@@ -216,10 +214,10 @@ W: possible message boundary splitting error
 
        # allow changing Received: and maybe other headers which can
        # contain sensitive info.
-       my $nhdr = $new_mime->header_obj;
-       my $ohdr = $old_mime->header_obj;
-       if (($nhdr->as_string eq $ohdr->as_string) &&
-           (content_id($new_mime) eq content_id($old_mime))) {
+       my $nhdr = $new_mime->header_obj->as_string;
+       my $ohdr = $old_mime->header_obj->as_string;
+       if (($nhdr eq $ohdr) &&
+           (content_hash($new_mime) eq content_hash($old_mime))) {
                warn "No change detected to:\n", show_cmd($ibx, $smsg);
 
                next unless $opt->{verbose};