SlideShare a Scribd company logo
1 of 10
#!/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"
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"
[ -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 ;;
*)
if [ $header -eq 1 ]
then
case $line in
$wsp*) printf "%s " "$line" ;;
*) printf "%sn" "$line" ;;
esac
fi
esac
echo "$line"
done
}
hnum() {
case ${#1} in
1|2|3|4) _HNUM=$1 ;;
5|6) _HNUM=$(( ($1 + 500) / 1000 ))K ;;
7|8|9) _HNUM=$(( ($1 + 500000) / 1000000 ))M ;;
10|11|12) _HNUM=$(( ($1 + 500000000) / 1000000000 ))G ;;
*) _HNUM="HUGE" ;;
esac
}
popheader()
{
local ph_num=$1
local sw=$(( $COLUMNS - 44 - ${#num_messages} ))
f1= #$scroll_down${HB_RESET}${colour}${cle}
f2="${f1}%2.1s %${#num_messages}d %6.6s %-25.25s %6.6s %-${sw}.${sw}s$
{HB_RESET}r"
notify reading header $ph_num
popcmd top $ph_num ${msg_lines:-10} || return 1
size[$ph_num]=$num
_POPREAD=`popread x <&3`
header=1
local IFS=$NL
_POPHEADER=( ${_POPREAD%%$NL$NL} )
msg_top[$ph_num]=${_POPREAD#*$NL$NL}
msg_read[$ph_num]=1
local num=0
while [ $num -lt ${#_POPHEADER[@]} ]
do
line=${_POPHEADER[$num]}
case $line in
"") header=0; break ;;
[  ]*) ;;
[Ss][Uu][Bb][Jj][Ee][Cc][Tt]:* )
msg_subject[$ph_num]=${line#*: } ;;
[Ff][Rr][Oo][Mm]:*)
msg_from[$ph_num]=${line#*: }
msg_xfrom[$ph_num]=${msg_from[$ph_num]%%<*};;
[Tt][Oo]:*)
msg_to[$ph_num]=${line#*: } ;;
[Cc][Cc]:*)
msg_cc[$ph_num]=${line#*: } ;;
[Dd][Aa][Tt][Ee]:*)
msg_date[$ph_num]=${line#*: } ;;
[Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]:*)
msg_id[$ph_num]=${line#*: } ;;
[Rr][Ee][Pp][Ll][Yy]-[Tt][Oo]:*)
msg_reply_to[$ph_num]=${line#*: } ;;
[Ss][Ee][Nn][Dd][Ee][Rr]:*)
msg_sender[$ph_num]=${line#*: } ;;
*:*) last_type=${line#*: } ;;
esac
num=$(( $num + 1 ))
done
hnum "${size[$ph_num]}"
msg_hnum[$ph_num]=$_HNUM
msg_status[$ph_num]=' '
summaries[$ph_num]=`printf "$f2" "${msg_status[$ph_num]}" 
"$ph_num" 
"${msg_date[$ph_num]:5:6}" 
"${msg_xfrom[$ph_num]//"/}" 
"($_HNUM)" "${msg_subject[$ph_num]}"`
printf "n%sn" "${summaries[$ph_num]}"
}
notify() {
local msg=" $* "
printat 1 $(( $COLUMNS - ${#msg} - 1 )) "$msg"
}
show_cmd() {
local n=-1
local num=${#cmds[@]}
local cmd=${cmds[*]}
local cmd_line=$(( $LINES - 1 ))
justify=$(( ($COLUMNS - ${#cmd}) / (${num} + 1) ))
commands=
printat $cmd_line 1 "${BR}"
printf "%${COLUMNS}s" ' '
printat $cmd_line 1
while [ $(( n += 1 )) -lt $num ]
do
initial="${cmds[n]:0:1}"
the_rest="${cmds[n]:1}"
commands=$commands$initial
printf " %${justify:-0}.${justify}s${NA}${B}%s${R}%s${BR}" ' ' $initial "$
{the_rest}"
done
printf "${NA}"
}
show_msg() {
local num=${1:-1}
local w=$(( $COLUMNS - 10 ))
cls
echo "$CINV"
printat 1 1; printf "$BR%${COLUMNS}.${COLUMNS}s" " "
printat 1 1; echo "$BR Message $num of $num_messages$NA"
printat 2 1; printf "$date_lattr Date: $date_attr %-${w}.${w}s${NA}" "$
{msg_date[num]}"
printat 3 1; printf "$from_lattr From: $from_attr %-${w}.${w}s${NA}" "$
{msg_from[num]}"
printat 4 1; printf "$to_lattr To: $to_attr %-${w}.${w}s${NA}" "$
{msg_to[num]}"
printat 5 1; printf "$subj_lattr Subject: $subj_attr %-${w}.${w}s${NA}" "$
{msg_subject[num]}"
printat 7 1
local IFS=$NL
# printf "%sn" "${msg_top[$num]}" | cut -c1-$(( $COLUMNS - 1 )) | head -$
(( $LINES - 10 ))
printf "%sn" "${msg_top[$num]}" | fold -w $(( $COLUMNS - 1 )) | head -$
(( $LINES - 10 ))
}
show_summaries() {
local msg_num=-1
cls
while [ $(( msg_num += 1 )) -lt $num_messages ]
do
[ ${msg_read[$msg_num]:=0} -ne 1 ] && popheader $msg_num
done
cls
printat 3 1
printf "%sn" "${summaries[@]}" |
if [ $num_messages -gt $(( $LINES - 10 )) ]
then
less
else
cat
fi
echo
read -sn1 -p " ${B}Press any key to continue${NA} "
}
set_attr() {
case $1 in
-var) var=$2; shift 2 ;;
-var=*) var=${1#-var=}; shift ;;
-var*) var=${1#-var}; shift ;;
*) var= ;;
esac
_SET_ATTR=
for attr
do
case $attr in
*,*) eval "_SET_ATTR=$_SET_ATTR${fg_${attr%,*}}${bg_${attr#*,}}" ;;
*) eval "_SET_ATTR=$_SET_ATTR${fg_${attr}}" ;;
esac
done
[ -n "$var" ] && eval "$var="$_SET_ATTR""
}
cleanup() {
msg_num=-1
while [ $(( msg_num += 1 )) -lt $num_messages ]
do
[ "${msg_status[$msg_num]}" = D ] && {
popcmd dele $msg_num
printf "r${cle}%sn" "$ok $num $x"
} # || printf "r${cle}%sr" " $num"
done
[ ${_CONNECT:-0} -eq 1 ] && popcmd quit
stty $stty
stty sane echo
printf "$NAr$cles$CVIS"
}
wsp="[ ]"
bra='['
ket=']'
ESC=$'e'
NL=$'n'
CR=$'r'
TAB=$'t'
CSI=${ESC}${bra}
cle=${CSI}K
cles=${CSI}J
clbs=${CSI}1J
CVIS="${CSI}?25h"
CINV="${CSI}0;8m"
MSI=${CSI}M
NA=${CSI}0m
B=${CSI}1m
R=${CSI}7m
BR=$B$R
U=${CSI}4m
UP=${CSI}A
DN=${CSI}B
RT=${CSI}C
LF=${CSI}D
mouse_type[0]=${CSI}?9h ## report mouse button press
mouse_type[1]=${CSI}?1000h ## report mouse button press and release
mouse_on=${mouse_type[0]}
mouse_off=${CSI}?9l${CSI}?1000l
upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ
lower=abcdefghijklmnopqrstuvwxyz
numeric=0123456789
alphanumeric=$upper$lower$numeric
CVIS=${CSI}?25h
CINV=${CSI}?25l
allkeys=$chars
verbose=0
longusage=0
version="1.0"
copyright=2004
author="Chris F.A. Johnson"
progname=${0##*/}
config_file=$HOME/.pop3ckrc
while getopts vVhH-:c:s var
do
case $var in
c) config_file=$OPTARG ;;
s) pop3stat || return 5
printf "r$_POP3STAT for $user on $pop $clen"
popcmd quit || exit 4
exit ;;
-) case $OPTARG in
help) usage; exit ;;
help_long) longusage=1; usage; exit ;;
version) version; exit ;;
esac
;;
h) usage; exit ;;
H) longusage=1; usage; exit ;;
v) verbose=$(( $verbose + 1 )) ;;
V) version; exit ;;
*);;
esac
done
shift $(( $OPTIND - 1 ))
cls
stty=`stty -g`
stty -icanon -echo
delete_will_advance=1
[ -f "$config_file" ] || { create_config || exit 5; }
. "$config_file"
setsize() {
set `stty size || { tput lines; tput cols; }`
LINES=${1:-24}
COLUMNS=${2:-80}
[ -n "$1" ] || show_msg $msg_num
}
trap setsize SIGWINCH
trap cleanup EXIT
echo "Making connection to $pop as $user"
pop3stat || { echo "$OK $num $x (conection failed)" ; exit 5; }
echo "$_POP3STAT"
[ ${num:-0} -gt 0 ] || { popcmd quit; exit; }
cmds=( forward next back previous goto summary delete undelete quit )
msg_lines=$(( ${LINES} - 6 ))
msg_num=1
while :
do
setsize
[ ${msg_read[$msg_num]:=0} -ne 1 ] && popheader $msg_num
[ ${last_msg:-0} -ne $msg_num ] && show_msg $msg_num
show_cmd
last_msg=$msg_num
get_key "$commands$ESC"
case $_GET_KEY in
n|f|$UP|$RT) msg_num=$(( $msg_num + 1 )) ;;
b|p|$DN|$LF) msg_num=$(( $msg_num - 1 )) ;;
d)
msg_top[$msg_num]=" ${BR} DELETED ${NA}"
msg_status[$msg_num]=D
summaries[$msg_num]=`printf "$f2" "${msg_status[$msg_num]}" $msg_num "$
{msg_date[$msg_num]}" "${msg_from[$msg_num]//"/}" "(${msg_hnum[$msg_num]})" "$
{msg_subject[$msg_num]}"`
show_msg $msg_num
sleep .2
msg_num=$(( $msg_num + ${delete_will_advance:=0} ))
;;
g) stty echo
printat $(( $LINES - 1 )) 1 "$cle"
read -ep "$BR Enter number of message:$NA " num
stty -echo
case $num in
*[!0-9]*) printf "aInvalid entry"
sleep 2
;;
*) msg_num=$num ;;
esac
;;
q) break ;;
u) msg_status[$msg_num]=U
popheader $msg_num
show_msg $msg_num
;;
s) show_summaries
show_msg $msg_num
;;
esac
if [ $msg_num -lt 1 ]
then
msg_num=1
elif [ $msg_num -ge $num_messages ]
then
msg_num=$num_messages
fi
done
cleanup
fi
done
cleanup

