]> diplodocus.org Git - minc/blobdiff - minc
Correct minor oops in last.
[minc] / minc
diff --git a/minc b/minc
index 8ac7af2..f8d54dd 100755 (executable)
--- a/minc
+++ b/minc
@@ -37,6 +37,8 @@ rest of the line.
 use strict;
 use warnings;
 
+$SIG{'PIPE'} = 'IGNORE';
+
 use Data::Dumper;
 use Errno;
 use Fcntl qw(O_WRONLY O_EXCL O_CREAT);
@@ -292,7 +294,7 @@ sub getfiles {
     }
 
     if (@result <= 2) {
-        exit(0);
+        return ();
     }
 
     STDOUT->autoflush(1);
@@ -340,7 +342,8 @@ sub get_highest_msgnum {
         }
     }
 
-    return  $msgnum_cache{$mhfolder} = $highest;
+    $msgnum_cache{$mhfolder} = $highest;
+    return $msgnum_cache{$mhfolder}++;
 }
 
 sub mark {
@@ -361,8 +364,42 @@ 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");
@@ -568,6 +605,7 @@ sub find_mh_folder {
 }
 
 sub filter_mail {
+    @_ or return ();
     my $msgcount = @_ - 2; # don't count . and ..
     my $len = length($msgcount);
     my @baton;
@@ -625,8 +663,6 @@ sub filter_mail {
             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),
@@ -637,7 +673,6 @@ sub filter_mail {
             $hook->(\%batons, \%headers, $mhfolder, $msgnum);
         }
 
-        print("\r");
         printf(" \%${len}d SPAM \%${len}d saved \%${len}d/%1d",
                $spam, $saved, $spam + $saved, $msgcount);
 
@@ -709,6 +744,35 @@ sub update_dot_folders {
     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;
@@ -733,7 +797,9 @@ MAIN: {
                 }
                 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);
 }