#!/bin/bash # Tue Feb 17 17:36:38 EST 2004 # NAME: pop3stat # Copyright 2004, Chris F.A. Johnson # Released under the terms of the GNU General Public License # check POP3 server for e-mail ## set these variables to appropriate values pop=pop.your-isp.com user=$USER pass=password image=$HOME/mail.png ## or put them into the config file configfile=$HOME/.pop3statrc pop3stat() { exec 3<>/dev/tcp/$pop/110 popcmd user $user || return 1 popcmd pass $pass || return 2 popcmd stat || return 3 popcmd quit || return 4 } popcmd() { local IFS=${IFS}$'\r' cmd=$* echo $cmd >&3 read ok num x <&3 [ $verbose -ge 1 ] && printf "%s\n" "$1: $ok $num $x" [ "$ok" = "+OK" ] } popupicon() { set -- $(ps awwwxo user,pid,command | grep "$USER.*[m]ail-notify.*$image") [ -n "$2" ] && kill $2 [ $num -gt 0 ] && { display -geometry +1+1 -name mail-notify -comment "$num" $image & } } [ -s "$configfile" ] && . "$configfile" verbose=0 while getopts vc: var do case $var in c) configfile=$OPTARG ;; v) verbose=$(( $verbose + 1 )) ;; esac done shift $(( $OPTIND - 1 )) pop3stat || { echo "popcmd \"$cmd\" failed"; exit 5; } case ${1:-t} in g) popupicon ;; t) [ $num -eq 1 ] && _PL= || _PL=s echo "You have $num message$_PL" ;; esac