More Related Content

What's hot

ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleIan Barber
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
 
PythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみたPythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみたitoxdev
 
Mkscript sh
Mkscript shMkscript sh
Mkscript shBen Pope
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionIan Barber
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackVic Metcalfe
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type Systemabrummett
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The AnswerIan Barber
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersIan Barber
 
PHP for Python Developers
PHP for Python DevelopersPHP for Python Developers
PHP for Python DevelopersCarlos Vences
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureAmaury Bouchard
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2osfameron
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)Dennis Knochenwefel
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6 brian d foy
 

What's hot (20)

ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
PythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみたPythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみた
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
 
Debugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 VersionDebugging: Rules And Tools - PHPTek 11 Version
Debugging: Rules And Tools - PHPTek 11 Version
 
TerminalでTwitter
TerminalでTwitterTerminalでTwitter
TerminalでTwitter
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
 
PHP for Python Developers
PHP for Python DevelopersPHP for Python Developers
PHP for Python Developers
 
Créer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heureCréer une base NoSQL en 1 heure
Créer une base NoSQL en 1 heure
 
DOS
DOSDOS
DOS
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
Data Types Master
Data Types MasterData Types Master
Data Types Master
 
London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)London XQuery Meetup: Querying the World (Web Scraping)
London XQuery Meetup: Querying the World (Web Scraping)
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 

