From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id E986D20189; Sun, 19 Jun 2016 03:44:10 +0000 (UTC) Date: Sun, 19 Jun 2016 03:44:10 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 5/4] watch_maildir: tighten up path checks Message-ID: <20160619034410.GA15456@dcvr.yhbt.net> References: <20160619002847.26685-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160619002847.26685-1-e@80x24.org> List-Id: Only mark seen messages as spam, otherwise it could be too aggressive and cause problems or over training. We wouldn't want a wayward FIFO ruining our day, either :) --- lib/PublicInbox/WatchMaildir.pm | 12 +++++------- t/watch_maildir.t | 3 ++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index cb64f89..4468a44 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -71,6 +71,7 @@ sub _try_fsn_paths { sub _check_spam { my ($self, $path) = @_; + $path =~ /:2,[A-R]*S[T-Z]*\z/ or return; my $mime = _path_to_mime($path) or return; _force_mid($mime); foreach my $inbox (values %{$self->{mdmap}}) { @@ -107,6 +108,9 @@ sub _force_mid { sub _try_path { my ($self, $path) = @_; + my @p = split(m!/+!, $path); + return unless $p[-1] =~ /\A[a-zA-Z0-9][\w:,=\.]+\z/; + return unless -f $path; if ($path !~ $self->{mdre}) { warn "unrecognized path: $path\n"; return; @@ -155,13 +159,7 @@ sub scan { next; } while (my $fn = readdir($dh)) { - next unless $fn =~ /\A[a-zA-Z0-9][\w:,=\.]+\z/; - $fn = "$dir/$fn"; - if (-f $fn) { - _try_path($self, $fn); - } else { - warn "not a file: $fn\n"; - } + _try_path($self, "$dir/$fn"); } closedir $dh; } diff --git a/t/watch_maildir.t b/t/watch_maildir.t index 8a2c934..e8c9740 100644 --- a/t/watch_maildir.t +++ b/t/watch_maildir.t @@ -25,6 +25,7 @@ Date: Sat, 18 Jun 2016 00:00:00 +0000 something EOF PublicInbox::Emergency->new($maildir)->prepare(\$msg); +ok(POSIX::mkfifo("$maildir/cur/fifo", 0777)); my $sem = PublicInbox::Emergency->new($spamdir); # create dirs my $config = PublicInbox::Config->new({ @@ -47,7 +48,7 @@ my $write_spam = sub { my @new = glob("$spamdir/new/*"); is(scalar @new, 1); my @p = split(m!/+!, $new[0]); - ok(link($new[0], "$spamdir/cur/".$p[-1])); + ok(link($new[0], "$spamdir/cur/".$p[-1].":2,S")); is(unlink($new[0]), 1); }; $write_spam->();