diff options
author | Eric Wong <e@80x24.org> | 2021-07-19 08:59:35 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-07-22 02:29:00 +0000 |
commit | 5b4fde37adefa37508d131dbe013353ef3345051 (patch) | |
tree | bfd68b4f1fedf94464776a5760a4dc531f1d097e /lib/PublicInbox/LeiAddWatch.pm | |
parent | 7e1c18af5468c7708e28de759911ec5542d23c4b (diff) | |
download | public-inbox-5b4fde37adefa37508d131dbe013353ef3345051.tar.gz |
This allows lei to automatically note keyword (message flag) changes made to a Maildir and propagate it into lei/store: lei add-watch --state=tag-ro /path/to/Maildir This doesn't persist across restarts, yet. In the future, it will be applied automatically to "lei q" output Maildirs by default (with an option to disable it). State values of tag-rw, index-<ro|rw>, import-<ro|rw> will all be supported for Maildir. This represents a fairly major internal change that's fairly intrusive, but the whole daemon-oriented design was to facilitate being able to automatically monitor (and propagate) Maildir/IMAP flag changes.
Diffstat (limited to 'lib/PublicInbox/LeiAddWatch.pm')
-rw-r--r-- | lib/PublicInbox/LeiAddWatch.pm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiAddWatch.pm b/lib/PublicInbox/LeiAddWatch.pm new file mode 100644 index 00000000..671d54f9 --- /dev/null +++ b/lib/PublicInbox/LeiAddWatch.pm @@ -0,0 +1,41 @@ +# Copyright all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> + +# "lei add-watch" command +package PublicInbox::LeiAddWatch; +use strict; +use v5.10.1; +use parent qw(PublicInbox::LeiInput); + +sub lei_add_watch { + my ($lei, @argv) = @_; + my $cfg = $lei->_lei_cfg(1); + my $self = bless {}, __PACKAGE__; + $lei->{opt}->{'mail-sync'} = 1; # for prepare_inputs + my $state = $lei->{opt}->{'state'} // 'import-rw'; + $lei->watch_state_ok($state) or + return $lei->fail("invalid state: $state"); + my $vmd_mod = $self->vmd_mod_extract(\@argv); + return $lei->fail(join("\n", @{$vmd_mod->{err}})) if $vmd_mod->{err}; + $self->prepare_inputs($lei, \@argv) or return; + my @vmd; + while (my ($type, $vals) = each %$vmd_mod) { + push @vmd, "$type:$_" for @$vals; + } + my $vmd0 = shift @vmd; + for my $w (@{$self->{inputs}}) { + # clobber existing, allow multiple + if (defined($vmd0)) { + $lei->_config("watch.$w.vmd", '--replace-all', $vmd0); + for my $v (@vmd) { + $lei->_config("watch.$w.vmd", $v); + } + } + next if defined $cfg->{"watch.$w.state"}; + $lei->_config("watch.$w.state", $state); + } + delete $lei->{cfg}; # force reload + $lei->refresh_watches; +} + +1; |