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
#
# 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;
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use IO::Handle;
-use PublicInbox::WatchMaildir;
+use PublicInbox::Watch;
use PublicInbox::Config;
use PublicInbox::DS;
use PublicInbox::Sigfd;
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,
PublicInbox::Sigfd::set_sigmask($oldset);
PublicInbox::DS->SetLoopTimeout(1000);
}
- $watch_md->watch($sig, $oldset) while ($watch_md);
+ $watch->watch($sig, $oldset) while ($watch);
}
}
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);
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);
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";
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');
}
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(\<<EOF);
publicinbox.i.address=i\@example.com
publicinbox.i.inboxdir=/nonexistent
publicinbox.i.watch=imap://example.com/INBOX.a
publicinboxlearn.watchspam=imap://example.com/INBOX.spam
EOF
-my $watch = PublicInbox::WatchMaildir->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',
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';
$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');
}
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');
};
$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));
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]);
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));
$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');
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');
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');
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';
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');
};
$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');
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]);
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');
$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');
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]);
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];
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});
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');
$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');
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';
$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');
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',