taro/mread

74 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
mhandle() {
case $2 in
text/html)
cp $1 ${1}.html
netsurf ${1}.html
rm ${1}.html;;
image/*)
qiv $1;;
audio/*|video/*)
mpv $1;;
pgp/encrypted)
gpg --decrypt $1;;
application/vnd*)
libreoffice $1;;
application/pdf)
zathura $1;;
esac
}
_mread() {
local META
mflag -S ${this}
local this=$(mseq $@)
while true; do
mshow ${this}
while true; do
META=""
printf "\n"
mshow -t
printf "\n"
printf "[1..n] view attachment (add s to save)\n"
printf "[r]reply, [f]orward, [q]uit\n"
read cmd
case ${cmd} in
1|2|3|4|5|6|7|8|9|10|\
11|12|13|14|15|16|17|18|19|20)
attachment=$(mktemp)
mshow -O . ${cmd} > ${attachment}
mimetype=$(mshow -t | grep ${cmd}: | awk '{print $2}')
mhandle ${attachment} ${mimetype}
rm ${attachment};;
1s|2s|3s|4s|5s|6s|7s|8s|9s|10s|\
11s|12s|13s|14s|15s|16s|17s|18s|19s|20s)
mshow -x . ${cmd%s};;
q|quit)
META=q;;
r|reply)
META=r;;
f|forward)
META=f;;
esac
[ ! -z "${META}" ] && break;
done
this="."
case ${META} in
f)
mfwd ${this};;
r)
mrep ${this};;
q)
return;;
*)
;;
esac
mseq -f | mseq -S
done
}
_mread $@