From 5632e0be34c7a07227543d3b44c3be7a1387613e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 3 Apr 2017 20:44:11 +0200 Subject: Update email-unread script --- local/bin/email-unread | 67 ++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 35 deletions(-) (limited to 'local/bin') 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); -- cgit v1.2.3