user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] watch: support `watch=false' to negate watchspam
@ 2023-11-22  1:04  7% Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2023-11-22  1:04 UTC (permalink / raw)
  To: meta

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<maildir:> paths:
 	[publicinbox "test"]
 		watch = maildir:/path/to/maildirs/.INBOX.test/
 
-public-inbox 1.6.0 supports C<nntp://>, C<nntps://>,
+public-inbox 1.6.0+ supports C<nntp://>, C<nntps://>,
 C<imap://> and C<imaps://> URLs:
 
 		watch = nntp://news.example.com/inbox.test.group
@@ -89,6 +89,9 @@ into a single public-inbox.  URLs requiring authentication
 will require L<netrc(5)> and/or L<git-credential(1)> (preferred) to fill
 in the username and password.
 
+public-inbox 2.0+ supports boolean C<false> to prevent the global
+L</publicinboxwatch.watchspam> directive from writing to the inbox.
+
 Default: none
 
 =item publicinbox.<name>.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 = <<EOF;
 From: user\@example.com
 To: $addr
@@ -26,6 +25,9 @@ Date: Sat, 18 Jun 2016 00:00:00 +0000
 
 something
 EOF
+
+my $ibx_ro = create_inbox 'ro', sub { $_[0]->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, <<EOF;
 	filter = PublicInbox::Filter::Vger
 [publicinboxlearn]
 	watchspam = maildir:$spamdir
+[publicinbox "test-ro"]
+	watch = false
+	inboxdir = $ibx_ro->{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(--

^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2023-11-22  1:04  7% [PATCH] watch: support `watch=false' to negate watchspam Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).