]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/WatchMaildir.pm
watch: ensure HUP causes the scanner to be reloaded
[public-inbox.git] / lib / PublicInbox / WatchMaildir.pm
index 1823c24862e6e6da36112ce86f123692f1b82e1d..f81a917c5ab74070425a309c3ae3f25a93981fd4 100644 (file)
@@ -97,7 +97,8 @@ sub _try_fsn_paths {
 
 sub _remove_spam {
        my ($self, $path) = @_;
-       $path =~ /:2,[A-R]*S[T-Z]*\z/i or return;
+       # path must be marked as (S)een
+       $path =~ /:2,[A-R]*S[T-Za-z]*\z/ or return;
        my $mime = _path_to_mime($path) or return;
        _force_mid($mime);
        $self->{config}->each_inbox(sub {
@@ -107,10 +108,14 @@ sub _remove_spam {
                        $im->remove($mime);
                        if (my $scrub = _scrubber_for($ibx)) {
                                my $scrubbed = $scrub->scrub($mime) or return;
+                               $scrubbed == 100 and return;
                                $im->remove($scrubbed);
                        }
                };
-               warn "error removing spam at $path from $ibx->{name}\n" if $@;
+               if ($@) {
+                       warn "error removing spam at: ", $path,
+                               " from ", $ibx->{name}, ': ', $@, "\n";
+               }
        })
 }
 
@@ -165,13 +170,17 @@ sub _try_path {
                return unless ($v && $v =~ $wm->[1]);
        }
        if (my $scrub = _scrubber_for($inbox)) {
-               $mime = $scrub->scrub($mime) or return;
+               my $ret = $scrub->scrub($mime) or return;
+               $ret == 100 and return;
+               $mime = $ret;
        }
 
        _force_mid($mime);
        $im->add($mime, $self->{spamcheck});
 }
 
+sub quit { $_[0]->{quit} = 1 }
+
 sub watch {
        my ($self) = @_;
        my $cb = sub { _try_fsn_paths($self, \@_) };
@@ -181,7 +190,7 @@ sub watch {
        # in the future...
        require Filesys::Notify::Simple;
        my $watcher = Filesys::Notify::Simple->new($mdir);
-       $watcher->wait($cb) while (1);
+       $watcher->wait($cb) until ($self->{quit});
 }
 
 sub scan {
@@ -238,7 +247,7 @@ sub _scrubber_for {
        my ($inbox) = @_;
        my $f = $inbox->{filter};
        if ($f && $f =~ /::/) {
-               my @args;
+               my @args = (-inbox => $inbox);
                # basic line splitting, only
                # Perhaps we can have proper quote splitting one day...
                ($f, @args) = split(/\s+/, $f) if $f =~ /\s+/;