apps/scan.pl: new argument parser, skip directories
authorSebastian <basti@notizbuch>
Tue, 10 Jun 2014 22:56:32 +0000 (00:56 +0200)
committerSebastian <basti@notizbuch>
Tue, 10 Jun 2014 22:56:32 +0000 (00:56 +0200)
Directories inside inbound are now skipped.
Instead of "scan.pl path/", now needs to be called with "scan.pl -i path/".
This allows "-c config -i path".

apps/scan.pl

index 3359852b44ffb9250a162a1ff547dbef1c2f4f1d..0ce3682b94f7d51d26ed45f1cf2b2236cfbbde11 100755 (executable)
@@ -20,13 +20,16 @@ sub handle_mail($); # handles single mail
 
 sub main()
 {
-       if(!$ARGV[0]) {
-               say "Usage: $0 <inbound>";
+       # parse argument list
+       my ($argidx) = grep { $ARGV[$_] eq '-i' } 0..$#ARGV;
+       if(!defined $argidx || !$ARGV[$argidx+1]) {
+               say "Usage: $0 <-i inbound>";
                say "\tinbound: path to binkley-style inbound";
                return(1);
        }
+       my $inbound = $ARGV[$argidx+1];
 
-       my $fails = dispatch($ARGV[0]);
+       my $fails = dispatch($inbound);
        say "Finished with $fails errors.";
 
        # close areas
@@ -53,6 +56,7 @@ sub dispatch($)
        opendir(my $dh, $dirname) or die("Can't open $dirname: $!");
        while(my $file = readdir $dh) {
                next if($file =~ /^\.{1,2}$/);
+               next if(-d "$dirname/$file");
 
                if($file =~ /^[0-9a-f]{8}\.(mo|tu|we|th|fr|sa|su)[0-9a-z]$/i) {
                # ARCMAIL bundle - assume ZIP