diff options
Diffstat (limited to 'lib/PublicInbox/LeiTag.pm')
-rw-r--r-- | lib/PublicInbox/LeiTag.pm | 43 |
1 files changed, 12 insertions, 31 deletions
diff --git a/lib/PublicInbox/LeiTag.pm b/lib/PublicInbox/LeiTag.pm index 817b87f8..da8caeb7 100644 --- a/lib/PublicInbox/LeiTag.pm +++ b/lib/PublicInbox/LeiTag.pm @@ -1,66 +1,47 @@ -# Copyright (C) 2021 all contributors <meta@public-inbox.org> +# Copyright (C) all contributors <meta@public-inbox.org> # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> # handles "lei tag" command package PublicInbox::LeiTag; -use strict; -use v5.10.1; +use v5.12; use parent qw(PublicInbox::IPC PublicInbox::LeiInput); use PublicInbox::InboxWritable qw(eml_from_path); +use PublicInbox::OnDestroy; sub input_eml_cb { # used by PublicInbox::LeiInput::input_fh my ($self, $eml) = @_; if (my $xoids = $self->{lse}->xoids_for($eml) // # tries LeiMailSync $self->{lei}->{ale}->xoids_for($eml)) { $self->{lei}->{sto}->wq_do('update_xvmd', $xoids, $eml, - $self->{vmd_mod}); + $self->{lei}->{vmd_mod}); } else { - ++$self->{unimported}; + ++$self->{-nr_unimported}; } } -sub input_mbox_cb { - my ($eml, $self) = @_; - $eml->header_set($_) for (qw(X-Status Status)); - input_eml_cb($self, $eml); -} - sub pmdir_cb { # called via wq_io_do from LeiPmdir->each_mdir_fn my ($self, $f) = @_; my $eml = eml_from_path($f) or return; input_eml_cb($self, $eml); } -sub input_net_cb { # imap_each, nntp_each cb - my ($url, $uid, $kw, $eml, $self) = @_; - input_eml_cb($self, $eml); -} - sub lei_tag { # the "lei tag" method my ($lei, @argv) = @_; - my $sto = $lei->_lei_store(1); - $sto->write_prepare($lei); + $lei->{opt}->{'in-format'} //= 'eml' if $lei->{opt}->{stdin}; + my $sto = $lei->_lei_store(1)->write_prepare($lei); my $self = bless {}, __PACKAGE__; $lei->ale; # refresh and prepare - my $vmd_mod = $self->vmd_mod_extract(\@argv); - return $lei->fail(join("\n", @{$vmd_mod->{err}})) if $vmd_mod->{err}; - $self->{vmd_mod} = $vmd_mod; # before LeiPmdir->new in prepare_inputs $self->prepare_inputs($lei, \@argv) or return; - grep(defined, @$vmd_mod{qw(+kw +L -L -kw)}) or + grep(defined, @{$lei->{vmd_mod}}{qw(+kw +L -L -kw)}) or return $lei->fail('no keywords or labels specified'); - my $ops = {}; - $lei->{auth}->op_merge($ops, $self) if $lei->{auth}; - (my $op_c, $ops) = $lei->workers_start($self, 1, $ops); - $lei->{wq1} = $self; $lei->{-err_type} = 'non-fatal'; - net_merge_all_done($self) unless $lei->{auth}; - $lei->wait_wq_events($op_c, $ops); + $lei->wq1_start($self); } sub note_unimported { my ($self) = @_; - my $n = $self->{unimported} or return; - $self->{lei}->{pkt_op_p}->pkt_do('incr', 'unimported', $n); + my $n = $self->{-nr_unimported} or return; + $self->{lei}->{pkt_op_p}->pkt_do('incr', -nr_unimported => $n); } sub ipc_atfork_child { @@ -68,7 +49,7 @@ sub ipc_atfork_child { PublicInbox::LeiInput::input_only_atfork_child($self); $self->{lse} = $self->{lei}->{sto}->search; # this goes out-of-scope at worker process exit: - PublicInbox::OnDestroy->new($$, \¬e_unimported, $self); + on_destroy \¬e_unimported, $self; } # Workaround bash word-splitting s to ['kw', ':', 'keyword' ...] |