#!/bin/sh -ue # # Read a mail folder with mutt. # - Cameron Simpson # set -ue : ${MAILHOMEHOST:=$HOMEHOST} : ${DISPLAY:=''} : ${LOGDIR:=$HOME/var/log} : ${ALERTLOG:=$LOGDIR/alert} : ${MAILDIR:=$HOME/mail} : ${MAIL_EXPIRE_FORMAT:='%Y'} # versus, say, %Y-%m needhost "$MAILHOMEHOST@$SYSTEMID" \ || { rhost=$SYSTEMID # sshto clause to deliver to system home host qargv=`shqstr + -s "$@"` set -x exec envssh -t "$rhost" "$qargv" } cmd=$0 usage="Usage: $0 [+a] [+s] [+t] [-f] [some-mutt-options...] [mutt-folder]" mfolder=+me delay=5 muttopts= anyhost= use_term= ## 1; case "$DISPLAY" in localhost:[1-9]*) use_term= ;; esac use_screen= preshcmd=: postshcmd=: termopts='-g M' badopts= while [ $# -gt 0 ] do case $1 in +a) termopts="$termopts $1" ;; -s) use_screen=1 ;; +s) use_screen= ;; +t) use_term= ;; -f) anyhost=1 ;; -[nR]) muttopts="$muttopts $1" ;; -[em]) muttopts="$muttopts $1 "`shqstr "$2"`; shift ;; --pre=*) preshcmd=`expr "x$1" : 'x--pre=\(.*\)'` ;; --post=*) postshcmd=`expr "x$1" : 'x--post=\(.*\)'` ;; --) shift; break ;; -?*|+?*) echo "$cmd: unrecognised option: $1" >&2; badopts=1 ;; *) break ;; esac shift done if [ $# -gt 0 ] then case $1 in /*|.|./*|..|../*) mfolder=$1 ;; +*) mfolder=$1 ;; imap:*|imaps:*) mfolder=$1 anyhost=1 ;; *?.?*) mfolder=nntp://$NNTPSERVER/$1 anyhost=1 ;; *) mfolder=+$1 ;; esac shift [ $# = 0 ] || { echo "$cmd: extra arguments: $*" >&2; badopts=1; } else # hack to clear my alert window when I view my default folder ( clear >>"$ALERTLOG" ) & fi [ $badopts ] && { echo "$usage" >&2; exit 2; } fpath=`mailfolderpath "$mfolder"` || exit 1 muttcmd="$HOME/bin-local/mutt -f '$mfolder' -e 'fcc-hook . $mfolder' $muttopts" # where to take copies - presumes sendmail=sendmesg-fcc in muttrc SENDMESG_FCC="$fpath +spool-out" export SENDMESG_FCC if [ -z "$fpath" ] then fbase=misc else fbase=`basename "$fpath"` ismaildir "$fpath" \ || ismhdir "$fpath" \ || { echo "$cmd: $fpath: not Maildir or MH folder" >&2 exit 1 } mutthcache=$HOME/var/mutt/header-cache/$fbase { needdir "$mutthcache" \ && muttcmd="$muttcmd -e 'set header_cache=$mutthcache'" } || : fmuttrc=$fpath/.muttrc [ ! -s "$fmuttrc" ] || muttcmd="$muttcmd -e 'source $fmuttrc'" fpremutt=$fpath/.preshcmd [ ! -s "$fpremutt" ] || preshcmd="$preshcmd; . $fpremutt" fpostmutt=$fpath/.postshcmd [ ! -s "$fpostmutt" ] || postshcmd="$postshcmd; . $fpostmutt" fi CURRENT_FOLDER=$fpath DELETE_FOLDER=$MAILDIR/OLD/`date "+$MAIL_EXPIRE_FORMAT"`/$fbase export DELETE_FOLDER export CURRENT_FOLDER DELETE_FOLDER maildir "$DELETE_FOLDER" set -- sh -c "exec $muttcmd" [ $use_screen ] && set -- scr "MUTT_$mfolder" "$@" [ $use_term ] && set -- term -j email $termopts -n "mutt $mfolder" "$@" [ -z "$preshcmd" ] || eval "$preshcmd" "$@" xit=$? [ -z "$postshcmd" ] || eval "$postshcmd" || xit=1 exit $xit