- my ($self, $eml, $new_kw_sorted) = @_;
- my $found = xids_for($self, $eml, 1) // return;
- my ($num) = values %$found;
- my @cur_kw = msg_keywords($self, $num);
- join("\0", @$new_kw_sorted) eq join("\0", @cur_kw) ? 0 : 1;
+ my ($self, $eml, $new_kw_sorted, $docids) = @_;
+ my $cur_kw;
+ if ($eml) {
+ my $xoids = xoids_for($self, $eml) // return;
+ $docids //= [];
+ @$docids = sort { $a <=> $b } values %$xoids;
+ }
+ for my $id (@$docids) {
+ $cur_kw = eval { msg_keywords($self, $id) } and last;
+ }
+ if (!defined($cur_kw) && $@) {
+ $docids = join(', num:', @$docids);
+ croak "E: num:$docids keyword lookup failure: $@";
+ }
+ # RFC 5550 sec 5.9 on the $Forwarded keyword states:
+ # "Once set, the flag SHOULD NOT be cleared"
+ if (exists($cur_kw->{forwarded}) &&
+ !grep(/\Aforwarded\z/, @$new_kw_sorted)) {
+ delete $cur_kw->{forwarded};
+ }
+ $cur_kw = join("\0", sort keys %$cur_kw);
+ join("\0", @$new_kw_sorted) eq $cur_kw ? 0 : 1;
+}
+
+sub all_terms {
+ my ($self, $pfx) = @_;
+ my $xdb = $self->xdb;
+ my $cur = $xdb->allterms_begin($pfx);
+ my $end = $xdb->allterms_end($pfx);
+ my %ret;
+ for (; $cur != $end; $cur++) {
+ my $tn = $cur->get_termname;
+ index($tn, $pfx) == 0 and
+ $ret{substr($tn, length($pfx))} = undef;
+ }
+ wantarray ? (sort keys %ret) : \%ret;
+}
+
+sub qparse_new {
+ my ($self) = @_;
+ my $qp = $self->SUPER::qparse_new; # PublicInbox::Search
+ $qp->add_boolean_prefix('kw', 'K');
+ $qp->add_boolean_prefix('L', 'L');
+ $qp
+}
+
+sub lms {
+ my ($self) = @_;
+ require PublicInbox::LeiMailSync;
+ my $f = "$self->{topdir}/mail_sync.sqlite3";
+ -f $f ? PublicInbox::LeiMailSync->new($f) : undef;
+}
+
+# allow SolverGit->resolve_patch to work with "lei index"
+sub smsg_eml {
+ my ($self, $smsg) = @_;
+ PublicInbox::Inbox::smsg_eml($self, $smsg) // do {
+ my $lms = lms($self);
+ my $bref = $lms ? $lms->local_blob($smsg->{blob}, 1) : undef;
+ $bref ? PublicInbox::Eml->new($bref) : undef;
+ };