Viewers also liked

Getfilestruct zbksh
Getfilestruct zbkshGetfilestruct zbksh
Getfilestruct zbkshBen Pope
 
Getfilestruct zbksh(1)
Getfilestruct zbksh(1)Getfilestruct zbksh(1)
Getfilestruct zbksh(1)Ben Pope
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate shBen Pope
 
Analysis of the Performance of Sea Level Stations at Haiti
Analysis of the Performance of Sea Level Stations at HaitiAnalysis of the Performance of Sea Level Stations at Haiti
Analysis of the Performance of Sea Level Stations at HaitiKaruska Matos-Horta
 
An a z index of the bash commands
An a z index of the bash commandsAn a z index of the bash commands
An a z index of the bash commandsBen Pope
 
Applecmdlista zs
Applecmdlista zsApplecmdlista zs
Applecmdlista zsBen Pope
 
Xz file-format-1.0.4
Xz file-format-1.0.4Xz file-format-1.0.4
Xz file-format-1.0.4Ben Pope
 
An a z index of windows power shell commandss
An a z index of windows power shell commandssAn a z index of windows power shell commandss
An a z index of windows power shell commandssBen Pope
 
Compound var
Compound varCompound var
Compound varBen Pope
 

Viewers also liked (15)

Getfilestruct zbksh
Getfilestruct zbkshGetfilestruct zbksh
Getfilestruct zbksh
 
