From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 369111FA10; Mon, 31 Aug 2020 04:41:41 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Cc: Eric Wong Subject: [PATCH 03/11] rename WatchMaildir => Watch Date: Mon, 31 Aug 2020 04:41:32 +0000 Message-Id: <20200831044140.17027-4-e@80x24.org> In-Reply-To: <20200831044140.17027-1-e@80x24.org> References: <20200831044140.17027-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Eric Wong This is no longer limited to Maildirs now that IMAP and NNTP support exist; so give it a shorter name. --- MANIFEST | 2 +- lib/PublicInbox/{WatchMaildir.pm => Watch.pm} | 2 +- script/public-inbox-watch | 18 +++++++-------- t/imapd.t | 2 +- t/nntpd.t | 2 +- t/watch_filter_rubylang.t | 4 ++-- t/watch_imap.t | 4 ++-- t/watch_maildir.t | 18 +++++++-------- t/watch_maildir_v2.t | 22 +++++++++---------- t/watch_multiple_headers.t | 4 ++-- t/watch_nntp.t | 4 ++-- 11 files changed, 41 insertions(+), 41 deletions(-) rename lib/PublicInbox/{WatchMaildir.pm => Watch.pm} (99%) diff --git a/MANIFEST b/MANIFEST index 35adc8d3..f090175e 100644 --- a/MANIFEST +++ b/MANIFEST @@ -200,7 +200,7 @@ lib/PublicInbox/ViewDiff.pm lib/PublicInbox/ViewVCS.pm lib/PublicInbox/WWW.pm lib/PublicInbox/WWW.pod -lib/PublicInbox/WatchMaildir.pm +lib/PublicInbox/Watch.pm lib/PublicInbox/WwwAltId.pm lib/PublicInbox/WwwAtomStream.pm lib/PublicInbox/WwwAttach.pm diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/Watch.pm similarity index 99% rename from lib/PublicInbox/WatchMaildir.pm rename to lib/PublicInbox/Watch.pm index 1c7ac6c0..5f786139 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/Watch.pm @@ -3,7 +3,7 @@ # # ref: https://cr.yp.to/proto/maildir.html # http://wiki2.dovecot.org/MailboxFormat/Maildir -package PublicInbox::WatchMaildir; +package PublicInbox::Watch; use strict; use v5.10.1; use PublicInbox::Eml; diff --git a/script/public-inbox-watch b/script/public-inbox-watch index 20534bf2..02491860 100755 --- a/script/public-inbox-watch +++ b/script/public-inbox-watch @@ -3,7 +3,7 @@ # License: AGPL-3.0+ use strict; use IO::Handle; -use PublicInbox::WatchMaildir; +use PublicInbox::Watch; use PublicInbox::Config; use PublicInbox::DS; use PublicInbox::Sigfd; @@ -11,18 +11,18 @@ use PublicInbox::Syscall qw($SFD_NONBLOCK); my $oldset = PublicInbox::Sigfd::block_signals(); STDOUT->autoflush(1); STDERR->autoflush(1); -my ($config, $watch_md); +my ($config, $watch); my $reload = sub { $config = PublicInbox::Config->new; - $watch_md->quit if $watch_md; - $watch_md = PublicInbox::WatchMaildir->new($config); + $watch->quit if $watch; + $watch = PublicInbox::Watch->new($config); }; $reload->(); -if ($watch_md) { - my $scan = sub { $watch_md->trigger_scan('full') if $watch_md }; +if ($watch) { + my $scan = sub { $watch->trigger_scan('full') if $watch }; my $quit = sub { - $watch_md->quit if $watch_md; - $watch_md = undef; + $watch->quit if $watch; + $watch = undef; }; my $sig = { HUP => $reload, @@ -41,5 +41,5 @@ if ($watch_md) { PublicInbox::Sigfd::set_sigmask($oldset); PublicInbox::DS->SetLoopTimeout(1000); } - $watch_md->watch($sig, $oldset) while ($watch_md); + $watch->watch($sig, $oldset) while ($watch); } diff --git a/t/imapd.t b/t/imapd.t index 8db72bd7..f743bf06 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -449,7 +449,7 @@ ok($mic->logout, 'logged out'); } SKIP: { - use_ok 'PublicInbox::WatchMaildir'; + use_ok 'PublicInbox::Watch'; use_ok 'PublicInbox::InboxIdle'; require_git('1.8.5', 1) or skip('git 1.8.5+ needed for --urlmatch', 4); diff --git a/t/nntpd.t b/t/nntpd.t index 74e21a41..d8a44334 100644 --- a/t/nntpd.t +++ b/t/nntpd.t @@ -396,7 +396,7 @@ sub read_til_dot { sub test_watch { my ($tmpdir, $sock, $group) = @_; - use_ok 'PublicInbox::WatchMaildir'; + use_ok 'PublicInbox::Watch'; use_ok 'PublicInbox::InboxIdle'; use_ok 'PublicInbox::Config'; require_git('1.8.5', 1) or skip('git 1.8.5+ needed for --urlmatch', 4); diff --git a/t/watch_filter_rubylang.t b/t/watch_filter_rubylang.t index db48cb2f..4b72dbae 100644 --- a/t/watch_filter_rubylang.t +++ b/t/watch_filter_rubylang.t @@ -7,7 +7,7 @@ use Test::More; use PublicInbox::Eml; use PublicInbox::Config; require_mods(qw(DBD::SQLite Search::Xapian)); -use_ok 'PublicInbox::WatchMaildir'; +use_ok 'PublicInbox::Watch'; use_ok 'PublicInbox::Emergency'; my ($tmpdir, $for_destroy) = tmpdir(); local $ENV{PI_CONFIG} = "$tmpdir/pi_config"; @@ -76,7 +76,7 @@ EOF my $ibx = $config->lookup_name($v); ok($ibx, 'found inbox by name'); - my $w = PublicInbox::WatchMaildir->new($config); + my $w = PublicInbox::Watch->new($config); for my $i (1..2) { $w->scan('full'); } diff --git a/t/watch_imap.t b/t/watch_imap.t index 9433bb6f..fb71d3df 100644 --- a/t/watch_imap.t +++ b/t/watch_imap.t @@ -5,14 +5,14 @@ use Test::More; use PublicInbox::Config; # see t/imapd*.t for tests against a live IMAP server -use_ok 'PublicInbox::WatchMaildir'; +use_ok 'PublicInbox::Watch'; my $cfg = PublicInbox::Config->new(\<new($cfg); +my $watch = PublicInbox::Watch->new($cfg); is($watch->{imap}->{'imap://example.com/INBOX.a'}->[0]->{name}, 'i', 'watched an inbox'); is($watch->{imap}->{'imap://example.com/INBOX.spam'}, 'watchspam', diff --git a/t/watch_maildir.t b/t/watch_maildir.t index c44273f0..ae53caf9 100644 --- a/t/watch_maildir.t +++ b/t/watch_maildir.t @@ -11,7 +11,7 @@ my ($tmpdir, $for_destroy) = tmpdir(); my $git_dir = "$tmpdir/test.git"; my $maildir = "$tmpdir/md"; my $spamdir = "$tmpdir/spam"; -use_ok 'PublicInbox::WatchMaildir'; +use_ok 'PublicInbox::Watch'; use_ok 'PublicInbox::Emergency'; my $cfgpfx = "publicinbox.test"; my $addr = 'test-public@example.com'; @@ -40,7 +40,7 @@ $cfgpfx.inboxdir=$git_dir $cfgpfx.watch=maildir:$spamdir publicinboxlearn.watchspam=maildir:$spamdir EOF - my $wm = PublicInbox::WatchMaildir->new($config); + my $wm = PublicInbox::Watch->new($config); is(scalar grep(/is a spam folder/, @w), 1, 'got warning about spam'); is_deeply($wm->{mdmap}, { "$spamdir/cur" => 'watchspam' }, 'only got the spam folder to watch'); @@ -62,7 +62,7 @@ EOF } my $config = PublicInbox::Config->new($cfg_path); -PublicInbox::WatchMaildir->new($config)->scan('full'); +PublicInbox::Watch->new($config)->scan('full'); my $git = PublicInbox::Git->new($git_dir); my @list = $git->qx(qw(rev-list refs/heads/master)); is(scalar @list, 1, 'one revision in rev-list'); @@ -79,7 +79,7 @@ my $write_spam = sub { }; $write_spam->(); is(unlink(glob("$maildir/new/*")), 1, 'unlinked old spam'); -PublicInbox::WatchMaildir->new($config)->scan('full'); +PublicInbox::Watch->new($config)->scan('full'); @list = $git->qx(qw(rev-list refs/heads/master)); is(scalar @list, 2, 'two revisions in rev-list'); @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master)); @@ -93,7 +93,7 @@ To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo\@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html\n); PublicInbox::Emergency->new($maildir)->prepare(\$msg); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master)); is(scalar @list, 1, 'tree has one file'); my $mref = $git->cat_file('HEAD:'.$list[0]); @@ -101,7 +101,7 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); is(unlink(glob("$maildir/new/*")), 1, 'unlinked spam'); $write_spam->(); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master)); is(scalar @list, 0, 'tree is empty'); @list = $git->qx(qw(rev-list refs/heads/master)); @@ -118,7 +118,7 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); $config->{'publicinboxwatch.spamcheck'} = 'spamc'; { local $SIG{__WARN__} = sub {}; # quiet spam check warning - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); } @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master)); is(scalar @list, 0, 'tree has no files spamc checked'); @@ -133,7 +133,7 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); PublicInbox::Emergency->new($maildir)->prepare(\$msg); $config->{'publicinboxwatch.spamcheck'} = 'spamc'; @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master)); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); @list = $git->qx(qw(ls-tree -r --name-only refs/heads/master)); is(scalar @list, 1, 'tree has one file after spamc checked'); @@ -211,7 +211,7 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); sub is_maildir { my ($dir) = @_; - PublicInbox::WatchMaildir::is_maildir($dir); + PublicInbox::Watch::is_maildir($dir); } is(is_maildir('maildir:/hello//world'), '/hello/world', 'extra slash gone'); diff --git a/t/watch_maildir_v2.t b/t/watch_maildir_v2.t index 59ec247e..ca1cf965 100644 --- a/t/watch_maildir_v2.t +++ b/t/watch_maildir_v2.t @@ -14,7 +14,7 @@ my ($tmpdir, $for_destroy) = tmpdir(); my $inboxdir = "$tmpdir/v2"; my $maildir = "$tmpdir/md"; my $spamdir = "$tmpdir/spam"; -use_ok 'PublicInbox::WatchMaildir'; +use_ok 'PublicInbox::Watch'; use_ok 'PublicInbox::Emergency'; my $cfgpfx = "publicinbox.test"; my $addr = 'test-public@example.com'; @@ -49,7 +49,7 @@ my $ibx = $config->lookup_name('test'); ok($ibx, 'found inbox by name'); my $srch = $ibx->search; -PublicInbox::WatchMaildir->new($config)->scan('full'); +PublicInbox::Watch->new($config)->scan('full'); my $total = scalar @{$srch->reopen->query('')}; is($total, 1, 'got one revision'); @@ -69,7 +69,7 @@ my $write_spam = sub { }; $write_spam->(); is(unlink(glob("$maildir/new/*")), 1, 'unlinked old spam'); -PublicInbox::WatchMaildir->new($config)->scan('full'); +PublicInbox::Watch->new($config)->scan('full'); is_deeply($srch->reopen->query(''), [], 'deleted file'); is(unlink(glob("$spamdir/cur/*")), 1, 'unlinked trained spam'); @@ -80,7 +80,7 @@ To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo\@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html\n); PublicInbox::Emergency->new($maildir)->prepare(\$msg); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); my $msgs = $srch->reopen->query(''); is(scalar(@$msgs), 1, 'got one file back'); my $mref = $ibx->msg_by_smsg($msgs->[0]); @@ -88,7 +88,7 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); is(unlink(glob("$maildir/new/*")), 1, 'unlinked spam'); $write_spam->(); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); $msgs = $srch->reopen->query(''); is(scalar(@$msgs), 0, 'inbox is empty again'); is(unlink(glob("$spamdir/cur/*")), 1, 'unlinked trained spam'); @@ -103,7 +103,7 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); $config->{'publicinboxwatch.spamcheck'} = 'spamc'; { local $SIG{__WARN__} = sub {}; # quiet spam check warning - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); } my $msgs = $srch->reopen->query(''); is(scalar(@$msgs), 0, 'inbox is still empty'); @@ -117,7 +117,7 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); local $ENV{PATH} = $main_path; PublicInbox::Emergency->new($maildir)->prepare(\$msg); $config->{'publicinboxwatch.spamcheck'} = 'spamc'; - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); my $msgs = $srch->reopen->query(''); is(scalar(@$msgs), 1, 'inbox has one mail after spamc OK-ed a message'); my $mref = $ibx->msg_by_smsg($msgs->[0]); @@ -130,7 +130,7 @@ More majordomo info at http://vger.kernel.org/majordomo-info.html\n); open my $fh, '<', $patch or die "failed to open $patch: $!\n"; $msg = do { local $/; <$fh> }; PublicInbox::Emergency->new($maildir)->prepare(\$msg); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); my $msgs = $srch->reopen->query('dfpost:6e006fd7'); is(scalar(@$msgs), 1, 'diff postimage found'); my $post = $msgs->[0]; @@ -161,7 +161,7 @@ Date: Sat, 18 Jun 2016 00:00:00 +0000 both EOF PublicInbox::Emergency->new($maildir)->prepare(\$both); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); my $msgs = $srch->reopen->query('m:both@b.com'); my $v1 = $config->lookup_name('v1'); my $msg = $v1->git->cat_file($msgs->[0]->{blob}); @@ -186,7 +186,7 @@ EOF PublicInbox::Emergency->new($maildir)->prepare(\$want); PublicInbox::Emergency->new($maildir)->prepare(\$do_not_want); my $config = PublicInbox::Config->new(\$cfg); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); $ibx = $config->lookup_name('test'); my $num = $ibx->mm->num_for('do.want@example.com'); ok(defined $num, 'List-ID matched for watch'); @@ -195,7 +195,7 @@ EOF $cfg = $orig."$cfgpfx.watchheader=X-Mailing-List:no\@example.com\n"; $config = PublicInbox::Config->new(\$cfg); - PublicInbox::WatchMaildir->new($config)->scan('full'); + PublicInbox::Watch->new($config)->scan('full'); $ibx = $config->lookup_name('test'); $num = $ibx->mm->num_for('do.not.want@example.com'); ok(defined $num, 'X-Mailing-List matched'); diff --git a/t/watch_multiple_headers.t b/t/watch_multiple_headers.t index 0ee96d5f..a0813532 100644 --- a/t/watch_multiple_headers.t +++ b/t/watch_multiple_headers.t @@ -9,7 +9,7 @@ require_mods(qw(Search::Xapian DBD::SQLite)); my ($tmpdir, $for_destroy) = tmpdir(); my $inboxdir = "$tmpdir/v2"; my $maildir = "$tmpdir/md"; -use_ok 'PublicInbox::WatchMaildir'; +use_ok 'PublicInbox::Watch'; use_ok 'PublicInbox::Emergency'; my $cfgpfx = "publicinbox.test"; my $addr = 'test-public@example.com'; @@ -62,7 +62,7 @@ $cfgpfx.watchheader=To:$addr $cfgpfx.watchheader=Cc:$addr EOF my $config = PublicInbox::Config->new(\$cfg); -PublicInbox::WatchMaildir->new($config)->scan('full'); +PublicInbox::Watch->new($config)->scan('full'); my $ibx = $config->lookup_name('test'); ok($ibx, 'found inbox by name'); diff --git a/t/watch_nntp.t b/t/watch_nntp.t index 98fb1161..ce1a3153 100644 --- a/t/watch_nntp.t +++ b/t/watch_nntp.t @@ -5,8 +5,8 @@ use Test::More; use PublicInbox::Config; # see t/nntpd*.t for tests against a live NNTP server -use_ok 'PublicInbox::WatchMaildir'; -my $nntp_url = \&PublicInbox::WatchMaildir::nntp_url; +use_ok 'PublicInbox::Watch'; +my $nntp_url = \&PublicInbox::Watch::nntp_url; is('news://example.com/inbox.foo', $nntp_url->('NEWS://examplE.com/inbox.foo'), 'lowercased'); is('nntps://example.com/inbox.foo',