]> diplodocus.org Git - minc/blobdiff - minc
File::Basename hasn't been used since we stopped using `mhpath new`.
[minc] / minc
diff --git a/minc b/minc
index 790ecfe..a8eb94f 100755 (executable)
--- a/minc
+++ b/minc
@@ -8,7 +8,7 @@ B<minc> - Incorporate mail from a maildir into mh folders.
 
 =head1 SYNOPSIS
 
-B<minc> [-B<dfhnps>]
+B<minc> [-B<dmnp>]
 
 =head1 DESCRIPTION
 
@@ -29,13 +29,14 @@ use Data::Dumper;
 use Errno;
 use Fcntl qw(O_WRONLY O_EXCL O_CREAT);
 use FileHandle;
-use File::Basename;
 use File::stat;
-use Getopt::Std;
+use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1;
 use Log::Dispatch;
 use Log::Dispatch::File;
 use POSIX qw(strftime WEXITSTATUS WIFEXITED);
 
+our $VERSION = 1;
+
 # If a filter set's header is $MAGIC_TO_TOKEN, that set is compared
 # against headers matching this regex (taken from procmail).
 my $MAGIC_TO_REGEX = '^((Original-)?(Resent-)?(To|Cc|Bcc)|(X-Envelope |Apparently(-Resent)?)-To)';
@@ -54,10 +55,14 @@ my @SPAM;
 Dump (using Data::Dumper) the FILTERS list and exit.  This is useful
 for testing the syntax of .mincfilter.
 
-=item B<-h>
+=item B<--help>
 
 Show help.
 
+=item B<-m> I<MAX>
+
+Stop processing after I<MAX> messages.
+
 =item B<-n>
 
 Dry run; do not actually incorporate the mail, but log and report to
@@ -74,28 +79,27 @@ problem.
 =cut
 
 my $dumpfilters = 0;
+my $maxmsgs;
 our $run = 1;
 my $printfilenames = 0;
 
-our $opt_d;
-our $opt_h;
-our $opt_n;
-our $opt_p;
+my %opts;
 
-if (not getopts('dhnp')) {
+if (not getopts('dm:np', \%opts)) {
     exit(2);
 }
 
-if ($opt_d) {
+if ($opts{'d'}) {
     $dumpfilters = 1;
-} elsif ($opt_h) {
-    print("Sorry bub, no help.\n");
-    exit;
-} elsif ($opt_n) {
+} elsif ($opts{'n'}) {
     $run = 0;
 }
 
-if ($opt_p) {
+if (defined($opts{'m'})) {
+    $maxmsgs = $opts{'m'};
+}
+
+if ($opts{'p'}) {
     $printfilenames = 1;
 }
 
@@ -579,6 +583,7 @@ sub find_mh_folder {
 sub filter_mail {
     my @msglist = @_;
     my $msgcount = scalar(@msglist);
+    my $msgcountlen = length($msgcount);
     my @baton;
     my $msg;
     my $mhfolder;
@@ -588,7 +593,6 @@ sub filter_mail {
 
     @baton = spam_start_hook();
 
-
     STDOUT->autoflush(1);
     print("$msgcount messages...");
     foreach $msg (@msglist) {
@@ -604,13 +608,15 @@ sub filter_mail {
 
         print("\r");
         if (not $FOLDERS{$mhfolder}) {
-            print(' ' x length($msgcount));
+            print(' ' x $msgcountlen);
             print("                                \r+$mhfolder\n");
             $FOLDERS{$mhfolder} = 1;
         }
 
         printf('%6d SPAM %6d saved %6d/%1d',
                $spam, $saved, $spam + $saved, $msgcount);
+
+        defined($maxmsgs) and ($spam + $saved < $maxmsgs or last);
     }
     print("\n");
 
@@ -724,6 +730,9 @@ stolen from Adam Lazur <adam@lazur.org>.
 
 Design by Eric Gillespie and Doug Porter <dsp@waterspout.com>.
 
+This program is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
 =cut
 
 # Local variables: