Added mhbuild: -nocontentid to profile used for tests, to simplify
[mmh] / docs / historical / mh-6.8.5 / miscellany / audit / rfolder
1 #!/usr/bin/perl
2
3 $program = $0;
4 $program =~ s|.*/||;
5 $| = 1;
6
7 unshift(@INC, $ENV{'DELIVERPATH'});
8 require 'audit.pl' || die "$program: cannot include audit.pl: $@";
9 require 'mh.pl' || die "$program: cannot include mh.pl: $@";
10
11
12 @SW = (
13         '-exec',
14         '-except "+folder..."',
15         '-all',
16         '-verbose',
17         '-clean',
18         '-debug',
19         '-recurse',
20         '-norecurse',
21         '-help',
22       );
23
24
25 &mh_profile();
26
27 ($folder = shift @ARGV) if ($ARGV[0] =~ /^\+/);
28
29 &mh_parse();
30
31 defined($SW{'help'}) && do {
32     print "syntax: $program [+folder] [switches] [-exec MH command]\n";
33     &print_switches();
34     exit;
35 };
36
37
38 #if (!defined($folder)) {
39 #    $mailpath = $MH{'path'} . '/';
40 #    $folder = `mhpath`; chop $folder; 
41 #    $folder =~ s|^$mailpath|\+|;
42 #};
43
44
45 @args = (($program =~ /s$/) ? ("-all") : ( )); 
46 for ('all', 'recurse', 'norecurse') {
47     push(@args, "-$_") if defined($SW{$_});
48 };
49
50
51 if (defined($SW{'exec'})) {
52     @command = @ARGV;
53 } else {
54     exec "folder $folder @args";
55 };
56
57
58 $path = `mhpath $folder`; chop $path;
59 die "$0: unable to change directory to $path: No such file or directory.\n" 
60     if (! -d $path);
61
62
63 open(FOLDERS, "folder $folder @args -fast -noheader |") || die 
64         "$0: cannot find list of folders: $?";
65
66 @exceptions = split(' ', $SW{'except'});
67
68 SKIP:
69 while (<FOLDERS>) {
70     chop; 
71     for $ef (@exceptions) {
72         ($f = $ef) =~ s/^\+//;
73         next SKIP if ($_ =~ m|$f|);
74         $f = `mhpath +$f`; chop $f;
75         next SKIP if ($_ eq $f);
76     };
77
78     if (defined($SW{'clean'})) {
79         $contents = `folder +$_ -total`; 
80         if ($contents =~ /\s+0\s+messages/) {
81             print "removing empty folder +$_...\n" if defined($SW{'verbose'});
82             $f = `mhpath +$_`; chop $f;
83             rmdir($f) unless defined($SW{'debug'});
84             next; 
85         };
86     };
87
88     print "@command +$_ \n" if defined($SW{'verbose'});
89     system "@command +$_" unless (defined($SW{'debug'})); 
90     print "\n";
91 };
92
93 close(FOLDERS);
94