+sub index_eml_only {
+ my ($self, $eml, $vmd, $xoids) = @_;
+ require PublicInbox::FakeImport;
+ local $self->{-fake_im} = PublicInbox::FakeImport->new;
+ set_eml($self, $eml, $vmd, $xoids);
+}
+
+# store {kw} / {L} info for a message which is only in an external
+sub _external_only ($$$) {
+ my ($self, $xoids, $eml) = @_;
+ my $eidx = $self->{priv_eidx};
+ my $oidx = $eidx->{oidx} // die 'BUG: {oidx} missing';
+ my $smsg = bless { blob => '' }, 'PublicInbox::Smsg';
+ $smsg->{num} = $oidx->adj_counter('eidx_docid', '+');
+ # save space for an externals-only message
+ my $hdr = $eml->header_obj;
+ $smsg->populate($hdr); # sets lines == 0
+ $smsg->{bytes} = 0;
+ delete @$smsg{qw(From Subject)};
+ $smsg->{to} = $smsg->{cc} = $smsg->{from} = '';
+ $oidx->add_overview($hdr, $smsg); # subject+references for threading
+ $smsg->{subject} = '';
+ for my $oid (keys %$xoids) {
+ $oidx->add_xref3($smsg->{num}, -1, $oid, '.');
+ }
+ my $idx = $eidx->idx_shard($smsg->{num});
+ $idx->index_eml(PublicInbox::Eml->new("\n\n"), $smsg);
+ ($smsg, $idx);
+}
+
+sub update_xvmd {
+ my ($self, $xoids, $eml, $vmd_mod) = @_;
+ my ($eidx, $tl) = eidx_init($self);
+ my $oidx = $eidx->{oidx};
+ my %seen;
+ for my $oid (keys %$xoids) {
+ my $docid = oid2docid($self, $oid) // next;
+ delete $xoids->{$oid};
+ next if $seen{$docid}++;
+ my $idx = $eidx->idx_shard($docid);
+ $idx->ipc_do('update_vmd', $docid, $vmd_mod);
+ sto_export_kw($self, $docid, $vmd_mod);
+ }
+ return unless scalar(keys(%$xoids));
+
+ # see if it was indexed, but with different OID(s)
+ if (my @docids = _docids_for($self, $eml)) {
+ for my $docid (@docids) {
+ next if $seen{$docid};
+ for my $oid (keys %$xoids) {
+ $oidx->add_xref3($docid, -1, $oid, '.');
+ }
+ my $idx = $eidx->idx_shard($docid);
+ $idx->ipc_do('update_vmd', $docid, $vmd_mod);
+ sto_export_kw($self, $docid, $vmd_mod);
+ }
+ return;
+ }
+ # totally unseen
+ my ($smsg, $idx) = _external_only($self, $xoids, $eml);
+ $idx->ipc_do('update_vmd', $smsg->{num}, $vmd_mod);
+ sto_export_kw($self, $smsg->{num}, $vmd_mod);
+}
+
+# set or update keywords for external message, called via ipc_do
+sub set_xvmd {
+ my ($self, $xoids, $eml, $vmd) = @_;
+
+ my ($eidx, $tl) = eidx_init($self);
+ my $oidx = $eidx->{oidx};
+ my %seen;
+
+ # see if we can just update existing docs
+ for my $oid (keys %$xoids) {
+ my $docid = oid2docid($self, $oid) // next;
+ delete $xoids->{$oid}; # all done with this oid
+ next if $seen{$docid}++;
+ my $idx = $eidx->idx_shard($docid);
+ $idx->ipc_do('set_vmd', $docid, $vmd);
+ sto_export_kw($self, $docid, $vmd);
+ }
+ return unless scalar(keys(%$xoids));
+
+ # n.b. we don't do _docids_for here, we expect the caller
+ # already checked $lse->kw_changed before calling this sub
+
+ return unless (@{$vmd->{kw} // []}) || (@{$vmd->{L} // []});
+ # totally unseen:
+ my ($smsg, $idx) = _external_only($self, $xoids, $eml);
+ $idx->ipc_do('add_vmd', $smsg->{num}, $vmd);
+ sto_export_kw($self, $smsg->{num}, $vmd);
+}
+
+sub checkpoint {
+ my ($self, $wait) = @_;
+ if (my $im = $self->{im}) {
+ $wait ? $im->barrier : $im->checkpoint;
+ }
+ delete $self->{lms};
+ $self->{priv_eidx}->checkpoint($wait);
+}
+
+sub xchg_stderr {