#!/usr/local/perl-5.6.0/bin/perl -w
# Based on "rmmallunseen", but it removes the
# "prevunseen" sequence, which is set by "unseen".

use strict;

$| = 1;

if(@ARGV) {
   foreach (@ARGV) {
      do_folder($_);
   }
}
else {
   open FDR, "$ENV{HOME}/Mail/.folders" or die "$!";
   
   while (<FDR>)
   {
       chomp;
       do_folder($_);
   }
}

close FDR;

sub do_folder {
    local $_=shift;
    # Remove pluses at the beginning and slashes at the end
    s/^\+//; s@/+$@@;

    if (open INP, "$ENV{HOME}/Mail/$_/.mh_sequences")
    {
        if (grep(/^prevunseen: /, <INP>))
        {
            print "** $_\n";
            system "rmm +$_ prevunseen";
        }

        close INP;
    }
}

# Original implementation of this program: (too slow)
#!/bin/sh
#rmmunseen `flist -all -noshowzero -recurse -fast`
