#!/bin/bash
# Dale Bewley <dale bewley.net> Wed Apr 27 14:21:47 PDT 2005
# quick script to count the number of messages found on a system in
# ~/mbox, ~/mail, and /var/mail

SPOOL=/var/mail
HOMEROOT=/export/home/raid

echo user,spool,mbox,folders

for spool in $SPOOL/*; do
	user=`basename $spool`

        # count messages in spool
        if [ -f "$SPOOL/$user" ]; then
                spool_cnt=`grep -c '^From ' $SPOOL/$user`
        fi

        # count messages in mbox (pine)
        if [ -f "$HOMEROOT/$user/mbox" ]; then
                mbox_cnt=`grep -c '^From ' $HOMEROOT/$user/mbox`
        fi

        # count messages in folders
	# i want to know how many folders and how big they are, but not the names
	# there are 2 users who have SO MANY folders that this output will split the lines!
        if [ -d "$HOMEROOT/$user/mail" ]; then
                folder_cnt=`find $HOMEROOT/$user/mail/ -type f -exec grep -c '^From ' {} \;`
        fi

        echo $user,$spool_cnt,$mbox_cnt,$folder_cnt
done

