.\"	This file is automatically generated.  Do not edit!
.SC MHOOK 1
.NA
mhook \- MH receive\-mail hooks
.SY
$HOME/\&.maildelivery
.ds SL \fIslocal\fR
.ds ZS slocal

.ti .5i
/usr/new/lib/mh/rcvdist
address\ ...
\%[\-help]

.ti .5i
/usr/new/lib/mh/rcvpack
file
\%[\-help]

.ti .5i
/usr/new/lib/mh/rcvtty
\%[command\ ...]
\%[\-help]
.DE
A receive\-mail hook is a program that is run whenever you receive a
mail message.
You do \fBNOT\fR invoke the hook yourself,
rather the hook is invoked on your behalf by \fISendMail\fR,
when you include the line
.nf
.in +.5i
    \*(lq| /usr/new/lib/mh/slocal\*(rq
.in -.5i
.fi
in your \&.forward file in your home directory.

The \fI\&.maildelivery\fR file,
which is an ordinary ASCII file,
controls how local delivery is performed.
This file is read by \*(SL.
.if '\*(ZS'slocal' \{\

The format of each line in the \fI\&.maildelivery\fR file is

.ti +.5i
\fBfield pattern action result string\fR

where

.in +.5i
.ti -.25i
\fBfield\fR:
.br
The name of a field that is to be searched for a pattern.
This is any field in the headers of the message that might be present.
In addition, the following special fields are also defined:
.in +.25i
\fIsource\fR: the out\-of\-band sender information
.br
\fIaddr\fR: the address that was used to cause delivery to the recipient
.br
\fIdefault\fR: this matches \fIonly\fR if the message hasn't been delivered yet
.br
\fI*\fR: this always matches
.in -.25i

.ti -.25i
\fBpattern\fR:
.br
The sequence of characters to match in the specified field.
Matching is case\-insensitive but not RE\-based.

.ti -.25i
\fBaction\fR:
.br
The action to take to deliver the message.
This is one of

.in +.5i
.ti -.5i
\fIfile\fR or \fI>\fR:
.br
Append the message to the file named by \fBstring\fR.
The standard maildrop delivery process is used.
If the message can be appended to the file,
then this action succeeds.

When writing to the file,
a new field is added:

.ti +.5i
Delivery\-Date:\ date

which indicates the date and time that message was appended to the file.

.ti -.5i
\fIpipe\fR or \fI|\fR:
.br
Pipe the message as the standard input to the command named by \fBstring\fR,
using the Bourne shell \fIsh\fR\0(1) to interpret the string.
Prior to giving the string to the shell,
it is expanded with the following built\-in variables:
.in +.25i
$(sender): the return address for the message
.br
$(address): the address that was used to cause delivery to the recipient
.br
$(size): the size of the message in bytes
.br
$(reply\-to): either the \*(lqReply\-To:\*(rq or \*(lqFrom:\*(rq field
of the message
.br
$(info): miscellaneous out\-of\-band information
.in -.25i

When a process is invoked, its environment is:
the user/group id:s are set to recipient's id:s;
the working directory is the recipient's directory;
the umask is 0077;
the process has no /dev/tty;
the standard input is set to the message;
the standard output and diagnostic output are set to /dev/null;
all other file\-descriptors are closed;
the environment variables \fB$USER\fR, \fB$HOME\fR, \fB$SHELL\fR are set
appropriately,
and no other environment variables exist.

The process is given a certain amount of time to execute.
If the process does not exit within this limit,
the process will be terminated with extreme prejudice.
The amount of time is calculated as ((size x 60) + 300) seconds,
where size is the number of bytes in the message.

The exit status of the process is consulted in determining the success of the
action.
An exit status of zero means that the action succeeded.
Any other exit status (or abnormal termination) means that the action failed.

In order to avoid any time limitations,
you might implement a process that began by \fIforking\fR.
The parent would return the appropriate value immediately,
and the child could continue on,
doing whatever it wanted for as long as it wanted.
This approach is somewhat risky if the parent is going to return an
exit status of zero.
If the parent is going to return a non\-zero exit status,
then this approach can lead to quicker delivery into your maildrop.

.ti -.5i
\fIqpipe\fR or \fI<caret>\fR:
.br
Similar to \fIpipe\fR,
but executes the command directly,
after built\-in variable expansion,
without assistance from the shell.

.ti -.5i
\fIdestroy\fR:
.br
This action always succeeds.
.in -.5i

.ti -.25i
\fBresult\fR:
.br
Indicates how the action should be performed:

.in +.5i
.ti -.5i
\fIA\fR:
.br
Perform the action.
If the action succeeded, then the message is considered delivered.

.ti -.5i
\fIR\fR:
.br
Perform the action.
Regardless of the outcome of the action,
the message is not considered delivered.

.ti -.5i
\fI?\fR:
.br
Perform the action only if the message has not been delivered.
If the action succeeded, then the message is considered delivered.
.in -.5i
.in -.5i

The file is always read completely,
so that several matches can be made and several actions can be taken.
The \fI\&.maildelivery\fR file must be owned either by the user or by root,
and must be writable only by the owner.
If the \fI\&.maildelivery\fR file can not be found,
or does not perform an action which delivers the message,
then the file /usr/new/lib/mh/maildelivery is read according to the same rules.
This file must be owned by the root and must be writable only by the root.
If this file can not be found
or does not perform an action which delivers the message,
then standard delivery to the user's maildrop, /usr/spool/mail/$USER, is performed.

Arguments in the \fI\&.maildelivery\fR file are separated by white\-space or
comma.
Since double\-quotes are honored,
these characters may be included in a single argument by enclosing the
entire argument in double\-quotes.
A double\-quote can be included by preceeding it with a backslash.

To summarize, here's an example:

.nf
.in +.5i
.ta \w'default  'u +\w'uk-mmdf-workers  'u +\w'action  'u +\w'result  'u
#\fIfield\fR	\fIpattern\fR	\fIaction\fR	\fIresult\fR	\fIstring\fR
# lines starting with a '#' are ignored, as are blank lines
#
# file mail with mmdf2 in the \*(lqTo:\*(rq line into file mmdf2.log
To	mmdf2	file	A	mmdf2.log
# Messages from mmdf pipe to the program err-message-archive
From	mmdf	pipe	A	err-message-archive
# Anything with the \*(lqSender:\*(rq address \*(lquk-mmdf-workers\*(rq
# file in mmdf2.log if not filed already
Sender	uk-mmdf-workers	file	?	mmdf2.log
# \*(lqTo:\*(rq unix \- put in file unix-news
To	Unix	>	A	unix-news
# if the address is jpo=mmdf \- pipe into mmdf-redist
addr	jpo=mmdf	|	A	mmdf-redist
# if the address is jpo=ack \- send an acknowledgement copy back
addr	jpo=ack	|	R	\*(lqresend\0\-r\0$(reply-to)\*(rq
# anything from steve \- destroy!
From	steve	destroy	A	\-
# anything not matched yet \- put into mailbox
default	\-	>	?	mailbox
# always run rcvalert
*	\-	|	R	rcvalert
.re
.in -.5i
.fi
.\}
.if '\*(ZS'mmdfII' \{\
See \fImaildelivery\fR\0(5) for the details.
.\}

Four programs are currently standardly available,
\fIrcvdist\fR (redistribute incoming messages to additional recipients),
\fIrcvpack\fR (save incoming messages in a \fIpackf\fR'd file),
and \fIrcvtty\fR (notify user of incoming messages).
The fourth program,
\fIrcvstore\fR\0(1) is described separately.
They all reside in the \fI/usr/new/lib/mh/\fR directory.

The \fIrcvdist\fR program will resend a copy of the message to all of the
addresses listed on its command line.

The \fIrcvpack\fR program will append a copy of the message to the file listed
on its command line.
Its use is obsoleted by the \fI\&.maildelivery\fR.

The \fIrcvtty\fR program executes the named file with the message as its
standard input,
and gives the resulting output to the terminal access daemon for display
on your terminal.
If the terminal access daemon is unavailable on your system,
then \fIrcvtty\fR will write the output to your terminal
if, and only if, your terminal has \*(lqworld\-writable\*(rq permission.
If no file is specified, or is bogus, etc.,
then the \fIrcvtty\fR program will give a one\-line scan listing
to the terminal access daemon.
.Fi
^/usr/new/lib/mh/mtstailor~^tailor file
^$HOME/\&.maildelivery~^The file controlling local delivery
^/usr/new/lib/mh/maildelivery~^Rather than the standard file
.Sa
.if '\*(ZS'slocal' \{\
rcvstore (1)
.\}
.if '\*(ZS'mmdfII' \{\
rcvstore (1), maildelivery(5)
.\}
.Co
None
.if '\*(ZS'slocal' \{\
.Hi
For compatibility with older versions of \fIMH\fR,
if \fIslocal\fR can't find the user's \fI\&.maildelivery\fR file,
it will attempt to execute an old\-style rcvmail hook in the user's $HOME
directory.
In particular,
it will first attempt to execute

.ti +.5i
\&.mh\(rureceive file maildrop directory user

failing that it will attempt to execute

.ti +.5i
$HOME/bin/rcvmail user file sender

before giving up and writing to the user's maildrop.

In addition,
whenever a hook or process is invoked,
file\-descriptor three (3) is set to the message in addition to the standard
input.

.\}
.Bu
Only two return codes are meaningful, others should be.

.if '\*(ZS'mmdfII' \{\
Versions of \fIMMDF\fR with the \fImaildelivery\fR mechanism aren't
entirely backwards\-compatible with earlier versions.
If you have an old\-style hook, the best you can do is to have a one\-line
\fI\&.maildelivery\fR file:

.ti +.15i
default \- pipe A \*(lqbin/rcvmail $(address) $(info) $(sender)\*(rq
.\}
.En
