use strict;
use warnings;
+$SIG{'PIPE'} = 'IGNORE';
+
use Data::Dumper;
use Errno;
use Fcntl qw(O_WRONLY O_EXCL O_CREAT);
}
if (@result <= 2) {
- exit(0);
+ return ();
}
STDOUT->autoflush(1);
}
}
- return $msgnum_cache{$mhfolder} = $highest;
+ $msgnum_cache{$mhfolder} = $highest;
+ return $msgnum_cache{$mhfolder}++;
}
sub mark {
my $marked = 0;
open($fh, '>', $fn) or die("open(>$fn): $!");
for $_ (@sequences) {
- if (/^$seq: /) {
- print($fh "$_ $msgnum\n");
+ if (/^$seq: (.*)/) {
+ my @parts;
+ my @result;
+ my $done = 0;
+ for my $part (split(' ', $1)) {
+ if (not $done) {
+ my ($st, $en) = split('-', $part);
+ if ((defined($en) and ($msgnum >= $st and $msgnum <= $en))
+ or $msgnum == $st) {
+ # It's already there.
+ $done = 1;
+ }
+ if (defined($en)) {
+ if ($st - 1 == $msgnum) {
+ $part = "$msgnum-$en";
+ $done = 1;
+ } elsif ($en + 1 == $msgnum) {
+ $part = "$st-$msgnum";
+ $done = 1;
+ }
+ } else {
+ if ($part - 1 == $msgnum) {
+ $part = "$msgnum-$part";
+ $done = 1;
+ } elsif ($part + 1 == $msgnum) {
+ $part = "$part-$msgnum";
+ $done = 1;
+ }
+ }
+ }
+ push(@result, $part);
+ }
+ if (not $done) {
+ push(@result, $msgnum);
+ }
+ print($fh "$seq: ", join(' ', @result), "\n");
$marked = 1;
} else {
print($fh "$_\n");
}
sub filter_mail {
+ @_ or return ();
my $msgcount = @_ - 2; # don't count . and ..
my $len = length($msgcount);
my @baton;
for ($from, $subject) {
tr/\x00-\x1f\x80-\xff/ /;
}
- print("\r");
- print(' ' x $COLUMNS);
printf("\r\%-${nf}s \%${nm}d \%-${nF}s \%s\n",
substr($mhfolder, 0, $nf), substr($msgnum, 0, $nm),
substr($from, 0, $nF),
$hook->(\%batons, \%headers, $mhfolder, $msgnum);
}
- print("\r");
printf(" \%${len}d SPAM \%${len}d saved \%${len}d/%1d",
$spam, $saved, $spam + $saved, $msgcount);
build_dot_folders($folders, $fh);
}
+# XXX Could use some unification with getfiles...
+sub maildir_spam {
+ my $dir = "$MAILDIR/spam";
+
+ if (not chdir($dir)) {
+ print(STDERR "skipping maildir spam: chdir($dir): $!\n");
+ return;
+ }
+
+ if (not opendir(DIR, '.')) {
+ print(STDERR "skipping maildir spam: opendir($dir): $!\n");
+ return;
+ }
+
+ $! = 0;
+ my @spams = readdir(DIR);
+ if ($! != 0) {
+ print(STDERR "skipping maildir spam: readdir($dir): $!\n");
+ return;
+ }
+
+ closedir(DIR);
+
+ for my $msg (@spams) {
+ ($msg eq '.' or $msg eq '..') and next;
+ store_message($msg, 'SPAM');
+ }
+}
+
\f
MAIN: {
my $st;
}
getfiles('.'));
- $run and update_dot_folders(\%folders);
+ $run and %folders and update_dot_folders(\%folders);
+
+ maildir_spam();
@SPAM and (exec('scan', '+SPAM', @SPAM) or die);
}