B<minc> [B<-m> I<MAX>] [B<-n>]
B<minc> B<-d>
-B<minc> B<-h>
+B<minc> B<-r>
=head1 DESCRIPTION
Dry run; do not actually incorporate the mail, but log and report to
stdout/stderr as normal.
+=item B<-r>
+
+Rebuild `mhpath +`/.folders from scratch, processing no mail.
+
=back
=cut
my $help;
my $maxmsgs;
my $norun;
+my $rebuild_dot_folders;
GetOptions(
'd' => \$dumpfilters,
'h|help' => \$help,
'm=i' => \$maxmsgs,
'n' => \$norun,
+ 'r' => \$rebuild_dot_folders,
) or pod2usage();
$help and pod2usage(-exitstatus=>0, -verbose=>1);
@ARGV == 0 or pod2usage();
return %folders;
}
-sub update_dot_folders {
+sub build_dot_folders {
my $folders = shift;
- my ($fh, $fn);
+ my $fh = shift;
+ my $fn;
- if (open($fh, "$mh/.folders")) {
+ if (defined($fh)) {
while (<$fh>) {
chomp;
$folders->{$_}++;
}
- } elsif (not $!{ENOENT}) {
- # For ENOENT, we go ahead and create it, else we error and
- # don't clobber it.
- warn("open($mh/.folders): $!");
- return;
}
eval { ($fh, $fn) = tempfile("$mh/.folders.XXXXX") };
rename($fn, "$mh/.folders") or warn("rename($fn, $mh/.folders): $!");
}
+sub create_dot_folders {
+ my %folders;
+ open(my $fh, '-|', 'folders', '-fast', '-recur')
+ or die("open(folders|): $!");
+ build_dot_folders(\%folders, $fh);
+ return 0;
+}
+
+sub update_dot_folders {
+ my $folders = shift;
+ my $fh;
+
+ if (not open($fh, "$mh/.folders") and not $!{ENOENT}) {
+ # For ENOENT, we go ahead and create it, else we error and
+ # don't clobber it.
+ warn("open($mh/.folders): $!");
+ return;
+ }
+
+ build_dot_folders($folders, $fh);
+}
+
\f
MAIN: {
my $st;
exit;
}
+ $rebuild_dot_folders and exit(create_dot_folders);
+
chdir("$MAILDIR/new") or die("chdir($MAILDIR/new): $!");
my %folders = filter_mail(map { $_->[1] }
sort { $a->[0] <=> $b->[0] }