Getfilestruct zbksh(1)
Getfilestruct zbksh(1)Getfilestruct zbksh(1)
Getfilestruct zbksh(1)
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
 
Firewall
FirewallFirewall
Firewall
 
Analysis of the Performance of Sea Level Stations at Haiti
Analysis of the Performance of Sea Level Stations at HaitiAnalysis of the Performance of Sea Level Stations at Haiti
Analysis of the Performance of Sea Level Stations at Haiti
 
Slowinski_Portfolio
Slowinski_PortfolioSlowinski_Portfolio
Slowinski_Portfolio
 
Diplom
DiplomDiplom
Diplom
 
An a z index of the bash commands
An a z index of the bash commandsAn a z index of the bash commands
An a z index of the bash commands
 
Applecmdlista zs
Applecmdlista zsApplecmdlista zs
Applecmdlista zs
 
Stefanie Lopez Angel - PPP Final
Stefanie Lopez Angel - PPP FinalStefanie Lopez Angel - PPP Final
Stefanie Lopez Angel - PPP Final
 
Xz file-format-1.0.4
Xz file-format-1.0.4Xz file-format-1.0.4
Xz file-format-1.0.4
 
An a z index of windows power shell commandss
An a z index of windows power shell commandssAn a z index of windows power shell commandss
An a z index of windows power shell commandss
 
Compound var
Compound varCompound var
Compound var
 
Cuadro sipnotico
Cuadro sipnoticoCuadro sipnotico
Cuadro sipnotico
 
Pcad mision sucre
Pcad mision sucrePcad mision sucre
Pcad mision sucre
 

Similar to Pop3 email client bash script

32 shell-programming
32 shell-programming32 shell-programming
32 shell-programmingkayalkarnan
 
Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)James Titcumb
 
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)James Titcumb
 
Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)James Titcumb
 
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)James Titcumb
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)James Titcumb
 
Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)James Titcumb
 
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)James Titcumb
 
Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)James Titcumb
 
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)James Titcumb
 
Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)James Titcumb
 
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)James Titcumb
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)James Titcumb
 
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)James Titcumb
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
Interpret this... (PHPem 2016)
Interpret this... (PHPem 2016)Interpret this... (PHPem 2016)
Interpret this... (PHPem 2016)James Titcumb
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Michael Schwern
 

Similar to Pop3 email client bash script (20)

32 shell-programming
32 shell-programming32 shell-programming
32 shell-programming
 
5th Sem SS lab progs
5th Sem SS lab progs5th Sem SS lab progs
5th Sem SS lab progs
 
Php functions
Php functionsPhp functions
Php functions
 
Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)Climbing the Abstract Syntax Tree (IPC Fall 2017)
Climbing the Abstract Syntax Tree (IPC Fall 2017)
 
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
Climbing the Abstract Syntax Tree (CodeiD PHP Odessa 2017)
 
Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)Climbing the Abstract Syntax Tree (DPC 2017)
Climbing the Abstract Syntax Tree (DPC 2017)
 
