# Copyright (C) 2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
-# parent class for LeiImport, LeiConvert
+# parent class for LeiImport, LeiConvert, LeiIndex
package PublicInbox::LeiInput;
use strict;
use v5.10.1;
my ($fh, $pid) = popen_rd($cmd, undef, $rdr);
grep(/\A--compressed\z/, @$curl) or
$fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1);
- eval {
- PublicInbox::MboxReader->mboxrd($fh,
- $self->can('input_mbox_cb'),
- $self, @args);
- };
+ eval { $self->input_fh('mboxrd', $fh, $url, @args) };
my $err = $@;
waitpid($pid, 0);
$? || $err and
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
+ my $sync = $lei->{opt}->{'mail-sync'} ? {} : undef; # using LeiMailSync
if ($lei->{opt}->{stdin}) {
@$inputs and return
$lei->fail("--stdin and @$inputs do not mix");
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 =~ m!\Ahttps?://!i) {
+ push @{$sync->{ok}}, $input if $sync;
+ } elsif ($input_path =~ m!\Ahttps?://!i) { # mboxrd.gz
+ # TODO: how would we detect r/w JMAP?
+ push @{$sync->{no}}, $input if $sync;
prepare_http_input($self, $lei, $input_path) or return;
} elsif ($input_path =~ s/\A([a-z0-9]+)://is) {
my $ifmt = lc $1;
--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;
- }
+ if ($ifmt =~ /\A(?:maildir|mh)\z/i) {
+ push @{$sync->{ok}}, $input if $sync;
+ } else {
+ push @{$sync->{no}}, $input if $sync;
}
my $devfd = $lei->path_to_fd($input_path) // return;
if ($devfd >= 0 || (-f $input_path || -p _)) {
} else {
return $lei->fail("Unable to handle $input");
}
- } elsif ($input =~ /\.(eml|patch)\z/i && -f $input) {
+ } elsif ($input =~ /\.(?:eml|patch)\z/i && -f $input) {
lc($in_fmt//'eml') eq 'eml' or return $lei->fail(<<"");
$input is `eml', not --in-format=$in_fmt
}
if ($sync && $sync->{no}) {
return $lei->fail(<<"") if !$sync->{ok};
---sync specified but no inputs support it
+--mail-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}}");
+ $lei->err("# --mail-sync will only be used for @{$sync->{ok}}");
+ $lei->err("# --mail-sync is not supported for: @{$sync->{no}}");
}
if ($net) {
$net->{-can_die} = 1;
- if (my $err = $net->errors) {
+ if (my $err = $net->errors($lei)) {
return $lei->fail($err);
}
$net->{quiet} = $lei->{opt}->{quiet};
undef;
}
+# alias this as "net_merge_all_done" to use as an LeiAuth callback
+sub input_only_net_merge_all_done {
+ my ($self) = @_;
+ $self->wq_io_do('process_inputs');
+ $self->wq_close(1);
+}
+
# like Getopt::Long, but for +kw:FOO and -kw:FOO to prepare
# for update_xvmd -> update_vmd
sub vmd_mod_extract {