mhook
Purpose
Specifies actions to be taken when mail is received.
Description
An mhook (or receive-mail hook) is an action that is
automatically performed when new mail is received through
the Message Handling (MH) Package. Whenever you receive
a new message, the sendmail command searches for the file
.forward in your $HOME directory. sendmail pipes the new
message to the slocal program when $HOME/.forward exists
and contains the following line:
| /usr/lib/mh/slocal
The slocal program reads the file $HOME/.maildelivery and
performs the actions specified in that file for each
message being delivered. You can specify your own mail
delivery instructions (or mhooks) in $HOME/.maildelivery.
Each line in $HOME/.maildelivery describes an action and
the conditions under which the action should be per-
formed. Each line must contain five arguments separated
by commas or space characters. These arguments are:
field pattern action result string
The following list describes each argument:
field Specifies a header component field to be
searched for a match to the character string
specified in the pattern argument. You can
specify one of the following values for the
field argument:
component Searches the specified header compo-
nent.
"*" Always matches.
addr Searches whatever field was used to
deliver the message to you.
default Matches only if the message has not
been delivered yet.
source Specifies the out-of-band sender
information.
pattern Specifies the character string to search for in
the header component given by the field argu-
ment. The pattern argument is not case sensi-
tive. Thus, the character string matches any
combination of upper case and lower case char-
acters. You must specify a dummy pattern if
you use "*" or default in the field argument.
action Specifies an action to take with the message if
the message contains the pattern specified in
the pattern argument. You can specify the fol-
lowing actions:
file or > Appends the message to the file
given by the string argument. If
the message can be written to the
file, the action is considered suc-
cessful. When a message is
appended to a file, the header com-
ponent Delivery-Date: is added to
the message to indicate when the
message was appended to the file.
pipe or | Pipes the message as standard input
to the command named by the string
argument, using the shell to inter-
pret the string. If the exit
status from the command is 0
(zero), the action is considered
successful. Prior to giving the
string to the shell, the string is
expanded with the following
built-in variables:
$(sender) The return address
for the message.
$(address) The address that was
used to deliver the
message.
$(size) The size of the
message in bytes.
$(reply-to) Either the Reply-To:
or From: header com-
ponent of the
message.
$(info) Miscellaneous out-of-
band information.
qpipe or ^ Similar to pipe, but executes the
command directly after built-in
variable expansion without assist-
ance from the shell. If the exit
status from the command is 0
(zero), the action is successful.
destroy Always succeeds.
result Indicates how the action should be performed.
You can specify one of the following values for
this argument:
A Performed the action. If the action suc-
ceeds, the message is considered deliv-
ered.
R Performs the action. Even if the action
succeeds, the message is not considered
delivered.
? Performs the action only if the message
has not been delivered. If the action
succeeds, the message is considered deliv-
ered.
string If you use file as the action argument, string
specifies the file to which the message can be
appended. If you use pipe or qpipe, string
specifies the command to execute. If you use
destroy as the action argument, string is not
used, but you must still include a dummy string
argument.
All five arguments must be present in each line of the
file. Blank lines in .maildelivery are ignored. Put a #
in the first column to indicate a comment.
If .maildelivery cannot be found, or does not deliver the
message, /usr/lib/mh/maildelivery is used in the same
manner. If the message is still not delivered, it is
delivered to the user's maildrop, /usr/mail/$USER.
MH contains four standard programs that can be run as
receive-mail hooks: rcvdist, rcvpack, rcvstore, and
rcvtty. AIX Operating System Commands Reference contains
descriptions of these programs.
Example
The following example shows some lines that can be speci-
fied as mhooks in $HOME/.maildelivery:
# If the message is from George, save it.
From george file A george.mail
# If the message is to the project manager, save a copy in log.
addr manager > R proj_X/statlog
# and forward it to Amy
addr manager | A "/usr/lib/mh/rcvdist amy"
# Save any messages not delivered.
default - > ? mailbox
Files
$HOME/.forward The file searched by the sendmail
command when mail is received.
/usr/lib/mh/slocal The slocal program that, when
specified in
/usr/lib/mh/maildelivery The mail delivery instructions.
$HOME/.forward, performs actions
defined in $HOME/.maildelivery.
$HOME/.maildelivery The file specifying receive-mail
hooks for slocal to perform.
Related Information
The "Overview of the Message Handling Package" in Man-
aging the AIX Operating System.
The commands rcvdist, rcvpack, rcvstore, rcvtty,
sendmail, and slocal in AIX Operating System Commands
Reference.