#!/bin/bash

# wminfo plugin: displays the numbers of the messages in five mailboxes

# command: wminfo -p biff.wmi -u 5 -c -b#000000 -f#ff00ff

#
# CONFIGURATION SECTION BEGINS HERE
#

NAME1="spool"
MBOX1="/var/mail/$USER"

if [ ! -e $MBOX1 ]
then
    echo "biff.wmi: there's no $MBOX1 mailbox."
    exit
fi

#NAME2="gmail"
#MBOX2="$HOME/mbox-gmail"

#NAME3="yahoo"
#MBOX3="$HOME/mbox-yahoo"

NAME4=""
MBOX4=""

NAME5=""
MBOX5=""

#
# CONFIGURATION SECTION ENDS HERE
#

function test_mailbox {
if [ "$2" != "" ] && [ -e $2 ]
then
	ALL="0"
	NEW="0"
	OLD="0"
	tempfile="$HOME/.wminfo/.biff.$1.tmp"
	if [ ! -e $tempfile ]
	then
	    > $tempfile
	fi
	. $tempfile
	NEWSIZE=`ls -lL $2 | awk '{print $5}'`
	if [ "$OLDSIZE" == "" ] || [ $OLDSIZE -ne $NEWSIZE ]
	then
	    ALL=`egrep -c "^To: " $2`
	    OLD=`egrep -c "^Status: RO$" $2`
	    NEW="$(($ALL-$OLD))"
	    if [ $NEW -gt 0 ]
	    then
		echo "NEW=$NEW" > $tempfile
	    else
		echo "OLD=$OLD" > $tempfile
	    fi
	    echo "OLDSIZE=$NEWSIZE" >> $tempfile
	fi
	NAME="$1    "
	NAME="${NAME:0:5}"
	if [ $NEW -gt 0 ]
	then
	    NEW="  ${NEW}"
	    NEW=${NEW: -3:3}
	    echo "$NAME+$NEW"
	else
	    OLD="  ${OLD}"
	    OLD=${OLD: -3:3}
	    echo "$NAME-$OLD"
	fi
fi
}

test_mailbox $NAME1 $MBOX1
test_mailbox $NAME2 $MBOX2
test_mailbox $NAME3 $MBOX3
test_mailbox $NAME4 $MBOX4
test_mailbox $NAME5 $MBOX5
echo -e "         \n         \n         \n         \n         \n"

