]> Sergey Matveev's repositories - public-inbox.git/commitdiff
watch_maildir: tighten up path checks
authorEric Wong <e@80x24.org>
Sun, 19 Jun 2016 02:13:52 +0000 (02:13 +0000)
committerEric Wong <e@80x24.org>
Sun, 19 Jun 2016 02:23:50 +0000 (02:23 +0000)
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
t/watch_maildir.t

index cb64f899fb27e277b8a6032100f18683c35ff5e3..4468a4484fd63dfdbca81aa3bf193fd48a3f4c89 100644 (file)
@@ -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;
        }
index 8a2c934a36f05623d373392c648142c8fd630afd..e8c97406eb59e976aec3056af96ef57f027c07ed 100644 (file)
@@ -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->();