From: epg <> Date: Fri, 18 Nov 2005 23:57:04 +0000 (+0000) Subject: New -r option for rebuilding the .folders file from scratch. X-Git-Url: https://diplodocus.org/git/minc/commitdiff_plain/0d20b1e81a638b44245e079b0c0ae1953bd1e519?hp=273e9a40598df888eea9bc49346b63723c03d2d6 New -r option for rebuilding the .folders file from scratch. --- diff --git a/minc b/minc index 7f04612..3e30d8c 100755 --- a/minc +++ b/minc @@ -10,7 +10,7 @@ B - incorporate mail from a maildir into mh folders B [B<-m> I] [B<-n>] B B<-d> -B B<-h> +B B<-r> =head1 DESCRIPTION @@ -78,6 +78,10 @@ Stop processing after I messages. 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 @@ -86,12 +90,14 @@ my $dumpfilters; 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(); @@ -603,20 +609,16 @@ sub filter_mail { 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") }; @@ -638,6 +640,28 @@ sub update_dot_folders { 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); +} + MAIN: { my $st; @@ -649,6 +673,8 @@ MAIN: { 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] }