]> diplodocus.org Git - minc/commitdiff
New -r option for rebuilding the .folders file from scratch.
authorepg <>
Fri, 18 Nov 2005 23:57:04 +0000 (23:57 +0000)
committerepg <>
Fri, 18 Nov 2005 23:57:04 +0000 (23:57 +0000)
minc

diff --git a/minc b/minc
index 7f04612..3e30d8c 100755 (executable)
--- a/minc
+++ b/minc
@@ -10,7 +10,7 @@ B<minc> - incorporate mail from a maildir into mh folders
 
 B<minc> [B<-m> I<MAX>] [B<-n>]
 B<minc> B<-d>
-B<minc> B<-h>
+B<minc> B<-r>
 
 =head1 DESCRIPTION
 
@@ -78,6 +78,10 @@ Stop processing after I<MAX> 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);
+}
+
 \f
 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] }