#!/bin/bash
EMAIL=~/.mail
IGNORE="(Spam|trash|Important)"

if [ "$1" == "-s" ]; then
	V=n
else
	V=y
fi

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