Miscellaneous utilities for MH mail handling
--------------------------------------------

These utilities have evolved over time according to what I need for
handling mail. I normally use exmh for reading email, but I have found 
that combining it with command-line MH makes it much more
flexible. See below for a description of the scripts.

For installation, copy the scripts to somewhere in your path. You will 
very likely have to modify the paths in them to your setup.

Several of the scripts below are based on code I have seen in the exmh
mailing list (particularly by John Klassa - thanks!). If you feel your
name should also be here, please let me know.

If you have any comments or suggestions, feel free to drop me an
email.

--Diego Zamboni
  zamboni@purdue.edu

TCSH SETUP
----------

If you use tcshrc, the auto-completion feature is very handy for
dealing with MH mail. The tcshrc-setup file contains the aliases and
auto-completion settings I use. Put it in your .cshrc or .tcshrc file, 
and then you can do things like:

    last10 Org[tab]/Ka[tab]

Which will complete to "last10 Organizations/KarateClub", assuming you 
have a folder called that, of course :-)

The auto-completion settings also work for the regular MH commands, so 
you can do:

    refile +Org[tab]/Ka[tab]

To refile the current message to the "Organizations/KarateClub"
folder.

EXMH SETUP
----------

The msgshow_update_unseen.tcl file contains an exmh hook that makes it 
update the unseen sequence in a folder immediately when a message is
shown, instead of waiting for a "Commit" to take place. I like this
because then the mh scripts keep in sync with exmh, and because I use
gbuffy (http://www.fiction.net/blong/programs/gbuffy/) to show me my
new mail, so the immediate update also makes gbuffy update
immediately.

To install the hook, insert it into your ~/.tk/exmh/user.tcl file, and
follow the usual procedure. If you are not familiar with it, here it is:

	<Quit exmh>
	cd ~/.tk/exmh
	tclsh
	<within tclsh:>
	% auto_mkindex ~/.tk/exmh *.tcl
	<CTRL-D>
	<Restart exmh>

Speaking of gbuffy, I wrote a patch to make it use the unseen sequence 
properly. The patch is in the file gbuffy-use_mhunseen.patch. It has
to be applied to gbuffy 0.2.2. I sent it to the gbuffy author, but he
never replied.

TO DO
-----

- Clean up the scripts and make it easier to change the paths

- Make the commands that show email modify the "prevunseen" sequence
  as they go, so that you can do an "rmmprevunseen" after reading some
  of the email and have it delete only the messages that you haven't
  read.

THE SCRIPTS
-----------

Here's a brief rundown of the commands:

unseen:

	Displays the headers of the unseen messages in all your
	folders. As it goes, it creates a new sequence called
	"prevunseen" which is a copy of the unseen sequence.

	It accepts folder names (without the "+") as optional
	arguments, and that case it only processes those folders
	given.

	This program was originally written by John Klassa and sent to 
	the exmh mailing list, and modified by me. It is also the base 
	for some of the other programs below.

rmmprevunseen:

	Removes the messages belonging to the "prevunseen"
	sequence. The "prevunseen" sequence is used instead of the
	unseen sequence because otherwise you might accidentally
	delete new unseen messages that appear between the last time
	you run "unseen" and the time when you remove unseen messages.

	I am on a lot of mailing lists, and many times I don't want to 
	read all the messages. So instead of using exmh to go to each
	folder and remove things, a sequence might go like this:

	       % unseen
	       ... show unseen messages ...
	       ... read messages I'm interested in ...
	       % unseen
	       ... if there are no additional messages I want to read:
	       % rmmprevunseen

	It makes keeping my email under control so much easier :-)

	You can also give it as arguments the folders you want to
	process.

rmmunseen

	Alias to rmmprevunseen.

rmmallunseen

	Removes all messages in the unseen sequence (the real one, not 
	the "prevunseen" sequence).

firstunseen

	Shows the first unseen message in the folder you specify. The
	message is shown in the terminal. See "seeunseen" below for
	showing it in Exmh.

	Some day I'm going to modify this to show the first unseen
	message on all your folders if you don't give it an argument.

seeunseen

	Alias to ExmhSwitchFolder_showunseen. See below.

ExmhSwitchFolder_showunseen

	Switches to the specified folder in exmh, and shows the first
	unseen message. Exmh is started if it is not running.

ExmhSwitchFolder

	Switches to the specified folder in exmh. Exmh is started if
	it is not running.

last10

	Shows the last 10 messages in the specified folder

mhlast

	mhlast NUM folder [ folder  ... ]

	Shows the last NUM messages in the given folders.

unseenfolders

	Lists the names of the folders that have unseen messages.

markunseen

	Mark the messages given (or the current message without
	arguments) as unseen.
