1. #!/bin/bash
# Sun Jan 18 16:48:55 EST 2004
# NAME: pop3ck
# Copyright 2004, Chris F.A. Johnson
# Released under the terms of the GNU General Public License
version() {
echo " $progname, version $version
Copyright $copyright, $author $email
This is free software, released under the terms of the GNU General
Public License. There is NO warranty; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
"
}
usage() {
echo " $progname -
USAGE: $progname [OPTIONS]
OPTIONS:
-c FILE - use FILE for server information
(will prompt for details if file does not exist)
-s - Print number of messages and exit
-h - help: print this message
-H - help: print more detailed message
-v - verbose:
-V - print version information
Copyright 2004, Chris F.A. Johnson
"
}
set_chars() { #== create string of all 255 chars
q='0 1 2 3 4 5 6 7 8 9 a b c d e f'
chars=`for a in $q
do
for b in $q
do
case $a$b in
00) ;;
7f) printf "x11" ;;
*) printf "x$a$b" ;;
esac
done
done`
}
get_key() { #== store keypress from list of permissible characters
local OKchars=${1:-"$allkeys"}
local k
local error=0
local gk_tmo=${getkey_time:-${DFLT_TIME_OUT:-600}}
local ESC_END=[a-zA-NP-Z~^$]
type read_mouse >/dev/null 2>&1 || read_mouse() { :; }
mouse_x=0 mouse_y=0 mouse_b=0 mouse_line=0
printf "$mouse_on"
stty -echo
while :; do
IFS= read -r -d '' -sn1 -t$gk_tmo _GET_KEY </dev/tty 2>&1 || break
index "$OKchars" "$_GET_KEY"
2. if [ "$_INDEX" -gt 0 ]
then
case $_GET_KEY in
${ESC})
while :; do
IFS= read -rst1 -d '' -n1 k </dev/tty || break 2
_GET_KEY=$_GET_KEY$k
case $k in
$ESC_END)
[ "$_GET_KEY" = "$MSI" ] && read_mouse
break 2
;;
esac
done
;;
*) break;;
esac
fi
done
printf "$mouse_off"
return $error
}
index() { #== index return position of STR2 in STR1
local idx
case $1 in
*$2*)
idx=${1%%"${2}"*};
_INDEX=$(( ${#idx} + 1 ))
;;
*)
_INDEX=0
;;
esac
}
cls() {
printf "${CLS:=`clear`}"
}
printat() { #== print arguments 3-... at Y=$1 X=$2
[ $# -lt 2 ] && return 1
local y=$1
local x=$2
shift 2
local msg="$*"
printf "${CSI}%d;%dH%b" ${y//[!0-9]} ${x//[!0-9]} "$msg"
}
getline() {
[ $1 = -s ] && { shift; local opt=-s; } || local opt=
local var=$1
shift
eval read $opt -ep " "$*": " $var
}
create_config() {
stty=`stty -g`
stty echo icanon
printf "${CVIS}nn"
while :
do
[ -n "$pop" ] || getline pop " Enter pop3 mail server"
[ -n "$user" ] || getline user " Enter user name"
3. [ -n "$pass" ] || getline pass " Enter password"
printf "nt1. Server: %sn" $pop
printf "t2. User: %sn" $user
printf "t3. Password: %sn" $pass
printf "t4. Config file: %snn" $config_file
read -sn1 -p " To make a change, enter the number, otherwise press
<ENTER>: " l
echo
case $l in
1) getline pop " Enter pop3 mail server" ;;
2) getline user " Enter user name" ;;
3) getline pass " Enter password" ;;
4) getline config_file " Enter config file" ;;
*) break ;;
esac
done
echo
{ echo "pop=$pop"
echo "user=$user"
echo "pass=$pass"
} > "${config_file:-$HOME/.pop3ckrc}"
stty $stty
printf "${CINV}n"
}
connect() { ## open connection to POP server and log in
exec 3<> /dev/tcp/$pop/${port:=110}
read -rt${timeout:-2} ok num x <&3 || return 5
_CONNECT=1
popcmd user $user
popcmd pass $pass || return 5
}
popcmd() {
cmd=$*
echo $cmd >&3
read -rt${timeout:-2} ok num x <&3 || return 5
[ "$ok" = "+OK" ]
}
set_pl() {
local num=${1:-0}
[ $num -eq 1 ] && pl= || pl=s
}
pop3stat() {
[ -f "$config_file" ] && . "$config_file" || return 5
connect
popcmd stat || return 3
set_pl $num
num_messages=$num
_POP3STAT="$num message$pl"
}
popread() {
local header=1
while IFS= read -r line
do
line=${line%$CR}
case $line in
"") header=0; printf "nn" ;;
.) break ;;
*)