A mail system which uses deliver becomes very flexible in its handling of local mail delivery. All files used to control deliver are shell scripts. Thus anything you can express in a shell script can be used to control mail delivery.
deliver was designed for use in two environments. If your Unix system uses smail(8) to handle incoming mail, then you can change the LMAIL macro to call deliver. Or, if you have a Xenix system, deliver can be used as a direct replacement for /usr/lib/mail/mail.local. (If you are using smail under Xenix, either of these approaches will work.) deliver can also be used with sendmail or smail version 3, through the use of .forward files.
By default, deliver deposits mail in the system mailbox for the named user(s). However, deliver is useful specifically because of its ability to vary its behavior depending on the recipient(s) and content of mail messages.
When deliver starts execution, it interprets its arguments in one of three ways. If the -b (mailbox) option was specified, then all arguments are interpreted as mailbox pathnames. Otherwise, if a system delivery file exists, deliver executes it with all of deliver's arguments, interpreting the output as described below; this procedure gives the postmaster control over delivery to non-existent user names. If deliver cannot find a system delivery file, it interprets all its arguments as user names.
After executing the system delivery file (if any), deliver looks in its list of destinations for valid user names without explicitly named mailboxes. If any of those users have user delivery files in their home directories, deliver executes each delivery file with the name of the user for its only argument.
All command line options are put into environment variables, which deliver examines on startup; thus all flags are propagated when deliver is invoked recursively.
On each system the postmaster may create a system delivery file to controls delivery of all messages. The system delivery file, if it exists, is executed with the name(s) specified on the deliver command line as its arguments.
In addition, each user may create a user delivery file in his home directory. User delivery files are always executed with exactly one argument: the name of the user in whose home directory the file is found.
When deliver executes a delivery file, it sets several environment variables, listed below. Note that these environment variables are both set and used by deliver; therefore, all command line options automatically propagate when deliver is run recursively (within a delivery file). Recursive execution of deliver is quite useful, especially with the -b (mailbox) flag.
deliver monitors the standard output of delivery files for lines of two forms: either "user" or "user:mailbox". Those users whose names appear in the output of a delivery file will receive the message. If a mailbox name appears after the user name, then that mailbox receives the message. If a mailbox name is not specified, the user's default mailbox is used. (The default mailbox for a user is configuration-dependent.) If a mailbox is not an absolute pathname, it is interpreted relative to the home directory of the named user.
NOTE 1: When deliver executes a delivery file, it expects that delivery file to explicitly name all users (and, optionally, mailboxes) which should receive the message. If a delivery file does not name any users in its output, then the message will not be delivered to anyone whose mail delivery is controlled by that delivery file.
Therefore, a user delivery file which contains only "exit" will keep the given user from receiving any mail. A system delivery file which contains only "exit" will cause all mail to disappear. So be careful!
NOTE 2: If deliver is setuid root -- which it should be for normal operation -- then the system delivery file is executed as root. Be very careful about its permissions and its contents! If you are not careful, it can easily become a security hole.
NOTE 3: All user delivery files are executed in the context of the user in whose home directory they reside. A user's "context" includes the uid, gid, and home directory as specified in /etc/passwd.
NOTE 4: For security reasons, if a user's home directory is writable to the world, deliver will ignore any deliver file that might be found there.
NOTE 5: For security reasons, deliver rejects lines of the form "user:mailbox" when generated by a user delivery file unless they are output by the given user's delivery file. In other words, no user can request writing a mailbox as another user.
ML_DOTLOCK Lock on exclusive creation of the mailbox name with ".lock" appended. (Version 7 and early BSD mailers use this method.)
ML_DOTMLK Lock on exclusive creation of /tmp/basename.mlk, where basename is the last component of the mailbox pathname. (Xenix mailers use this method.)
ML_LOCKF Exclusively lock mailbox with lockf().
ML_FCNTL Exclusively lock mailbox with fcntl().
ML_LOCKING Exclusively lock mailbox with locking().