From b6b86cfd238c170ea3e2c4d4179f06c7af139086 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 24 Apr 2021 09:28:46 +0000 Subject: lei import: keep sync info for Maildir and IMAP folders We aren't using it, yet, but the plan is to be able to use this information to propagate keyword changes back to IMAP and Maildir folders using some to-be-implemented command. "lei inspect" is a half-baked new command to make testing this change easier. It will be updated to support more SQLite+Xapian introspection duties in the future, including public-inbox things independent of lei. --- lib/PublicInbox/LeiImport.pm | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'lib/PublicInbox/LeiImport.pm') diff --git a/lib/PublicInbox/LeiImport.pm b/lib/PublicInbox/LeiImport.pm index e3c756e8..daaa6753 100644 --- a/lib/PublicInbox/LeiImport.pm +++ b/lib/PublicInbox/LeiImport.pm @@ -13,7 +13,6 @@ sub input_eml_cb { # used by PublicInbox::LeiInput::input_fh my ($self, $eml, $vmd) = @_; my $xoids = $self->{lei}->{ale}->xoids_for($eml); if (my $all_vmd = $self->{all_vmd}) { - $vmd //= {}; @$vmd{keys %$all_vmd} = values %$all_vmd; } $self->{lei}->{sto}->ipc_do('set_eml', $eml, $vmd, $xoids); @@ -31,11 +30,26 @@ sub input_mbox_cb { # MboxReader callback sub input_maildir_cb { # maildir_each_eml cb my ($f, $kw, $eml, $self) = @_; - input_eml_cb($self, $eml, $self->{-import_kw} ? { kw => $kw } : undef); + my $vmd = $self->{-import_kw} ? { kw => $kw } : undef; + if ($self->{-mail_sync}) { + if ($f =~ m!\A(.+?)/(?:new|cur)/([^/]+)\z!) { # ugh... + $vmd->{sync_info} = [ "maildir:$1", \(my $n = $2) ]; + } else { + warn "E: $f was not from a Maildir?\n"; + } + } + input_eml_cb($self, $eml, $vmd); } -sub input_net_cb { # imap_each, nntp_each cb +sub input_imap_cb { # imap_each my ($url, $uid, $kw, $eml, $self) = @_; + my $vmd = $self->{-import_kw} ? { kw => $kw } : undef; + $vmd->{sync_info} = [ $url, $uid ] if $self->{-mail_sync}; + input_eml_cb($self, $eml, $vmd); +} + +sub input_nntp_cb { # nntp_each + my ($url, $num, $kw, $eml, $self) = @_; input_eml_cb($self, $eml, $self->{-import_kw} ? { kw => $kw } : undef); } @@ -61,6 +75,8 @@ sub lei_import { # the main "lei import" method return $lei->fail(join("\n", @{$vmd_mod->{err}})) if $vmd_mod->{err}; $self->{all_vmd} = $vmd_mod if scalar keys %$vmd_mod; $self->prepare_inputs($lei, \@inputs) or return; + $self->{-mail_sync} = $lei->{opt}->{sync} // 1; + $lei->ale; # initialize for workers to read my $j = $lei->{opt}->{jobs} // scalar(@{$self->{inputs}}) || 1; if (my $net = $lei->{net}) { -- cgit v1.2.3-24-ge0c7