SlideShare a Scribd company logo
#!/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 Simple
Ian Barber
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
brian d foy
 
PythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみたPythonでJWT生成からボット作成、投稿までやってみた
PythonでJWT生成からボット作成、投稿までやってみた
itoxdev
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
brian d foy
 
Mkscript sh
Mkscript shMkscript sh
Mkscript sh
Ben 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 Version
Ian Barber
 
TerminalでTwitter
TerminalでTwitterTerminalでTwitter
TerminalでTwitter
Yoshihiro Sugi
 
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
Vic Metcalfe
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
abrummett
 
ZeroMQ Is The Answer
ZeroMQ Is The AnswerZeroMQ Is The Answer
ZeroMQ Is The Answer
Ian Barber
 
Teaching Your Machine To Find Fraudsters
Teaching Your Machine To Find FraudstersTeaching Your Machine To Find Fraudsters
Teaching Your Machine To Find Fraudsters
Ian Barber
 
PHP for Python Developers
PHP for Python DevelopersPHP for Python Developers
PHP for Python Developers
Carlos 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 heure
Amaury Bouchard
 
DOS
DOSDOS
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
osfameron
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
Radek Benkel
 
Data Types Master
Data Types MasterData Types Master
Data Types Master
Paolo Marcatili
 
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
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
Andrew Shitov
 
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 zbksh
Ben Pope
 
Getfilestruct zbksh(1)
Getfilestruct zbksh(1)Getfilestruct zbksh(1)
Getfilestruct zbksh(1)
Ben Pope
 
Logrotate sh
Logrotate shLogrotate sh
Logrotate sh
Ben Pope
 
Firewall
FirewallFirewall
Firewall
Sher Rodriguez
 
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 commands
Ben Pope
 
Applecmdlista zs
Applecmdlista zsApplecmdlista zs
Applecmdlista zs
Ben Pope
 
Stefanie Lopez Angel - PPP Final
Stefanie Lopez Angel - PPP FinalStefanie Lopez Angel - PPP Final
Stefanie Lopez Angel - PPP Final
Stefanie Lopez-Angel
 
Xz file-format-1.0.4
Xz file-format-1.0.4Xz file-format-1.0.4
Xz file-format-1.0.4
Ben 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 commandss
Ben Pope
 
Compound var
Compound varCompound var
Compound var
Ben Pope
 
Cuadro sipnotico
Cuadro sipnoticoCuadro sipnotico
Cuadro sipnotico
thabata torrez perez
 
Pcad mision sucre
Pcad mision sucrePcad mision sucre
Pcad mision sucre
Lisanyis Alfonzo
 

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 Pop3ck sh

32 shell-programming
32 shell-programming32 shell-programming
32 shell-programmingkayalkarnan
 
5th Sem SS lab progs
5th Sem SS lab progs5th Sem SS lab progs
5th Sem SS lab progs
Nagarjun Pakka Kannadiga
 
Php functions
Php functionsPhp functions
Php functions
JIGAR MAKHIJA
 
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 Pop3ck sh (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-ref
Ben Pope
 
Popstat1 sh
Popstat1 shPopstat1 sh
Popstat1 sh
Ben Pope
 
Pop3stat sh
Pop3stat shPop3stat sh
Pop3stat sh
Ben Pope
 
Phadd sh
Phadd shPhadd sh
Phadd sh
Ben Pope
 
Phdel sh
Phdel shPhdel sh
Phdel sh
Ben Pope
 
Menu func-sh
Menu func-shMenu func-sh
Menu func-sh
Ben Pope
 
Menu func-sh(1)
Menu func-sh(1)Menu func-sh(1)
Menu func-sh(1)
Ben Pope
 
Luhn sh
Luhn shLuhn sh
Luhn sh
Ben Pope
 
Cpsh sh
Cpsh shCpsh sh
Cpsh sh
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

special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

Pop3ck sh

  • 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