aboutsummaryrefslogtreecommitdiff
path: root/local/bin/email-unread
blob: dec7d04f3864b1998147697d3d16a57cd301e11a (plain)
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
#!/usr/bin/env perl
use strict;
use warnings;
use File::Find;

use constant EMAIL => glob("~/.mail");
my $IGNORE = "(Spam|trash|Important)";

my $V = (shift || "") eq "-s";

opendir(EDIR, EMAIL) or die $!;
while (readdir EDIR) {
	next if /^\./ or not (-d EMAIL."/$_");
	our $count = 0;

	sub new_dir {
		my $path = substr $File::Find::name, 1 + length EMAIL;
		$path =~ s/\/new$//;
		return if $_ ne "new" or $path =~ /$IGNORE/;
		my $cnt = 0;
		opendir(NDIR, "$File::Find::name") or die $!;
		while (readdir NDIR) {
			$cnt += 1 unless /^\./;
		}
		closedir(NDIR);
		print "$path: $cnt\n" if not $V and $cnt > 0;
		$count += $cnt;
	}
	find(\&new_dir, EMAIL."/$_");

	print "$_: $count\n" if $V and $count > 0;
}
closedir(EDIR);