-# Copyright (C) 2016 all contributors <meta@public-inbox.org>
+# Copyright (C) 2016-2018 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
#
# ref: https://cr.yp.to/proto/maildir.html
sub _done_for_now {
my ($self) = @_;
+ my $importers = $self->{importers};
+ foreach my $im (values %$importers) {
+ $im->done if $im->{nchg};
+ }
+
my $opendirs = $self->{opendirs};
# spamdir scanning means every importer remains open
my $spamdir = $self->{spamdir};
return if defined($spamdir) && $opendirs->{$spamdir};
- foreach my $im (values %{$self->{importers}}) {
+ foreach my $im (values %$importers) {
# not done if we're scanning
next if $opendirs->{$im->{git}->{git_dir}};
$im->done;
my ($ibx) = @_;
eval {
my $im = _importer_for($self, $ibx);
- $im->remove($mime);
+ $im->remove($mime, 'spam');
if (my $scrub = _scrubber_for($ibx)) {
my $scrubbed = $scrub->scrub($mime) or return;
$scrubbed == 100 and return;
- $im->remove($scrubbed);
+ $im->remove($scrubbed, 'spam');
}
};
if ($@) {
$im->add($mime, $self->{spamcheck});
}
-sub quit { $_[0]->{quit} = 1 }
+sub quit { trigger_scan($_[0], 'quit') }
sub watch {
my ($self) = @_;
# in the future...
require Filesys::Notify::Simple;
my $fsn = Filesys::Notify::Simple->new([@{$self->{mdir}}, $scandir]);
- $fsn->wait($cb) until ($self->{quit});
+ $fsn->wait($cb) until $self->{quit};
}
sub trigger_scan {
my ($self, $base) = @_;
- my $dir = $self->{scandir} or die "not watch-ing, yet\n";
+ my $dir = $self->{scandir} or return;
open my $fh, '>', "$dir/$base" or die "open $dir/$base failed: $!\n";
close $fh or die "close $dir/$base failed: $!\n";
}
sub scan {
my ($self, $path) = @_;
+ if ($path =~ /quit\z/) {
+ %{$self->{opendirs}} = ();
+ _done_for_now($self);
+ delete $self->{scandir};
+ $self->{quit} = 1;
+ return;
+ }
+ # else: $path =~ /(cont|full)\z/
+ return if $self->{quit};
my $max = 10;
my $opendirs = $self->{opendirs};
my @dirnames = keys %$opendirs;
$opendirs->{$dir} = $dh if $n < 0;
}
}
- if (keys %$opendirs) { # do we have more work to do?
- trigger_scan($self, 'cont');
- } else {
- _done_for_now($self);
- }
+ _done_for_now($self);
+ # do we have more work to do?
+ trigger_scan($self, 'cont') if keys %$opendirs;
}
sub _path_to_mime {