X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FLeiStore.pm;h=a23efed55198e96c4ac5446c7681af235b58781c;hb=af0b0fb7a454470a32c452119d0392e0dedb3fe1;hp=2745c56047faa65efc3c2e210f6e9893043d4809;hpb=3ae5275eb187ed00bb83061a4d37a161bc8eb3e7;p=public-inbox.git
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index 2745c560..a23efed5 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 all contributors
+# Copyright (C) 2020-2021 all contributors
# License: AGPL-3.0+
#
# Local storage (cache/memo) for lei(1), suitable for personal/private
@@ -15,8 +15,8 @@ use PublicInbox::ExtSearchIdx;
use PublicInbox::Import;
use PublicInbox::InboxWritable;
use PublicInbox::V2Writable;
-use PublicInbox::ContentHash qw(content_hash);
-use PublicInbox::MID qw(mids);
+use PublicInbox::ContentHash qw(content_hash content_digest);
+use PublicInbox::MID qw(mids mids_in);
use PublicInbox::LeiSearch;
use List::Util qw(max);
@@ -107,14 +107,26 @@ sub eidx_init {
$eidx;
}
+# when a message has no Message-IDs at all, this is needed for
+# unsent Draft messages, at least
+sub _fake_mid_for ($$) {
+ my ($eml, $dig) = @_;
+ my $mids = mids_in($eml, qw(X-Alt-Message-ID Resent-Message-ID));
+ $eml->{-lei_fake_mid} =
+ $mids->[0] // PublicInbox::Import::digest2mid($dig, $eml);
+}
+
sub _docids_for ($$) {
my ($self, $eml) = @_;
my %docids;
- my $chash = content_hash($eml);
+ my $dig = content_digest($eml);
+ my $chash = $dig->clone->digest;
my $eidx = eidx_init($self);
my $oidx = $eidx->{oidx};
my $im = $self->{im};
- for my $mid (@{mids($eml)}) {
+ my $mids = mids($eml);
+ $mids->[0] //= _fake_mid_for($eml, $dig);
+ for my $mid (@$mids) {
my ($id, $prev);
while (my $cur = $oidx->next_by_mid($mid, \$id, \$prev)) {
my $oid = $cur->{blob};
@@ -199,6 +211,7 @@ sub add_eml {
$idx->shard_add_eidx_info($docid, '.', $eml); # List-Id
$idx->shard_add_keywords($docid, @kw) if @kw;
}
+ \@docids;
} else {
$smsg->{num} = $oidx->adj_counter('eidx_docid', '+');
$oidx->add_overview($eml, $smsg);
@@ -206,8 +219,13 @@ sub add_eml {
my $idx = $eidx->idx_shard($smsg->{num});
$idx->index_raw($msgref, $eml, $smsg);
$idx->shard_add_keywords($smsg->{num}, @kw) if @kw;
+ $smsg;
}
- $smsg->{blob}
+}
+
+sub set_eml {
+ my ($self, $eml, @kw) = @_;
+ add_eml($self, $eml, @kw) // set_eml_keywords($self, $eml, @kw);
}
sub done {