jeff-j of osxroot
2/13/2015 - 12:07 AM

Counts the messages in INBOX, Sent, Deleted folders on an OS X Server. Results are tab-delimited, easy to paste to excel for sorting.

Counts the messages in INBOX, Sent, Deleted folders on an OS X Server. Results are tab-delimited, easy to paste to excel for sorting.

#!/bin/sh

# mailCount v2
# jeff johnson
# jeff@topicdesk.com


mdir=`serveradmin settings mail:imap:partition-default | cut -d '"' -f 2`

cd "$mdir"

printf "## Starting:   `date`\n## Mailstore $mdir\n\n"
printf "NAME\tINBOX\tSENT\tTRASH\tJUNK\n"


for i in `/bin/ls -1`; do
   shortname=`dscl /Search -search /Users GeneratedUID $i | head -1 |  awk '{print $1}'`
   if [ -n "$shortname" ]; then
       # Valid user
        cd "$mdir/$i"
        INBOX=`find {cur,new} -type f -name "*S=*" 2> /dev/null | wc -l`
        SENT=`find .Sent* -type f -name "*S=*" 2> /dev/null | wc -l`
        TRASH=`find .Delet* -type f -name "*S=*" 2> /dev/null | wc -l`
        JUNK=`find .Junk* -type f -name "*S=*" 2> /dev/null | wc -l`
        printf "$shortname\t$INBOX\t$SENT\t$TRASH\t$JUNK\n"
   fi
done