about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiInput.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/LeiInput.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/LeiInput.pm')
-rw-r--r--lib/PublicInbox/LeiInput.pm41
1 files changed, 37 insertions, 4 deletions
diff --git a/lib/PublicInbox/LeiInput.pm b/lib/PublicInbox/LeiInput.pm
index 0114f5ee..d11d23d4 100644
--- a/lib/PublicInbox/LeiInput.pm
+++ b/lib/PublicInbox/LeiInput.pm
@@ -83,11 +83,13 @@ sub input_path_url {
         my $ifmt = lc($lei->{opt}->{'in-format'} // '');
         # TODO auto-detect?
         if ($input =~ m!\Aimaps?://!i) {
-                $lei->{net}->imap_each($input, $self->can('input_net_cb'),
+                $lei->{net}->imap_each($input, $self->can('input_imap_cb') //
+                                                $self->can('input_net_cb'),
                                         $self, @args);
                 return;
         } elsif ($input =~ m!\A(?:nntps?|s?news)://!i) {
-                $lei->{net}->nntp_each($input, $self->can('input_net_cb'),
+                $lei->{net}->nntp_each($input, $self->can('input_nntp_cb') //
+                                                $self->can('input_net_cb'),
                                         $self, @args);
                 return;
         }
@@ -130,11 +132,13 @@ EOM
 sub prepare_inputs { # returns undef on error
         my ($self, $lei, $inputs) = @_;
         my $in_fmt = $lei->{opt}->{'in-format'};
+        my $sync = $lei->{opt}->{sync} ? {} : undef; # using LeiMailSync
         if ($lei->{opt}->{stdin}) {
                 @$inputs and return
                         $lei->fail("--stdin and @$inputs do not mix");
                 check_input_format($lei) or return;
                 push @$inputs, '/dev/stdin';
+                push @{$sync->{no}}, '/dev/stdin' if $sync;
         }
         my $net = $lei->{net}; # NetWriter may be created by l2m
         my (@f, @d);
@@ -145,6 +149,13 @@ sub prepare_inputs { # returns undef on error
                         require PublicInbox::NetReader;
                         $net //= PublicInbox::NetReader->new;
                         $net->add_url($input);
+                        if ($sync) {
+                                if ($input =~ m!\Aimaps?://!) {
+                                        push @{$sync->{ok}}, $input;
+                                } else {
+                                        push @{$sync->{no}}, $input;
+                                }
+                        }
                 } elsif ($input_path =~ s/\A([a-z0-9]+)://is) {
                         my $ifmt = lc $1;
                         if (($in_fmt // $ifmt) ne $ifmt) {
@@ -152,6 +163,13 @@ sub prepare_inputs { # returns undef on error
 --in-format=$in_fmt and `$ifmt:' conflict
 
                         }
+                        if ($sync) {
+                                if ($ifmt =~ /\A(?:maildir|mh)\z/i) {
+                                        push @{$sync->{ok}}, $input;
+                                } else {
+                                        push @{$sync->{no}}, $input;
+                                }
+                        }
                         my $devfd = $lei->path_to_fd($input_path) // return;
                         if ($devfd >= 0 || (-f $input_path || -p _)) {
                                 require PublicInbox::MboxLock;
@@ -162,6 +180,7 @@ sub prepare_inputs { # returns undef on error
                                 require PublicInbox::MdirReader;
                                 $ifmt eq 'maildir' or return
                                         $lei->fail("$ifmt not supported");
+                                $input = $lei->abs_path($input) if $sync;
                         } else {
                                 return $lei->fail("Unable to handle $input");
                         }
@@ -170,12 +189,18 @@ sub prepare_inputs { # returns undef on error
 $input is `eml', not --in-format=$in_fmt
 
                         require PublicInbox::Eml;
+                        push @{$sync->{no}}, $input if $sync;
                 } else {
                         my $devfd = $lei->path_to_fd($input) // return;
                         if ($devfd >= 0 || -f $input || -p _) {
-                                push @f, $input
+                                push @{$sync->{no}}, $input if $sync;
+                                push @f, $input;
                         } elsif (-d $input) {
-                                push @d, $input
+                                if ($sync) {
+                                        $input = $lei->abs_path($input);
+                                        push @{$sync->{ok}}, $input;
+                                }
+                                push @d, $input;
                         } else {
                                 return $lei->fail("Unable to handle $input")
                         }
@@ -185,6 +210,14 @@ $input is `eml', not --in-format=$in_fmt
         if (@d) { # TODO: check for MH vs Maildir, here
                 require PublicInbox::MdirReader;
         }
+        if ($sync && $sync->{no}) {
+                return $lei->fail(<<"") if !$sync->{ok};
+--sync specified but no inputs support it
+
+                # non-fatal if some inputs support support sync
+                $lei->err("# --sync will only be used for @{$sync->{ok}}");
+                $lei->err("# --sync is not supported for: @{$sync->{no}}");
+        }
         if ($net) {
                 if (my $err = $net->errors) {
                         return $lei->fail($err);