]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiSearch.pm
lei: flesh out `forwarded' kw support for Maildir and IMAP
[public-inbox.git] / lib / PublicInbox / LeiSearch.pm
index 148aa18510546f603ef9fa6b98790ea8fa4925fe..ff615d890d30d908128ed158271a43ba16b00893 100644 (file)
@@ -8,7 +8,7 @@ use v5.10.1;
 use parent qw(PublicInbox::ExtSearch);
 use PublicInbox::Search qw(xap_terms);
 use PublicInbox::ContentHash qw(content_digest content_hash);
-use PublicInbox::MID qw(mids mids_in);
+use PublicInbox::MID qw(mids mids_for_index);
 
 # get combined docid from over.num:
 # (not generic Xapian, only works with our sharding scheme)
@@ -54,8 +54,7 @@ sub content_key ($) {
        my ($eml) = @_;
        my $dig = content_digest($eml);
        my $chash = $dig->clone->digest;
-       my $mids = mids_in($eml,
-                       qw(Message-ID X-Alt-Message-ID Resent-Message-ID));
+       my $mids = mids_for_index($eml);
        unless (@$mids) {
                $eml->{-lei_fake_mid} = $mids->[0] =
                                PublicInbox::Import::digest2mid($dig, $eml, 0);
@@ -104,8 +103,16 @@ sub kw_changed {
        my $xoids = xoids_for($self, $eml) // return;
        $docids //= [];
        @$docids = sort { $a <=> $b } values %$xoids;
-       my @cur_kw = msg_keywords($self, $docids->[0]);
-       join("\0", @$new_kw_sorted) eq join("\0", @cur_kw) ? 0 : 1;
+       my $cur_kw = msg_keywords($self, $docids->[0]);
+
+       # 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 {