From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 7D0D81F406 for ; Wed, 22 Nov 2023 01:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1700615058; bh=rXkClx1J0UQ3zaon7falRbKWKpy20XLWZRv0em8qqmQ=; h=From:To:Subject:Date:From; b=u1gCTJgCyE4aH8SyJ8Pe7ihulC1OVVShmVjyTxuFFE+waLVVnUxEYR1KqxTRtyA0j 8Y4QWWX3lWxFSFnvzHhniulH6lKEK46ETM4kIw+f7tWL1of2DoDG5hSdA1nulWiqvZ lz63inxewsslkRHwg5RPGIoMoouQMcr7EPTtyCIY= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] watch: support `watch=false' to negate watchspam Date: Wed, 22 Nov 2023 01:04:18 +0000 Message-ID: <20231122010418.3422792-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: For users hosting read-only mirrors (via clone|fetch) and feeding inboxes via -watch --- I'm also considering a `fetchonly' directive for -learn/-mda, too; but I think overloading watch can coexist with that... Documentation/public-inbox-watch.pod | 5 ++++- lib/PublicInbox/Watch.pm | 6 +++++- t/watch_maildir.t | 12 +++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Documentation/public-inbox-watch.pod b/Documentation/public-inbox-watch.pod index 7c21f7ce..6f812966 100644 --- a/Documentation/public-inbox-watch.pod +++ b/Documentation/public-inbox-watch.pod @@ -78,7 +78,7 @@ C paths: [publicinbox "test"] watch = maildir:/path/to/maildirs/.INBOX.test/ -public-inbox 1.6.0 supports C, C, +public-inbox 1.6.0+ supports C, C, C and C URLs: watch = nntp://news.example.com/inbox.test.group @@ -89,6 +89,9 @@ into a single public-inbox. URLs requiring authentication will require L and/or L (preferred) to fill in the username and password. +public-inbox 2.0+ supports boolean C to prevent the global +L directive from writing to the inbox. + Default: none =item publicinbox..watchheader diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm index 5253ec94..b83a77eb 100644 --- a/lib/PublicInbox/Watch.pm +++ b/lib/PublicInbox/Watch.pm @@ -85,7 +85,10 @@ sub new { $watches = PublicInbox::Config::_array($watches); for my $watch (@$watches) { my $uri; - if (is_maildir($watch)) { + my $bool = $cfg->git_bool($watch); + if (defined $bool && !$bool) { + $ibx->{-watch_disabled} = 1; + } elsif (is_maildir($watch)) { compile_watchheaders($ibx); my ($new, $cur) = ("$watch/new", "$watch/cur"); my $cur_dst = $mdmap{$cur} //= []; @@ -143,6 +146,7 @@ sub _done_for_now { sub remove_eml_i { # each_inbox callback my ($ibx, $self, $eml, $loc) = @_; + return if $ibx->{-watch_disabled}; eval { # try to avoid taking a lock or unnecessary spawning diff --git a/t/watch_maildir.t b/t/watch_maildir.t index 69a5e1f3..07ebeef6 100644 --- a/t/watch_maildir.t +++ b/t/watch_maildir.t @@ -16,7 +16,6 @@ use_ok 'PublicInbox::Emergency'; my $addr = 'test-public@example.com'; my $default_branch = PublicInbox::Import::default_branch; PublicInbox::Import::init_bare($git_dir); - my $msg = <add(PublicInbox::Eml->new($msg)) }; + PublicInbox::Emergency->new($maildir)->prepare(\$msg); ok(POSIX::mkfifo("$maildir/cur/fifo", 0777), 'create FIFO to ensure we do not get stuck on it :P'); @@ -56,6 +58,10 @@ my $cfg = cfg_new $tmpdir, <{inboxdir} + address = ro-test\@example.com EOF my $cfg_path = $cfg->{-f}; PublicInbox::Watch->new($cfg)->scan('full'); @@ -82,6 +88,10 @@ is(scalar @list, 2, 'two revisions in rev-list'); is(scalar @list, 0, 'tree is empty'); is(unlink(glob("$spamdir/cur/*")), 1, 'unlinked trained spam'); +@list = $ibx_ro->git->qx(qw(ls-tree -r --name-only), $default_branch); +undef $ibx_ro; +is scalar(@list), 1, 'read-only inbox is unchanged'; + # check with scrubbing { $msg .= qq(--