1#!/bin/zsh 2# 3# This autoloadable function checks the folders specified as arguments 4# for new mails. The arguments are interpreted in exactly the same way 5# as the mailpath special zsh parameter (see zshparam(1)). 6# 7# If no arguments are given mailpath is used. If mailpath is empty, $MAIL 8# is used and if that is also empty, /var/spool/mail/$LOGNAME is used. 9# This function requires zsh-3.0.1 or newer. 10# 11 12emulate -L zsh 13local file message 14 15for file in "${@:-${mailpath[@]:-${MAIL:-/var/spool/mail/$LOGNAME}}}" 16do 17 message="${${(M)file%%\?*}#\?}" 18 file="${file%%\?*}" 19 if [[ -d "$file" ]] then 20 file=( "$file"/**/*(.ND) ) 21 if (($#file)) then 22 checkmail ${^file}\?$message 23 fi 24 elif test -s "$file" -a -N "$file"; then # this also sets $_ to $file 25 print -r -- "${(e)message:-You have new mail.}" 26 fi 27done 28