* [PATCH 0/4] cleanup some minor annoyances
@ 2020-08-01 8:12 Eric Wong
2020-08-01 8:12 ` [PATCH 1/4] inboxwritable: mime_from_path: reduce `$/' scope and returns Eric Wong
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Eric Wong @ 2020-08-01 8:12 UTC (permalink / raw)
To: meta
Just some minor stuff I noticed while tracking down -watch
failures resolved by
https://public-inbox.org/meta/20200731213618.GA19572@dcvr/
Eric Wong (4):
inboxwritable: mime_from_path: reduce `$/' scope and returns
inboxwritable: rename mime_from_path to eml_from_path
searchidx: remove v1-only msg_mime sub
remove unnecessary ->header_obj calls
lib/PublicInbox/ContentHash.pm | 15 +++++++-------
lib/PublicInbox/Import.pm | 17 +++++++---------
lib/PublicInbox/InboxWritable.pm | 25 ++++++++++-------------
lib/PublicInbox/MID.pm | 5 +----
lib/PublicInbox/OverIdx.pm | 9 ++++----
lib/PublicInbox/SearchIdx.pm | 30 ++++++++++++---------------
lib/PublicInbox/V2Writable.pm | 35 +++++++++++++++-----------------
lib/PublicInbox/View.pm | 35 +++++++++++++++-----------------
lib/PublicInbox/WatchMaildir.pm | 10 ++++-----
lib/PublicInbox/WwwAtomStream.pm | 9 ++++----
script/public-inbox-edit | 15 +++++++-------
script/public-inbox-mda | 2 +-
t/search.t | 1 +
13 files changed, 92 insertions(+), 116 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] inboxwritable: mime_from_path: reduce `$/' scope and returns
2020-08-01 8:12 [PATCH 0/4] cleanup some minor annoyances Eric Wong
@ 2020-08-01 8:12 ` Eric Wong
2020-08-01 8:12 ` [PATCH 2/4] inboxwritable: rename mime_from_path to eml_from_path Eric Wong
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2020-08-01 8:12 UTC (permalink / raw)
To: meta
We don't want `local $/' affecting Eml->new, and we can
use implicit returns which may be faster on older Perl.
---
lib/PublicInbox/InboxWritable.pm | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index 1f3f66728..e8ecd3fba 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -8,6 +8,7 @@ use warnings;
use base qw(PublicInbox::Inbox);
use PublicInbox::Import;
use PublicInbox::Filter::Base qw(REJECT);
+use Errno qw(ENOENT);
use constant {
PERM_UMASK => 0,
@@ -135,16 +136,11 @@ sub is_maildir_path ($) {
sub mime_from_path ($) {
my ($path) = @_;
if (open my $fh, '<', $path) {
- local $/;
- my $str = <$fh>;
- $str or return;
- return PublicInbox::Eml->new(\$str);
- } elsif ($!{ENOENT}) {
- # common with Maildir
- return;
- } else {
- warn "failed to open $path: $!\n";
- return;
+ my $str = do { local $/; <$fh> } or return;
+ PublicInbox::Eml->new(\$str);
+ } else { # ENOENT is common with Maildir
+ warn "failed to open $path: $!\n" if $! != ENOENT;
+ undef;
}
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/4] inboxwritable: rename mime_from_path to eml_from_path
2020-08-01 8:12 [PATCH 0/4] cleanup some minor annoyances Eric Wong
2020-08-01 8:12 ` [PATCH 1/4] inboxwritable: mime_from_path: reduce `$/' scope and returns Eric Wong
@ 2020-08-01 8:12 ` Eric Wong
2020-08-01 8:12 ` [PATCH 3/4] searchidx: remove v1-only msg_mime sub Eric Wong
2020-08-01 8:12 ` [PATCH 4/4] remove unnecessary ->header_obj calls Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2020-08-01 8:12 UTC (permalink / raw)
To: meta
This is more accurate given we use PublicInbox::Eml instead
of Email::MIME/PublicInbox::MIME, nowadays.
---
lib/PublicInbox/InboxWritable.pm | 9 +++++----
lib/PublicInbox/WatchMaildir.pm | 7 +++----
script/public-inbox-edit | 9 ++++-----
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/lib/PublicInbox/InboxWritable.pm b/lib/PublicInbox/InboxWritable.pm
index e8ecd3fba..7fb5a150c 100644
--- a/lib/PublicInbox/InboxWritable.pm
+++ b/lib/PublicInbox/InboxWritable.pm
@@ -4,11 +4,12 @@
# Extends read-only Inbox for writing
package PublicInbox::InboxWritable;
use strict;
-use warnings;
-use base qw(PublicInbox::Inbox);
+use v5.10.1;
+use parent qw(PublicInbox::Inbox Exporter);
use PublicInbox::Import;
use PublicInbox::Filter::Base qw(REJECT);
use Errno qw(ENOENT);
+our @EXPORT_OK = qw(eml_from_path);
use constant {
PERM_UMASK => 0,
@@ -133,7 +134,7 @@ sub is_maildir_path ($) {
(is_maildir_basename($p[-1]) && -f $path) ? 1 : 0;
}
-sub mime_from_path ($) {
+sub eml_from_path ($) {
my ($path) = @_;
if (open my $fh, '<', $path) {
my $str = do { local $/; <$fh> } or return;
@@ -155,7 +156,7 @@ sub import_maildir {
opendir my $dh, "$dir/$sub" or die "opendir $dir/$sub: $!\n";
while (defined(my $fn = readdir($dh))) {
next unless is_maildir_basename($fn);
- my $mime = mime_from_path("$dir/$fn") or next;
+ my $mime = eml_from_path("$dir/$fn") or next;
if (my $filter = $self->filter($im)) {
my $ret = $filter->scrub($mime) or return;
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index fad708d8f..814b455b2 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -7,7 +7,7 @@ package PublicInbox::WatchMaildir;
use strict;
use warnings;
use PublicInbox::Eml;
-use PublicInbox::InboxWritable;
+use PublicInbox::InboxWritable qw(eml_from_path);
use PublicInbox::Filter::Base qw(REJECT);
use PublicInbox::Spamcheck;
use PublicInbox::Sigfd;
@@ -15,7 +15,6 @@ use PublicInbox::DS qw(now);
use PublicInbox::MID qw(mids);
use PublicInbox::ContentHash qw(content_hash);
use POSIX qw(_exit);
-*mime_from_path = \&PublicInbox::InboxWritable::mime_from_path;
sub compile_watchheaders ($) {
my ($ibx) = @_;
@@ -154,7 +153,7 @@ sub _remove_spam {
my ($self, $path) = @_;
# path must be marked as (S)een
$path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return;
- my $eml = mime_from_path($path) or return;
+ my $eml = eml_from_path($path) or return;
$self->{config}->each_inbox(\&remove_eml_i, [ $self, $eml, $path ]);
}
@@ -207,7 +206,7 @@ sub _try_path {
return _remove_spam($self, $path);
}
foreach my $ibx (@$inboxes) {
- my $eml = mime_from_path($path) or next;
+ my $eml = eml_from_path($path) or next;
import_eml($self, $ibx, $eml);
}
}
diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index d8e511b2e..2d3c4af4d 100755
--- a/script/public-inbox-edit
+++ b/script/public-inbox-edit
@@ -13,7 +13,7 @@ use PublicInbox::ContentHash qw(content_hash);
use PublicInbox::MID qw(mid_clean mids);
PublicInbox::Admin::check_require('-index');
use PublicInbox::Eml;
-use PublicInbox::InboxWritable;
+use PublicInbox::InboxWritable qw(eml_from_path);
use PublicInbox::Import;
my $usage = "$0 -m MESSAGE_ID [--all] [INBOX_DIRS]";
@@ -92,11 +92,10 @@ Multiple messages with different content found matching
warn "Will edit all of them\n";
}
} else {
- my $mime = PublicInbox::InboxWritable::mime_from_path($file) or
- die "open($file) failed: $!";
- my $mids = mids($mime->header_obj);
+ my $eml = eml_from_path($file) or die "open($file) failed: $!";
+ my $mids = mids($eml->header_obj);
find_mid($found, $_, \@ibxs) for (@$mids); # populates $found
- my $chash = content_hash($mime);
+ my $chash = content_hash($eml);
my $to_edit = $found->{$chash};
unless ($to_edit) {
my $nr = scalar(keys %$found);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/4] searchidx: remove v1-only msg_mime sub
2020-08-01 8:12 [PATCH 0/4] cleanup some minor annoyances Eric Wong
2020-08-01 8:12 ` [PATCH 1/4] inboxwritable: mime_from_path: reduce `$/' scope and returns Eric Wong
2020-08-01 8:12 ` [PATCH 2/4] inboxwritable: rename mime_from_path to eml_from_path Eric Wong
@ 2020-08-01 8:12 ` Eric Wong
2020-08-01 8:12 ` [PATCH 4/4] remove unnecessary ->header_obj calls Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2020-08-01 8:12 UTC (permalink / raw)
To: meta
We can rely on the newer mids() sub directly and use faster
numeric comparisons for Msgmap unindexing in v1.
---
lib/PublicInbox/MID.pm | 5 +----
lib/PublicInbox/SearchIdx.pm | 16 +++++++---------
t/search.t | 1 +
3 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/lib/PublicInbox/MID.pm b/lib/PublicInbox/MID.pm
index 685306dbf..e9a3b0c09 100644
--- a/lib/PublicInbox/MID.pm
+++ b/lib/PublicInbox/MID.pm
@@ -6,7 +6,7 @@ package PublicInbox::MID;
use strict;
use warnings;
use base qw/Exporter/;
-our @EXPORT_OK = qw(mid_clean id_compress mid2path mid_mime mid_escape MID_ESC
+our @EXPORT_OK = qw(mid_clean id_compress mid2path mid_escape MID_ESC
mids references mids_for_index $MID_EXTRACT);
use URI::Escape qw(uri_escape_utf8);
use Digest::SHA qw/sha1_hex/;
@@ -53,9 +53,6 @@ sub mid2path {
"$x2/$x38";
}
-# Only for v1 code paths:
-sub mid_mime ($) { mids($_[0]->header_obj)->[0] }
-
# only intended for Message-ID and X-Alt-Message-ID
sub extract_mids {
my @mids;
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 080aca7cb..feb00de22 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -12,7 +12,7 @@ use v5.10.1;
use parent qw(PublicInbox::Search PublicInbox::Lock Exporter);
use PublicInbox::Eml;
use PublicInbox::InboxWritable;
-use PublicInbox::MID qw(mid_mime mids_for_index mids);
+use PublicInbox::MID qw(mids_for_index mids);
use PublicInbox::MsgIter;
use PublicInbox::IdxStack;
use Carp qw(croak);
@@ -492,6 +492,11 @@ sub unindex_eml {
while (my ($num, $nr) = each %tmp) {
warn "BUG: $num appears >1 times ($nr) for $oid\n" if $nr != 1;
}
+ if ($nr) {
+ $self->{mm}->num_delete($_) for (keys %tmp);
+ } else { # just in case msgmap and over.sqlite3 become desynched:
+ $self->{mm}->mid_delete($mids->[0]);
+ }
xdb_remove($self, $oid, keys %tmp) if need_xapian($self);
}
@@ -512,11 +517,6 @@ sub index_mm {
}
}
-sub unindex_mm {
- my ($self, $mime) = @_;
- $self->{mm}->mid_delete(mid_mime($mime));
-}
-
# returns the number of bytes to add if given a non-CRLF arg
sub crlf_adjust ($) {
if (index($_[0], "\r\n") < 0) {
@@ -544,9 +544,7 @@ sub index_both { # git->cat_async callback
sub unindex_both { # git->cat_async callback
my ($bref, $oid, $type, $size, $self) = @_;
- my $eml = PublicInbox::Eml->new($bref);
- unindex_eml($self, $oid, $eml);
- unindex_mm($self, $eml);
+ unindex_eml($self, $oid, PublicInbox::Eml->new($bref));
}
# called by public-inbox-index
diff --git a/t/search.t b/t/search.t
index a75d944c3..299f57c85 100644
--- a/t/search.t
+++ b/t/search.t
@@ -420,6 +420,7 @@ $ibx->with_umask(sub {
$art = $ro->{over_ro}->next_by_mid($mid, \$id, \$prev);
ok($art, 'article exists in OVER DB');
}
+ $rw->_msgmap_init;
$rw->unindex_eml($oid, $amsg);
$rw->commit_txn_lazy;
SKIP: {
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/4] remove unnecessary ->header_obj calls
2020-08-01 8:12 [PATCH 0/4] cleanup some minor annoyances Eric Wong
` (2 preceding siblings ...)
2020-08-01 8:12 ` [PATCH 3/4] searchidx: remove v1-only msg_mime sub Eric Wong
@ 2020-08-01 8:12 ` Eric Wong
3 siblings, 0 replies; 5+ messages in thread
From: Eric Wong @ 2020-08-01 8:12 UTC (permalink / raw)
To: meta
We used ->header_obj in the past as an optimization with
Email::MIME. That optimization is no longer necessary
with PublicInbox::Eml.
This doesn't make any functional difference even if we were to
go back to Email::MIME. However, it reduces the amount of code
we have and slightly reduces allocations with PublicInbox::Eml.
---
lib/PublicInbox/ContentHash.pm | 15 +++++++-------
lib/PublicInbox/Import.pm | 17 +++++++---------
lib/PublicInbox/OverIdx.pm | 9 ++++----
lib/PublicInbox/SearchIdx.pm | 14 ++++++-------
lib/PublicInbox/V2Writable.pm | 35 +++++++++++++++-----------------
lib/PublicInbox/View.pm | 35 +++++++++++++++-----------------
lib/PublicInbox/WatchMaildir.pm | 3 +--
lib/PublicInbox/WwwAtomStream.pm | 9 ++++----
script/public-inbox-edit | 8 ++++----
script/public-inbox-mda | 2 +-
10 files changed, 66 insertions(+), 81 deletions(-)
diff --git a/lib/PublicInbox/ContentHash.pm b/lib/PublicInbox/ContentHash.pm
index 420dc5e7c..1fe229559 100644
--- a/lib/PublicInbox/ContentHash.pm
+++ b/lib/PublicInbox/ContentHash.pm
@@ -53,29 +53,28 @@ sub content_dig_i {
}
sub content_digest ($) {
- my ($mime) = @_;
+ my ($eml) = @_;
my $dig = Digest::SHA->new(256);
- my $hdr = $mime->header_obj;
# References: and In-Reply-To: get used interchangeably
# in some "duplicates" in LKML. We treat them the same
# in SearchIdx, so treat them the same for this:
# do NOT consider the Message-ID as part of the content_hash
# if we got here, we've already got Message-ID reuse
- my %seen = map { $_ => 1 } @{mids($hdr)};
- foreach my $mid (@{references($hdr)}) {
+ my %seen = map { $_ => 1 } @{mids($eml)};
+ foreach my $mid (@{references($eml)}) {
$dig->add("ref\0$mid\0") unless $seen{$mid}++;
}
# Only use Sender: if From is not present
foreach my $h (qw(From Sender)) {
- my @v = $hdr->header($h);
+ my @v = $eml->header($h);
if (@v) {
digest_addr($dig, $h, $_) foreach @v;
}
}
foreach my $h (qw(Subject Date)) {
- my @v = $hdr->header($h);
+ my @v = $eml->header($h);
foreach my $v (@v) {
utf8::encode($v);
$dig->add("$h\0$v\0");
@@ -85,10 +84,10 @@ sub content_digest ($) {
# not in the original message. For the purposes of deduplication,
# do not take it into account:
foreach my $h (qw(To Cc)) {
- my @v = $hdr->header($h);
+ my @v = $eml->header($h);
digest_addr($dig, $h, $_) foreach @v;
}
- msg_iter($mime, \&content_dig_i, $dig);
+ msg_iter($eml, \&content_dig_i, $dig);
$dig;
}
diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 07a495187..700b40262 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -285,15 +285,14 @@ sub extract_cmt_info ($;$) {
# $mime is PublicInbox::Eml, but remains Email::MIME-compatible
$smsg //= bless {}, 'PublicInbox::Smsg';
- my $hdr = $mime->header_obj;
- $smsg->populate($hdr);
+ $smsg->populate($mime);
my $sender = '';
my $from = delete($smsg->{From}) // '';
my ($email) = PublicInbox::Address::emails($from);
my ($name) = PublicInbox::Address::names($from);
if (!defined($name) || !defined($email)) {
- $sender = $hdr->header('Sender') // '';
+ $sender = $mime->header('Sender') // '';
$name //= (PublicInbox::Address::names($sender))[0];
$email //= (PublicInbox::Address::emails($sender))[0];
}
@@ -346,13 +345,12 @@ sub append_mid ($$) {
}
sub v1_mid0 ($) {
- my ($mime) = @_;
- my $hdr = $mime->header_obj;
- my $mids = mids($hdr);
+ my ($eml) = @_;
+ my $mids = mids($eml);
if (!scalar(@$mids)) { # spam often has no Message-ID
- my $mid0 = digest2mid(content_digest($mime), $hdr);
- append_mid($hdr, $mid0);
+ my $mid0 = digest2mid(content_digest($eml), $eml);
+ append_mid($eml, $mid0);
return $mid0;
}
$mids->[0];
@@ -671,8 +669,7 @@ version 1.0
my $parsed = PublicInbox::Eml->new($message);
my $ret = $im->add($parsed);
if (!defined $ret) {
- warn "duplicate: ",
- $parsed->header_obj->header_raw('Message-ID'), "\n";
+ warn "duplicate: ", $parsed->header_raw('Message-ID'), "\n";
} else {
print "imported at mark $ret\n";
}
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index 5821c562b..c8f61e012 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -271,11 +271,10 @@ sub subject_path ($) {
}
sub add_overview {
- my ($self, $mime, $smsg) = @_;
- $smsg->{lines} = $mime->body_raw =~ tr!\n!\n!;
- my $hdr = $mime->header_obj;
- my $mids = mids_for_index($hdr);
- my $refs = parse_references($smsg, $hdr, $mids);
+ my ($self, $eml, $smsg) = @_;
+ $smsg->{lines} = $eml->body_raw =~ tr!\n!\n!;
+ my $mids = mids_for_index($eml);
+ my $refs = parse_references($smsg, $eml, $mids);
my $subj = $smsg->{subject};
my $xpath;
if ($subj ne '') {
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index feb00de22..a1baa65bd 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -350,8 +350,7 @@ sub index_ids ($$$$) {
}
sub add_xapian ($$$$) {
- my ($self, $mime, $smsg, $mids) = @_;
- my $hdr = $mime->header_obj;
+ my ($self, $eml, $smsg, $mids) = @_;
my $doc = $X->{Document}->new;
add_val($doc, PublicInbox::Search::TS(), $smsg->{ts});
my @ds = gmtime($smsg->{ds});
@@ -366,10 +365,10 @@ sub add_xapian ($$$$) {
$tg->set_document($doc);
index_headers($self, $smsg);
- msg_iter($mime, \&index_xapian, [ $self, $doc ]);
- index_ids($self, $doc, $hdr, $mids);
+ msg_iter($eml, \&index_xapian, [ $self, $doc ]);
+ index_ids($self, $doc, $eml, $mids);
$smsg->{to} = $smsg->{cc} = ''; # WWW doesn't need these, only NNTP
- PublicInbox::OverIdx::parse_references($smsg, $hdr, $mids);
+ PublicInbox::OverIdx::parse_references($smsg, $eml, $mids);
my $data = $smsg->to_doc_data;
$doc->set_data($data);
if (my $altid = $self->{-altid}) {
@@ -398,8 +397,7 @@ sub _msgmap_init ($) {
sub add_message {
# mime = PublicInbox::Eml or Email::MIME object
my ($self, $mime, $smsg, $sync) = @_;
- my $hdr = $mime->header_obj;
- my $mids = mids_for_index($hdr);
+ my $mids = mids_for_index($mime);
$smsg //= bless { blob => '' }, 'PublicInbox::Smsg'; # test-only compat
$smsg->{mid} //= $mids->[0]; # v1 compatibility
$smsg->{num} //= do { # v1
@@ -408,7 +406,7 @@ sub add_message {
};
# v1 and tests only:
- $smsg->populate($hdr, $sync);
+ $smsg->populate($mime, $sync);
$smsg->{bytes} //= length($mime->as_string);
eval {
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index e1c9a393a..344edbbad 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -197,7 +197,7 @@ sub _add {
sub v2_num_for {
my ($self, $mime) = @_;
- my $mids = mids($mime->header_obj);
+ my $mids = mids($mime);
if (@$mids) {
my $mid = $mids->[0];
my $num = $self->{mm}->mid_insert($mid);
@@ -244,28 +244,27 @@ sub v2_num_for {
}
sub v2_num_for_harder {
- my ($self, $mime) = @_;
+ my ($self, $eml) = @_;
- my $hdr = $mime->header_obj;
- my $dig = content_digest($mime);
- my $mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
+ my $dig = content_digest($eml);
+ my $mid0 = PublicInbox::Import::digest2mid($dig, $eml);
my $num = $self->{mm}->mid_insert($mid0);
unless (defined $num) {
# it's hard to spoof the last Received: header
- my @recvd = $hdr->header_raw('Received');
+ my @recvd = $eml->header_raw('Received');
$dig->add("Received: $_") foreach (@recvd);
- $mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
+ $mid0 = PublicInbox::Import::digest2mid($dig, $eml);
$num = $self->{mm}->mid_insert($mid0);
# fall back to a random Message-ID and give up determinism:
until (defined($num)) {
$dig->add(rand);
- $mid0 = PublicInbox::Import::digest2mid($dig, $hdr);
+ $mid0 = PublicInbox::Import::digest2mid($dig, $eml);
warn "using random Message-ID <$mid0> as fallback\n";
$num = $self->{mm}->mid_insert($mid0);
}
}
- PublicInbox::Import::append_mid($hdr, $mid0);
+ PublicInbox::Import::append_mid($eml, $mid0);
($num, $mid0);
}
@@ -384,7 +383,7 @@ sub rewrite_internal ($$;$$$) {
my $over = $self->{over};
my $chashes = content_hashes($old_eml);
my $removed = [];
- my $mids = mids($old_eml->header_obj);
+ my $mids = mids($old_eml);
# We avoid introducing new blobs into git since the raw content
# can be slightly different, so we do not need the user-supplied
@@ -514,9 +513,7 @@ sub _check_mids_match ($$$) {
# Message-IDs are pretty complex and rethreading hasn't been fully
# implemented, yet.
sub check_mids_match ($$) {
- my ($old_mime, $new_mime) = @_;
- my $old = $old_mime->header_obj;
- my $new = $new_mime->header_obj;
+ my ($old, $new) = @_;
_check_mids_match(mids($old), mids($new), 'Message-ID(s)');
_check_mids_match(references($old), references($new),
'References/In-Reply-To');
@@ -894,9 +891,9 @@ sub index_oid { # cat_async callback
my ($bref, $oid, $type, $size, $arg) = @_;
return if $size == 0; # purged
my ($num, $mid0);
- my $mime = PublicInbox::Eml->new($$bref);
- my $mids = mids($mime->header_obj);
- my $chash = content_hash($mime);
+ my $eml = PublicInbox::Eml->new($$bref);
+ my $mids = mids($eml);
+ my $chash = content_hash($eml);
my $self = $arg->{v2w};
if (scalar(@$mids) == 0) {
@@ -960,8 +957,8 @@ sub index_oid { # cat_async callback
blob => $oid,
mid => $mid0,
}, 'PublicInbox::Smsg';
- $smsg->populate($mime, $arg);
- if (do_idx($self, $bref, $mime, $smsg)) {
+ $smsg->populate($eml, $arg);
+ if (do_idx($self, $bref, $eml, $smsg)) {
${$arg->{need_checkpoint}} = 1;
}
}
@@ -1113,7 +1110,7 @@ sub unindex_oid ($$;$) { # git->cat_async callback
my $self = $sync->{v2w};
my $unindexed = $sync->{in_unindex} ? $sync->{unindexed} : undef;
my $mm = $self->{mm};
- my $mids = mids(PublicInbox::Eml->new($bref)->header_obj);
+ my $mids = mids(PublicInbox::Eml->new($bref));
undef $$bref;
my $over = $self->{over};
foreach my $mid (@$mids) {
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index d7ec4eb0a..4cb72bea8 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -33,8 +33,7 @@ sub msg_page_i {
$ctx->{smsg} = $ctx->{over}->next_by_mid(@{$ctx->{next_arg}});
$ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ?
"../${\mid_href($smsg->{mid})}/" : '';
- my $hdr = $eml->header_obj;
- my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($hdr, $ctx);
+ my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
multipart_text_as_html($eml, $ctx);
delete $ctx->{obuf};
$$obuf .= '</pre><hr>';
@@ -50,14 +49,13 @@ sub no_over_html ($) {
my ($ctx) = @_;
my $bref = $ctx->{-inbox}->msg_by_mid($ctx->{mid}) or return; # 404
my $eml = PublicInbox::Eml->new($bref);
- my $hdr = $eml->header_obj;
$ctx->{mhref} = '';
PublicInbox::WwwStream::init($ctx);
- my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($hdr, $ctx);
+ my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($eml, $ctx);
multipart_text_as_html($eml, $ctx);
delete $ctx->{obuf};
$$obuf .= '</pre><hr>';
- eval { $$obuf .= html_footer($ctx, $hdr) };
+ eval { $$obuf .= html_footer($ctx, $eml) };
html_oneshot($ctx, 200, $obuf);
}
@@ -199,16 +197,15 @@ sub eml_entry {
# Deleting these fields saves about 400K as we iterate across 1K msgs
delete @$smsg{qw(ts blob)};
- my $hdr = $eml->header_obj;
- my $from = _hdr_names_html($hdr, 'From');
+ my $from = _hdr_names_html($eml, 'From');
obfuscate_addrs($obfs_ibx, $from) if $obfs_ibx;
$rv .= "From: $from @ ".fmt_ts($ds)." UTC";
my $upfx = $ctx->{-upfx};
my $mhref = $upfx . mid_href($mid_raw) . '/';
$rv .= qq{ (<a\nhref="$mhref">permalink</a> / };
$rv .= qq{<a\nhref="${mhref}raw">raw</a>)\n};
- my $to = fold_addresses(_hdr_names_html($hdr, 'To'));
- my $cc = fold_addresses(_hdr_names_html($hdr, 'Cc'));
+ my $to = fold_addresses(_hdr_names_html($eml, 'To'));
+ my $cc = fold_addresses(_hdr_names_html($eml, 'Cc'));
my ($tlen, $clen) = (length($to), length($cc));
my $to_cc = '';
if (($tlen + $clen) > COLS) {
@@ -227,7 +224,7 @@ sub eml_entry {
$rv .= $to_cc;
my $mapping = $ctx->{mapping};
- if (!$mapping && (defined($irt) || defined($irt = in_reply_to($hdr)))) {
+ if (!$mapping && (defined($irt) || defined($irt = in_reply_to($eml)))) {
my $href = $upfx . mid_href($irt) . '/';
my $html = ascii_html($irt);
$rv .= qq(In-Reply-To: <<a\nhref="$href">$html</a>>\n)
@@ -626,16 +623,16 @@ sub add_text_body { # callback for each_part
}
sub _msg_page_prepare_obuf {
- my ($hdr, $ctx) = @_;
+ my ($eml, $ctx) = @_;
my $over = $ctx->{-inbox}->over;
my $obfs_ibx = $ctx->{-obfs_ibx};
my $rv = '';
- my $mids = mids_for_index($hdr);
+ my $mids = mids_for_index($eml);
my $nr = $ctx->{nr}++;
if ($nr) { # unlikely
$rv .= '<pre>';
} else {
- $ctx->{first_hdr} = $hdr;
+ $ctx->{first_hdr} = $eml->header_obj;
if ($ctx->{smsg}) {
$rv .=
"<pre>WARNING: multiple messages have this Message-ID\n</pre>";
@@ -644,7 +641,7 @@ sub _msg_page_prepare_obuf {
}
$ctx->{-upfx} = '../' if $over;
my @title; # (Subject[0], From[0])
- for my $v ($hdr->header('From')) {
+ for my $v ($eml->header('From')) {
my @n = PublicInbox::Address::names($v);
$v = ascii_html($v);
$title[1] //= ascii_html(join(', ', @n));
@@ -655,14 +652,14 @@ sub _msg_page_prepare_obuf {
$rv .= "From: $v\n" if $v ne '';
}
foreach my $h (qw(To Cc)) {
- for my $v ($hdr->header($h)) {
+ for my $v ($eml->header($h)) {
fold_addresses($v);
$v = ascii_html($v);
obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
$rv .= "$h: $v\n" if $v ne '';
}
}
- my @subj = $hdr->header('Subject');
+ my @subj = $eml->header('Subject');
if (@subj) {
my $v = ascii_html(shift @subj);
obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
@@ -678,7 +675,7 @@ sub _msg_page_prepare_obuf {
$rv .= qq(<a\nhref="#r"\nid=t></a>) if $over;
$title[0] = '(no subject)';
}
- for my $v ($hdr->header('Date')) {
+ for my $v ($eml->header('Date')) {
$v = ascii_html($v);
obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx; # possible :P
$rv .= "Date: $v\n";
@@ -697,12 +694,12 @@ sub _msg_page_prepare_obuf {
my $lnk = PublicInbox::Linkify->new;
my $s = '';
for my $h (qw(Message-ID X-Alt-Message-ID)) {
- $s .= "$h: $_\n" for ($hdr->header_raw($h));
+ $s .= "$h: $_\n" for ($eml->header_raw($h));
}
$lnk->linkify_mids('..', \$s, 1);
$rv .= $s;
}
- $rv .= _parent_headers($hdr, $over);
+ $rv .= _parent_headers($eml, $over);
$rv .= "\n";
\$rv;
}
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index 814b455b2..7d4139a5d 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -163,9 +163,8 @@ sub import_eml ($$$) {
# any header match means it's eligible for the inbox:
if (my $watch_hdrs = $ibx->{-watchheaders}) {
my $ok;
- my $hdr = $eml->header_obj;
for my $wh (@$watch_hdrs) {
- my @v = $hdr->header_raw($wh->[0]);
+ my @v = $eml->header_raw($wh->[0]);
$ok = grep(/$wh->[1]/, @v) and last;
}
return unless $ok;
diff --git a/lib/PublicInbox/WwwAtomStream.pm b/lib/PublicInbox/WwwAtomStream.pm
index 1ed806fd4..388def123 100644
--- a/lib/PublicInbox/WwwAtomStream.pm
+++ b/lib/PublicInbox/WwwAtomStream.pm
@@ -116,9 +116,8 @@ sub atom_header {
# returns undef or string
sub feed_entry {
my ($ctx, $smsg, $eml) = @_;
- my $hdr = $eml->header_obj;
my $mid = $smsg->{mid};
- my $irt = PublicInbox::View::in_reply_to($hdr);
+ my $irt = PublicInbox::View::in_reply_to($eml);
my $uuid = to_uuid($mid);
my $base = $ctx->{feed_base_url};
if (defined $irt) {
@@ -130,13 +129,13 @@ sub feed_entry {
$irt = '';
}
my $href = $base . mid_href($mid) . '/';
- my $updated = feed_updated(msg_timestamp($hdr));
+ my $updated = feed_updated(msg_timestamp($eml));
- my $title = $hdr->header('Subject');
+ my $title = $eml->header('Subject');
$title = '(no subject)' unless defined $title && $title ne '';
$title = title_tag($title);
- my $from = $hdr->header('From') // $hdr->header('Sender') //
+ my $from = $eml->header('From') // $eml->header('Sender') //
$ctx->{-inbox}->{-primary_address};
my ($email) = PublicInbox::Address::emails($from);
my $name = ascii_html(join(', ', PublicInbox::Address::names($from)));
diff --git a/script/public-inbox-edit b/script/public-inbox-edit
index 2d3c4af4d..240beb3a1 100755
--- a/script/public-inbox-edit
+++ b/script/public-inbox-edit
@@ -93,7 +93,7 @@ Multiple messages with different content found matching
}
} else {
my $eml = eml_from_path($file) or die "open($file) failed: $!";
- my $mids = mids($eml->header_obj);
+ my $mids = mids($eml);
find_mid($found, $_, \@ibxs) for (@$mids); # populates $found
my $chash = content_hash($eml);
my $to_edit = $found->{$chash};
@@ -214,9 +214,9 @@ 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) &&
+ 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);
diff --git a/script/public-inbox-mda b/script/public-inbox-mda
index 42d0e00cb..02ca34316 100755
--- a/script/public-inbox-mda
+++ b/script/public-inbox-mda
@@ -119,7 +119,7 @@ for my $ibx (@$dests) {
# destination succeeds
$emm->abort;
} else { # v1-only
- my $mid = $mime->header_obj->header_raw('Message-ID');
+ my $mid = $mime->header_raw('Message-ID');
# this message is similar to what ssoma-mda shows:
print STDERR "CONFLICT: Message-ID: $mid exists\n";
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-01 8:12 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01 8:12 [PATCH 0/4] cleanup some minor annoyances Eric Wong
2020-08-01 8:12 ` [PATCH 1/4] inboxwritable: mime_from_path: reduce `$/' scope and returns Eric Wong
2020-08-01 8:12 ` [PATCH 2/4] inboxwritable: rename mime_from_path to eml_from_path Eric Wong
2020-08-01 8:12 ` [PATCH 3/4] searchidx: remove v1-only msg_mime sub Eric Wong
2020-08-01 8:12 ` [PATCH 4/4] remove unnecessary ->header_obj calls Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).