about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiImport.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-04-24 09:28:46 +0000
committerEric Wong <e@80x24.org>2021-04-24 16:10:03 -0400
commitb6b86cfd238c170ea3e2c4d4179f06c7af139086 (patch)
treebfca234b1b6a95baeb88e9fabb8fd9d90a5f6d8a /lib/PublicInbox/LeiImport.pm
parent7dd4d590e1d5e12b2b767122aeec66124a10acb1 (diff)
downloadpublic-inbox-b6b86cfd238c170ea3e2c4d4179f06c7af139086.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/LeiImport.pm')
-rw-r--r--lib/PublicInbox/LeiImport.pm22
1 files changed, 19 insertions, 3 deletions
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}) {