include "$book/mh.php";
includeHeader('chaenv.html', 'usiinf.html');
?>
Writing Your Own Draft Message Editor(s)
You may want to do more than an editor like vi
or emacs can do to a draft message. For instance, you might
want to start prompter on the new draft, then run a second
editor to fill in the body. Or you might want to do something
automatically each time a draft message is edited, like updating a
mail message log. Or you could customize the way that a particular
MH program, such as dist, handles a draft message. These
are all good reasons to write a special editing shell script.
There are five things to know before you write your editor script:
Each of the four mail composition commands will make a draft
message for you. If no other editor (including prompter)
has touched it, the draft will contain:
For comp, an empty copy of the components file.
(Exception: with comp -use, draft will be exactly as it
was left before.)
For repl, the result of the replcomps file, with
the original message filtered through the -filter file
(if you used one).
For forw, a copy of the forwcomps file, with the
forwarded message(s) (filtered through -format
or -filter if you used one).
Your editor should save the edited draft in the same file
($1) where it read the draft from.
If your editor exits with a zero status, whatnow will
prompt the user What now?. But, as the Section
Aborted Draft Messages
explains, if your editor exits with a nonzero
status, whatnow will abort without sending the message,
and:
If the mhuse variable is set to 1
(the comp -use program is being used), your draft message
won't be deleted.
Otherwise, the draft message will be deleted.
distprompter, an editor shell
script, acts like prompter to read the message header of a
message you're distributing with dist. When it's done
reading the header fields, it saves the draft and exits without
giving you a chance to type the body (you can't type a body for
dist).
Even if you don't run distprompter, it's a good example of
what you can do with an MH draft editor. To
run distprompter or another editor that you write, put an
entry like this in your MH profile:
dist: -editor distprompter
If you write a more general purpose shell script editor for all
the MH message composing programs, you can use an MH profile entry
like this instead:
Editor: myeditor
One more note about editors: even though the
mh-profile(5) and whatnow(1) manual pages have a lot
of details, they don't explain an editor's environment or the
effect of its exit status very thoroughly. I wrote this little
test editor script that helped me learn. Maybe it'll help you:
#! /bin/sh
echo The environment of $0:
printenv
echo "Command line had: '$*'"
echo -n "Enter exit status for $0: "
read stat
exit $stat