Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Mailpath notification message



In the last eposode (Nov 5), Bart Schaefer said:
> On Nov 5,  3:13pm, Nate Johnston wrote:
> } setopt magic_equal_subst                # for `export foo=~/bar`
> } function export() { EXPORT=${1%%\=*} ; typeset -Ux $* }
> } function +() { eval builtin export ${EXPORT}=\$\{$EXPORT\}:\$1 }
> } # some stuff snipped
> } export MAILPATH=        "~/mail/in/inbox?Mail in folder 1"
> }                 +       "~/.samizdat/in/inbox?Mail in filder 2"
> } # more snipped 
> } unfunction export +

That looks.. weird :)  I would rather keep sh-style syntax myself, plus
a notation easy for novices to use.

Here is a set of functions based around elm's "frm" command.  In
addition to "You have new Z-Shell" mail messages generated by the
mailpath variable, the frm command prints an extra line for every
mailbox with messages in it:

You have no mail.
You have 5 messages from the Z-Shell listserv.

I know only enough about zsh's variable substitution to be dangerous,
so my functions might be affected by setopt's I don't know about.

	-Dan Nelson
	dnelson@xxxxxxxxxxxx


To use, put these two functions in .zshenv ( or /etc/zshenv):

---.zshenv---

# _subfrm: Counts messages in a mailbox.  Argument 1 is the path of the
# mailbox.  Argument 2 is assumed to be a string of the form "You have
# new #### mail.".  The 2nd word from the right is pulled out and
# included in the message count.  No message is printed if the mailbox
# size is 0.  Messages are counted by grepping for "From " at the
# beginning of a line.  MMDF users might want to search for ^A's.
_subfrm()
{
	if [[ -s $@[1] ]] ; then 
		local msg
		msg=(${=@[2]})
		echo "You have" $(grep -c "^From " $@[1]) "messages from the $msg[4,-2] listserv."
	else

	fi
}

# frm: Parses the ZSH mailpath to print number of messages in each
# mailbox.  Skips the first entry, which is assumed to be the user's
# main mailbox (handled by the real frm command).  Each array element
# after that is passed to _subfrm.
frm()
{
	local i
	command frm

	for i in $mailpath[2,-1]
		_subfrm ${(s/?/)i}
	true
	# This is here so that frm() always returns success
	# The picky will want to save the result of "command frm" and
	# return that.
}
---.zshenv---

And add these to .zprofile or .zlogin:

---.zprofile---

# Addfrm:  Appends a mailbox to the zsh mailpath array.  Argument 1 is
# the path to the mailbox.  Argument 2 is a single word describing the
# list.  Don't quote this to put spaces in it, as _subfrm splits on
# spaces to extract the description from $mailpath.
addfrm()
{
	if [[ -z $@[2] ]] ; then
		mailpath=($mailpath $@[1])
	else
		mailpath=($mailpath $@[1]"?You have new "$@[2]" mail.")
	fi
}

export MAILPATH=/var/mail/$USER
addfrm ~/Mail/zsh Z-Shell
# Add other mailboxes here

unfunction addfrm
#don't need it any more
---.zprofile---



Messages sorted by: Reverse Date, Date, Thread, Author