forked from haqistan/mblaze-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmnewdirs
executable file
·53 lines (46 loc) · 1.18 KB
/
mnewdirs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env perl
##
# find maildirs with new messages by default spit out lines like this:
# dir count
# in this form dir will have /new at the end if the -n option is
# specified, we instead spit out:
# maildir
# which is just dirname $dir
use strict;
use warnings;
use File::Basename;
use File::Find;
use Getopt::Std;
our %newdirs = (); # dir => #files
our %opts;
our $MBLAZE = $ENV{'MBLAZE'} || join('/',$ENV{'HOME'},'.mblaze');
sub mhdr {
open(MHDR, "mhdr -h $_[0] $MBLAZE/profile |")
or die "mhdr: $!";
chomp(my $val = <MHDR>);
close(MHDR);
return $val;
}
our $maildir = mhdr("MaildirBase") || $ENV{'MAILDIR'} ||
join('/',$ENV{'HOME'},'mail');
$maildir = $ENV{"HOME"}."/Maildir" unless -d $maildir;
die "no maildir and no MAILDIR set!?\n" unless -d $maildir;
sub check {
$File::Find::name =~ /\/new\/\d+\.\d+_\d+.*$/ &&
$newdirs{$File::Find::dir}++;
}
sub mungdir {
my($dir) = @_;
if (!$opts{'n'}) {
$dir =~ s,^${maildir}/,,;
}
return dirname($dir);
}
getopts('n',\%opts);
our $fmt = $opts{'n'} ? "%s\n" : "%s %d\n";
find(\&check, $maildir);
foreach (sort keys %newdirs) {
my @out = (mungdir($_));
push(@out, $newdirs{$_}) unless $opts{'n'};
printf($fmt,@out);
}