]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiStore.pm
Merge remote-tracking branch 'origin/master' into lorelei
[public-inbox.git] / lib / PublicInbox / LeiStore.pm
index d3667d29ba5d4eb42bd42248f94baa46707a90aa..553adbc8f84d4cdf4b79935330098ddce0d28203 100644 (file)
@@ -52,6 +52,14 @@ sub git_epoch_max  {
        }
 }
 
+sub git_ident ($) {
+       my ($git) = @_;
+       chomp(my $i = $git->qx(qw(var GIT_COMMITTER_IDENT)));
+       warn "$git->{git_dir} GIT_COMMITTER_IDENT failed\n" if $?;
+       $i =~ /\A(.+) <([^>]+)> [0-9]+ [-\+]?[0-9]+$/ ? ($1, $2) :
+               ('lei user', 'x@example.com')
+}
+
 sub importer {
        my ($self) = @_;
        my $max;
@@ -79,10 +87,7 @@ sub importer {
                        $max++;
                        next;
                }
-               chomp(my $i = $git->qx(qw(var GIT_COMMITTER_IDENT)));
-               die "$git->{git_dir} GIT_COMMITTER_IDENT failed\n" if $?;
-               my ($n, $e) = ($i =~ /\A(.+) <([^>]+)> [0-9]+ [-\+]?[0-9]+$/g)
-                       or die "could not extract name/email from `$i'\n";
+               my ($n, $e) = git_ident($git);
                $self->{im} = $im = PublicInbox::Import->new($git, $n, $e);
                $im->{bytes_added} = int($packed_bytes / $self->packing_factor);
                $im->{lock_path} = undef;
@@ -157,8 +162,27 @@ sub remove_eml_keywords {
        \@docids;
 }
 
+# cf: https://doc.dovecot.org/configuration_manual/mail_location/mbox/
+my %status2kw = (F => 'flagged', A => 'answered', R => 'seen', T => 'draft');
+# O (old/non-recent), and D (deleted) aren't in JMAP,
+# so probably won't be supported by us.
+sub mbox_keywords {
+       my $eml = $_[-1];
+       my $s = "@{[$eml->header_raw('X-Status'),$eml->header_raw('Status')]}";
+       my %kw;
+       $s =~ s/([FART])/$kw{$status2kw{$1}} = 1/sge;
+       sort(keys %kw);
+}
+
+# cf: https://cr.yp.to/proto/maildir.html
+my %c2kw = ('D' => 'draft', F => 'flagged', R => 'answered', S => 'seen');
+sub maildir_keywords {
+       $_[-1] =~ /:2,([A-Z]+)\z/i ?
+               sort(map { $c2kw{$_} // () } split(//, $1)) : ();
+}
+
 sub add_eml {
-       my ($self, $eml) = @_;
+       my ($self, $eml, @kw) = @_;
        my $eidx = eidx_init($self);
        my $oidx = $eidx->{oidx};
        my $smsg = bless { -oidx => $oidx }, 'PublicInbox::Smsg';
@@ -173,6 +197,7 @@ sub add_eml {
                        my $idx = $eidx->idx_shard($docid);
                        $oidx->add_xref3($docid, -1, $smsg->{blob}, '.');
                        $idx->shard_add_eidx_info($docid, '.', $eml); # List-Id
+                       $idx->shard_add_keywords($docid, @kw) if @kw;
                }
        } else {
                $smsg->{num} = $oidx->adj_counter('eidx_docid', '+');
@@ -180,6 +205,7 @@ sub add_eml {
                $oidx->add_xref3($smsg->{num}, -1, $smsg->{blob}, '.');
                my $idx = $eidx->idx_shard($smsg->{num});
                $idx->index_raw($msgref, $eml, $smsg);
+               $idx->shard_add_keywords($smsg->{num}, @kw) if @kw;
        }
        $smsg->{blob}
 }