]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiRm.pm
lei rm|tag: drop redundant mbox+net callbacks
[public-inbox.git] / lib / PublicInbox / LeiRm.pm
1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # implements the "lei rm" command, you can point this at
5 # an entire spam mailbox or read a message from stdin
6 package PublicInbox::LeiRm;
7 use strict;
8 use v5.10.1;
9 use parent qw(PublicInbox::IPC PublicInbox::LeiInput);
10
11 sub input_eml_cb { # used by PublicInbox::LeiInput::input_fh
12         my ($self, $eml) = @_;
13         $self->{lei}->{sto}->wq_do('remove_eml', $eml);
14 }
15
16 sub input_maildir_cb {
17         my (undef, $kw, $eml, $self) = @_; # $_[0] $filename ignored
18         input_eml_cb($self, $eml);
19 }
20
21 sub lei_rm {
22         my ($lei, @inputs) = @_;
23         $lei->_lei_store(1)->write_prepare($lei);
24         $lei->{opt}->{'in-format'} //= 'eml';
25         my $self = bless {}, __PACKAGE__;
26         $self->prepare_inputs($lei, \@inputs) or return;
27         my ($op_c, $ops) = $lei->workers_start($self, 1);
28         $lei->{wq1} = $self;
29         $lei->{-err_type} = 'non-fatal';
30         net_merge_all_done($self) unless $lei->{auth};
31         $lei->wait_wq_events($op_c, $ops);
32 }
33
34 no warnings 'once';
35 *ipc_atfork_child = \&PublicInbox::LeiInput::input_only_atfork_child;
36 *net_merge_all_done = \&PublicInbox::LeiInput::input_only_net_merge_all_done;
37
38 1;