Unix prog
Unix progUnix prog
Unix prog
 
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)Climbing the Abstract Syntax Tree (PHP South Africa 2017)
Climbing the Abstract Syntax Tree (PHP South Africa 2017)
 
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)Climbing the Abstract Syntax Tree (Midwest PHP 2020)
Climbing the Abstract Syntax Tree (Midwest PHP 2020)
 
Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)Climbing the Abstract Syntax Tree (Forum PHP 2017)
Climbing the Abstract Syntax Tree (Forum PHP 2017)
 
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
Climbing the Abstract Syntax Tree (PHP Developer Days Dresden 2018)
 
Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)Climbing the Abstract Syntax Tree (PHP Russia 2019)
Climbing the Abstract Syntax Tree (PHP Russia 2019)
 
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
Climbing the Abstract Syntax Tree (ScotlandPHP 2018)
 
Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)Climbing the Abstract Syntax Tree (php[world] 2019)
Climbing the Abstract Syntax Tree (php[world] 2019)
 
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
Climbing the Abstract Syntax Tree (Bulgaria PHP 2016)
 
Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)Climbing the Abstract Syntax Tree (PHP UK 2018)
Climbing the Abstract Syntax Tree (PHP UK 2018)
 
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)Climbing the Abstract Syntax Tree (Southeast PHP 2018)
Climbing the Abstract Syntax Tree (Southeast PHP 2018)
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
Interpret this... (PHPem 2016)
Interpret this... (PHPem 2016)Interpret this... (PHPem 2016)
Interpret this... (PHPem 2016)
 
Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)Simple Ways To Be A Better Programmer (OSCON 2007)
Simple Ways To Be A Better Programmer (OSCON 2007)
 

More from Ben Pope

Programming collaborative-ref
Programming collaborative-refProgramming collaborative-ref
Programming collaborative-refBen Pope
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 shBen Pope
 
Pop3stat sh
Pop3stat shPop3stat sh
Pop3stat shBen Pope
 
Menu func-sh
Menu func-shMenu func-sh
Menu func-shBen Pope
 
Menu func-sh(1)
Menu func-sh(1)Menu func-sh(1)
Menu func-sh(1)Ben Pope
 

More from Ben Pope (9)

Programming collaborative-ref
Programming collaborative-refProgramming collaborative-ref
Programming collaborative-ref
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 sh
 
Pop3stat sh
Pop3stat shPop3stat sh
Pop3stat sh
 
Phadd sh
Phadd shPhadd sh
Phadd sh
 
Phdel sh
Phdel shPhdel sh
Phdel sh
 
Menu func-sh
Menu func-shMenu func-sh
Menu func-sh
 
Menu func-sh(1)
Menu func-sh(1)Menu func-sh(1)
Menu func-sh(1)
 
Luhn sh
Luhn shLuhn sh
Luhn sh
 
Cpsh sh
Cpsh shCpsh sh
Cpsh sh
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 

