From a00fdf39b4ec4ed045f28c29c79c8dcb9abac836 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 22 Mar 2021 07:53:57 +0000 Subject: lei: share input code between convert and import These commands accept mail the same way, and this forces us to maintain consistent input format support between commands. We'll be using this for "lei mark", too. --- lib/PublicInbox/LeiConvert.pm | 60 ++++--------------------------------------- 1 file changed, 5 insertions(+), 55 deletions(-) (limited to 'lib/PublicInbox/LeiConvert.pm') diff --git a/lib/PublicInbox/LeiConvert.pm b/lib/PublicInbox/LeiConvert.pm index 8d3b221a..0aa13229 100644 --- a/lib/PublicInbox/LeiConvert.pm +++ b/lib/PublicInbox/LeiConvert.pm @@ -5,7 +5,7 @@ package PublicInbox::LeiConvert; use strict; use v5.10.1; -use parent qw(PublicInbox::IPC); +use parent qw(PublicInbox::IPC PublicInbox::LeiInput); use PublicInbox::Eml; use PublicInbox::LeiStore; use PublicInbox::LeiOverview; @@ -79,64 +79,14 @@ sub do_convert { # via wq_do sub lei_convert { # the main "lei convert" method my ($lei, @inputs) = @_; - my $opt = $lei->{opt}; - $opt->{kw} //= 1; + $lei->{opt}->{kw} //= 1; + $lei->{opt}->{dedupe} //= 'none'; my $self = $lei->{cnv} = bless {}, __PACKAGE__; - my $in_fmt = $opt->{'in-format'}; - my (@f, @d); - $opt->{dedupe} //= 'none'; my $ovv = PublicInbox::LeiOverview->new($lei, 'out-format'); $lei->{l2m} or return $lei->fail("output not specified or is not a mail destination"); - my $net = $lei->{net}; # NetWriter may be created by l2m - $opt->{augment} = 1 unless $ovv->{dst} eq '/dev/stdout'; - if ($opt->{stdin}) { - @inputs and return $lei->fail("--stdin and @inputs do not mix"); - $lei->check_input_format(undef) or return; - $self->{0} = $lei->{0}; - } - # e.g. Maildir:/home/user/Mail/ or imaps://example.com/INBOX - for my $input (@inputs) { - my $input_path = $input; - if ($input =~ m!\A(?:imaps?|nntps?|s?news)://!i) { - require PublicInbox::NetReader; - $net //= PublicInbox::NetReader->new; - $net->add_url($input); - } elsif ($input_path =~ s/\A([a-z0-9]+)://is) { - my $ifmt = lc $1; - if (($in_fmt // $ifmt) ne $ifmt) { - return $lei->fail(<<""); ---in-format=$in_fmt and `$ifmt:' conflict - - } - if (-f $input_path) { - require PublicInbox::MboxLock; - require PublicInbox::MboxReader; - PublicInbox::MboxReader->can($ifmt) or return - $lei->fail("$ifmt not supported"); - } elsif (-d _) { - require PublicInbox::MdirReader; - $ifmt eq 'maildir' or return - $lei->fail("$ifmt not supported"); - } else { - return $lei->fail("Unable to handle $input"); - } - } elsif (-f $input) { push @f, $input } - elsif (-d _) { push @d, $input } - else { return $lei->fail("Unable to handle $input") } - } - if (@f) { $lei->check_input_format(\@f) or return } - if (@d) { # TODO: check for MH vs Maildir, here - require PublicInbox::MdirReader; - } - $self->{inputs} = \@inputs; - if ($net) { - if (my $err = $net->errors) { - return $lei->fail($err); - } - $net->{quiet} = $opt->{quiet}; - $lei->{net} //= $net; - } + $lei->{opt}->{augment} = 1 unless $ovv->{dst} eq '/dev/stdout'; + $self->prepare_inputs($lei, \@inputs) or return; my $op = $lei->workers_start($self, 'lei_convert', 1, { '' => [ $lei->can('dclose'), $lei ] }); -- cgit v1.2.3-24-ge0c7