rvp
That's a neat alternative solution, and probably better than what my script is doing. But it's lacking a quit option.
I intentionally designed it so that my script would run again immediately after closing one inbox so I could check the next inbox, hence the need for an option to exit the loop.
Also, I was enjoying playing with the interactive nature of the script and avoiding the need to enter any command line options etc.
EDIT 1:
Thanks for the email. That interactive script works a charm, aside from still missing the loop/quit option.
I thought I may as well include the script @rvp sent me here for anyone curious, and so I can revisit this thread again in the future.
#!/bin/sh
set -eu
die() {
echo >&2 "$0: $*"
exit 1
}
get_addr() { # space-separated To-address list
local var
read -p "To addrs: " var
[ -n "$var" ] || die "To-address is empty!"
echo "$var"
}
get_attach() { # f1 file* => -a f1 -a filea -a fileb
local v var
read -p "Attachments: " var
set -- $(eval echo $var) # expand FNs--no spaces allowed
for v
do [ -f $v -a -s $v ] && echo "-a $v" ||
die "$v: invalid file"
done
}
get_cc() { # addr1 addr2 => -c addr1,addr2
local v var
read -p "CC addrs: " var
set -- $var
[ $# -eq 0 ] && return 0 # blank CC: is OK
var="$1"; shift
for v
do var="$var,$1"
shift
done
echo "-c $var"
}
P1="Account?
1) d.a.p@gmail
2) dve.pfr@gmail
3) pfr@sdf.org
> "
P2="Action?
1) Read
2) Compose
> "
clear; read -p "$P1" var
case $var in
1) acct="gmail"
;;
2) acct="dve.pfr"
;;
3) acct="sdfmail"
;;
*) die "$var: invalid choice"
;;
esac
read -p "$P2" var
case $var in
1) addr="" attach="" cc=""
;;
2) addr=$(get_addr)
attach=$(get_attach)
cc=$(get_cc)
;;
*) die "$var: invalid choice"
;;
esac
exec hmail -A "$acct" "$@" $attach $cc $addr
EDIT 2:
And for an interactive version that loop's until you hit q
to quit we have this:
#!/bin/sh
set -eu
die() {
echo >&2 "$0: $*"
exit 1
}
get_addr() { # space-separated To-address list
local var
read -p "To addrs: " var
[ -n "$var" ] || die "To-address is empty!"
echo "$var"
}
get_attach() { # f1 file* => -a f1 -a filea -a fileb
local v var
read -p "Attachments: " var
set -- $(eval echo $var) # expand FNs--no spaces allowed
for v
do [ -f $v -a -s $v ] && echo "-a $v" ||
die "$v: invalid file"
done
}
get_cc() { # addr1 addr2 => -c addr1,addr2
local v var
read -p "CC addrs: " var
set -- $var
[ $# -eq 0 ] && return 0 # blank CC: is OK
var="$1"; shift
for v
do var="$var,$1"
done
echo "-c $var"
}
P1="Account?
1) d.a.p@gmail
2) dve.pfr@gmail
3) pfr@sdf.org
> "
P2="Action?
1) Read
2) Compose
> "
while :
do
clear; read -p "$P1" var
case $var in
1) acct="gmail"
;;
2) acct="dve.pfr"
;;
3) acct="sdfmail"
;;
q) break # loop
;;
*) die "$var: invalid choice"
;;
esac
read -p "$P2" var
case $var in
1) addr="" attach="" cc=""
;;
2) addr=$(get_addr)
attach=$(get_attach)
cc=$(get_cc)
;;
q) break # loop
;;
*) die "$var: invalid choice"
;;
esac
hmail -A "$acct" "$@" $attach $cc $addr || true
done
Big thanks to @rvp for completely revamping my script into a working solution which does exactly what I wanted it to do.
Some questions may follow.... 😉