taro/taro-reader

94 lines
1.7 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;;
*)
less $1;;
esac
}
save_attachments() {
while true; do
printf "\n"
mshow -t
printf "\n"
printf "select an attachment to save: "
read n
case ${n} in
''|*[!0-9]*) return ;;
*) file=$(mshow -x . ${n}); mv "${file}" ${TARO_DOWNLOADS} ;;
esac
done
}
open_attachments() {
while true; do
printf "\n"
mshow -t
printf "\n"
printf "select an attachment to open: "
read n
case $n in
''|*[!0-9]*) return ;;
*) attachment=$(mktemp)
mshow -O . ${n} > ${attachment}
mimetype=$(mshow -t | grep ${n}: | awk '{print $2}')
mhandle ${attachment} ${mimetype}
rm ${attachment};;
esac
done
}
keep_track_of_mailfile() {
orig=$1
stamp=${orig%,*}
new=$(echo ${stamp}*)
printf "${new}"
}
mread() {
local this=$(mseq $@)
mflag -S ${this}
while true; do
this=$(keep_track_of_mailfile ${this})
if [ ! -e "${this}" ]; then
printf "Looks like this email was refiled... Press Enter to close this window. "
read r
break
fi
(mshow ${this} ; printf "\n"; mshow -t ${this})| less --mouse -Ps"[o]pen or [s]ave attachments, [r]reply, [f]orward, [q]uit"$
case $? in
113) #q
break;;
102) #f
mfwd ${this};;
114) #r
mrep ${this};;
115) #s
save_attachments;;
111) #o
open_attachments;;
esac
done
}
mread $@