Pop3 email client bash script

  • 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 ;; *)
  • 4. if [ $header -eq 1 ] then case $line in $wsp*) printf "%s " "$line" ;; *) printf "%sn" "$line" ;; esac fi esac echo "$line" done } hnum() { case ${#1} in 1|2|3|4) _HNUM=$1 ;; 5|6) _HNUM=$(( ($1 + 500) / 1000 ))K ;; 7|8|9) _HNUM=$(( ($1 + 500000) / 1000000 ))M ;; 10|11|12) _HNUM=$(( ($1 + 500000000) / 1000000000 ))G ;; *) _HNUM="HUGE" ;; esac } popheader() { local ph_num=$1 local sw=$(( $COLUMNS - 44 - ${#num_messages} )) f1= #$scroll_down${HB_RESET}${colour}${cle} f2="${f1}%2.1s %${#num_messages}d %6.6s %-25.25s %6.6s %-${sw}.${sw}s$ {HB_RESET}r" notify reading header $ph_num popcmd top $ph_num ${msg_lines:-10} || return 1 size[$ph_num]=$num _POPREAD=`popread x <&3` header=1 local IFS=$NL _POPHEADER=( ${_POPREAD%%$NL$NL} ) msg_top[$ph_num]=${_POPREAD#*$NL$NL} msg_read[$ph_num]=1 local num=0 while [ $num -lt ${#_POPHEADER[@]} ] do line=${_POPHEADER[$num]} case $line in "") header=0; break ;; [ ]*) ;; [Ss][Uu][Bb][Jj][Ee][Cc][Tt]:* ) msg_subject[$ph_num]=${line#*: } ;; [Ff][Rr][Oo][Mm]:*) msg_from[$ph_num]=${line#*: } msg_xfrom[$ph_num]=${msg_from[$ph_num]%%<*};; [Tt][Oo]:*) msg_to[$ph_num]=${line#*: } ;; [Cc][Cc]:*) msg_cc[$ph_num]=${line#*: } ;; [Dd][Aa][Tt][Ee]:*) msg_date[$ph_num]=${line#*: } ;; [Mm][Ee][Ss][Ss][Aa][Gg][Ee]-[Ii][Dd]:*) msg_id[$ph_num]=${line#*: } ;; [Rr][Ee][Pp][Ll][Yy]-[Tt][Oo]:*) msg_reply_to[$ph_num]=${line#*: } ;; [Ss][Ee][Nn][Dd][Ee][Rr]:*) msg_sender[$ph_num]=${line#*: } ;; *:*) last_type=${line#*: } ;; esac
  • 5. num=$(( $num + 1 )) done hnum "${size[$ph_num]}" msg_hnum[$ph_num]=$_HNUM msg_status[$ph_num]=' ' summaries[$ph_num]=`printf "$f2" "${msg_status[$ph_num]}" "$ph_num" "${msg_date[$ph_num]:5:6}" "${msg_xfrom[$ph_num]//"/}" "($_HNUM)" "${msg_subject[$ph_num]}"` printf "n%sn" "${summaries[$ph_num]}" } notify() { local msg=" $* " printat 1 $(( $COLUMNS - ${#msg} - 1 )) "$msg" } show_cmd() { local n=-1 local num=${#cmds[@]} local cmd=${cmds[*]} local cmd_line=$(( $LINES - 1 )) justify=$(( ($COLUMNS - ${#cmd}) / (${num} + 1) )) commands= printat $cmd_line 1 "${BR}" printf "%${COLUMNS}s" ' ' printat $cmd_line 1 while [ $(( n += 1 )) -lt $num ] do initial="${cmds[n]:0:1}" the_rest="${cmds[n]:1}" commands=$commands$initial printf " %${justify:-0}.${justify}s${NA}${B}%s${R}%s${BR}" ' ' $initial "$ {the_rest}" done printf "${NA}" } show_msg() { local num=${1:-1} local w=$(( $COLUMNS - 10 )) cls echo "$CINV" printat 1 1; printf "$BR%${COLUMNS}.${COLUMNS}s" " " printat 1 1; echo "$BR Message $num of $num_messages$NA" printat 2 1; printf "$date_lattr Date: $date_attr %-${w}.${w}s${NA}" "$ {msg_date[num]}" printat 3 1; printf "$from_lattr From: $from_attr %-${w}.${w}s${NA}" "$ {msg_from[num]}" printat 4 1; printf "$to_lattr To: $to_attr %-${w}.${w}s${NA}" "$ {msg_to[num]}" printat 5 1; printf "$subj_lattr Subject: $subj_attr %-${w}.${w}s${NA}" "$ {msg_subject[num]}" printat 7 1 local IFS=$NL # printf "%sn" "${msg_top[$num]}" | cut -c1-$(( $COLUMNS - 1 )) | head -$ (( $LINES - 10 )) printf "%sn" "${msg_top[$num]}" | fold -w $(( $COLUMNS - 1 )) | head -$ (( $LINES - 10 )) } show_summaries() { local msg_num=-1
  • 6. cls while [ $(( msg_num += 1 )) -lt $num_messages ] do [ ${msg_read[$msg_num]:=0} -ne 1 ] && popheader $msg_num done cls printat 3 1 printf "%sn" "${summaries[@]}" | if [ $num_messages -gt $(( $LINES - 10 )) ] then less else cat fi echo read -sn1 -p " ${B}Press any key to continue${NA} " } set_attr() { case $1 in -var) var=$2; shift 2 ;; -var=*) var=${1#-var=}; shift ;; -var*) var=${1#-var}; shift ;; *) var= ;; esac _SET_ATTR= for attr do case $attr in *,*) eval "_SET_ATTR=$_SET_ATTR${fg_${attr%,*}}${bg_${attr#*,}}" ;; *) eval "_SET_ATTR=$_SET_ATTR${fg_${attr}}" ;; esac done [ -n "$var" ] && eval "$var="$_SET_ATTR"" } cleanup() { msg_num=-1 while [ $(( msg_num += 1 )) -lt $num_messages ] do [ "${msg_status[$msg_num]}" = D ] && { popcmd dele $msg_num printf "r${cle}%sn" "$ok $num $x" } # || printf "r${cle}%sr" " $num" done [ ${_CONNECT:-0} -eq 1 ] && popcmd quit stty $stty stty sane echo printf "$NAr$cles$CVIS" } wsp="[ ]" bra='[' ket=']' ESC=$'e' NL=$'n' CR=$'r' TAB=$'t' CSI=${ESC}${bra} cle=${CSI}K cles=${CSI}J clbs=${CSI}1J CVIS="${CSI}?25h" CINV="${CSI}0;8m"
  • 7. MSI=${CSI}M NA=${CSI}0m B=${CSI}1m R=${CSI}7m BR=$B$R U=${CSI}4m UP=${CSI}A DN=${CSI}B RT=${CSI}C LF=${CSI}D mouse_type[0]=${CSI}?9h ## report mouse button press mouse_type[1]=${CSI}?1000h ## report mouse button press and release mouse_on=${mouse_type[0]} mouse_off=${CSI}?9l${CSI}?1000l upper=ABCDEFGHIJKLMNOPQRSTUVWXYZ lower=abcdefghijklmnopqrstuvwxyz numeric=0123456789 alphanumeric=$upper$lower$numeric CVIS=${CSI}?25h CINV=${CSI}?25l allkeys=$chars verbose=0 longusage=0 version="1.0" copyright=2004 author="Chris F.A. Johnson" progname=${0##*/} config_file=$HOME/.pop3ckrc while getopts vVhH-:c:s var do case $var in c) config_file=$OPTARG ;; s) pop3stat || return 5 printf "r$_POP3STAT for $user on $pop $clen" popcmd quit || exit 4 exit ;; -) case $OPTARG in help) usage; exit ;; help_long) longusage=1; usage; exit ;; version) version; exit ;; esac ;; h) usage; exit ;; H) longusage=1; usage; exit ;; v) verbose=$(( $verbose + 1 )) ;; V) version; exit ;; *);; esac done shift $(( $OPTIND - 1 )) cls stty=`stty -g` stty -icanon -echo delete_will_advance=1 [ -f "$config_file" ] || { create_config || exit 5; } . "$config_file" setsize() { set `stty size || { tput lines; tput cols; }`
  • 8. LINES=${1:-24} COLUMNS=${2:-80} [ -n "$1" ] || show_msg $msg_num } trap setsize SIGWINCH trap cleanup EXIT echo "Making connection to $pop as $user" pop3stat || { echo "$OK $num $x (conection failed)" ; exit 5; } echo "$_POP3STAT" [ ${num:-0} -gt 0 ] || { popcmd quit; exit; } cmds=( forward next back previous goto summary delete undelete quit ) msg_lines=$(( ${LINES} - 6 )) msg_num=1 while : do setsize [ ${msg_read[$msg_num]:=0} -ne 1 ] && popheader $msg_num [ ${last_msg:-0} -ne $msg_num ] && show_msg $msg_num show_cmd last_msg=$msg_num get_key "$commands$ESC" case $_GET_KEY in n|f|$UP|$RT) msg_num=$(( $msg_num + 1 )) ;; b|p|$DN|$LF) msg_num=$(( $msg_num - 1 )) ;; d) msg_top[$msg_num]=" ${BR} DELETED ${NA}" msg_status[$msg_num]=D summaries[$msg_num]=`printf "$f2" "${msg_status[$msg_num]}" $msg_num "$ {msg_date[$msg_num]}" "${msg_from[$msg_num]//"/}" "(${msg_hnum[$msg_num]})" "$ {msg_subject[$msg_num]}"` show_msg $msg_num sleep .2 msg_num=$(( $msg_num + ${delete_will_advance:=0} )) ;; g) stty echo printat $(( $LINES - 1 )) 1 "$cle" read -ep "$BR Enter number of message:$NA " num stty -echo case $num in *[!0-9]*) printf "aInvalid entry" sleep 2 ;; *) msg_num=$num ;; esac ;; q) break ;; u) msg_status[$msg_num]=U popheader $msg_num show_msg $msg_num ;; s) show_summaries show_msg $msg_num ;; esac if [ $msg_num -lt 1 ] then msg_num=1 elif [ $msg_num -ge $num_messages ] then msg_num=$num_messages