aboutsummaryrefslogtreecommitdiff
path: root/local/bin/email-unread
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2017-04-03 20:44:11 +0200
committerKarel Kočí <cynerd@email.cz>2017-04-03 20:44:11 +0200
commit5632e0be34c7a07227543d3b44c3be7a1387613e (patch)
tree19f647dedb6f565c0d4cd3c738f174e4e2796ef1 /local/bin/email-unread
parent81836945a63f726033fb6550755e2c9dbf1a1f83 (diff)
downloadmyconfigs-5632e0be34c7a07227543d3b44c3be7a1387613e.tar.gz
myconfigs-5632e0be34c7a07227543d3b44c3be7a1387613e.tar.bz2
myconfigs-5632e0be34c7a07227543d3b44c3be7a1387613e.zip
Update email-unread script
Diffstat (limited to 'local/bin/email-unread')
-rwxr-xr-xlocal/bin/email-unread67
1 files changed, 32 insertions, 35 deletions
diff --git a/local/bin/email-unread b/local/bin/email-unread
index f9e3aa9..3956f3b 100755
--- a/local/bin/email-unread
+++ b/local/bin/email-unread
@@ -1,37 +1,34 @@
-#!/bin/bash
-EMAIL=~/.mail
-IGNORE="(Spam|trash|Important)"
+#!/bin/perl
+use strict;
+use warnings;
+use File::Find;
-if [ "$1" == "-s" ]; then
- V=n
-else
- V=y
-fi
+use constant EMAIL => glob("~/.mail");
+my $IGNORE = "(Spam|trash|Important)";
-for account in $(ls "$EMAIL"); do
- if ! cd $EMAIL/$account; then continue; fi
- COUNT="0"
- COUNT=$(find . -name new -type d -print0 |
- while read -d $'\0' folder; do
- if [ -n "`echo $folder | grep -E $IGNORE`" ]; then
- continue
- fi
- directory=$(echo $folder | sed 's/^\.\///' | sed 's/\/new$//')
- count=$(ls "$folder" | wc -l)
- if [ "$count" -gt "0" ]; then
- if [ $V == 'y' ]; then
- echo "$account/$directory: $count"
- else
- let 'COUNT = COUNT + count'
- echo $COUNT
- fi
- fi
- done | tail -1)
- if [ -n "$COUNT" ]; then
- if [ $V == "n" ]; then
- echo "$account:$COUNT"
- else
- echo $COUNT
- fi
- fi
-done
+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);