aboutsummaryrefslogtreecommitdiff
path: root/local/bin/email-unread
blob: a17c9b490eb4452164c4bd4f48ecda46e8cf1a2d (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
34
#!/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/;
		#print "ok: $path\n";
		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);