X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FWatchMaildir.pm;h=f81a917c5ab74070425a309c3ae3f25a93981fd4;hb=5bde05b66f084c7c9dcf7389079aab6925aef328;hp=0b284bdba41bc5dcf0de46e0f8711a3f679ba3ea;hpb=c265481528208a832c5731b8da597554f2a8f693;p=public-inbox.git diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 0b284bdb..f81a917c 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -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,11 +247,17 @@ sub _scrubber_for { my ($inbox) = @_; my $f = $inbox->{filter}; if ($f && $f =~ /::/) { + 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+/; + eval "require $f"; if ($@) { warn $@; } else { - return $f->new; + # e.g: PublicInbox::Filter::Vger->new(@args) + return $f->new(@args); } } undef;