# The .maildelivery File: Overview

> NOTE: for users of the online version of this book: This section has a lot of examples followed by long explanations. To avoid jumping between the example and its explanation, it's a good idea to open a new browser window to show an example. (Check your browser's menu for a command like New Web Browser or Open in New Window). Then, use the original browser to read the explanation while you view the example in the second browser window.

Without a .maildelivery file, when new mail arrives, your computer's MTA drops it in your system mailbox. The entries you put in your .maildelivery file will control what happens instead. This section gives an overview. The Section The .maildelivery File in Detail has more info.

> NOTE: You should not perform the steps in this section, to set up your .maildelivery file, yet. Instead, give the file another name. When you're ready to use the file, follow the instructions in the Section Running Your .maildelivery File for enabling the file. Rename your temporary version to .maildelivery then.

When a new message comes in, the .maildelivery file is read entry by entry, from top to bottom. If an entry matches the incoming message, an action on the entry stores the message in a file or passes the message to a command listed on that entry. Then, in most cases, the message will be flagged as "delivered." Following entries in .maildelivery can test whether the message has been delivered by a previous entry.

The system is fairly easy to understand and set up. It's not as flexible as you might want it to be, but you can work around most of the problems.

Let's look at the simple .maildelivery file in the next Example. The line numbers to the left of each line (like `2>`) are not part of the file; they are for reference only. Entries starting with a hash mark (`#`) are comments that explain the following entry. Comments aren't required, but they're a good idea! (You can also get the file, without line numbers, from this book's online archive. It's in examples/mh/misc/maildelivery-1.)

Example: Simple .maildelivery file

        1> # Throw away all mail from this guy:
        2> from     flamer@xyz.abc  destroy A  -
        3> # File VAX mailing list in +vax folder; I read it later:
        4> subject  "vax digest"    qpipe   A  "/x/y/rcvstore +vax"
        5> # Put the rest into my maildrop:
        6> default  -               file    ?  /usr/spool/mail/jerry

In general:

- Line 2 will match if the message has the `From:` address flamer@xyz.abc. That message will be "destroyed" -- in other words, unless another entry in the .maildelivery file delivers it, the message will never be delivered.
- Line 4 will match any message that contains the expression "vax digest" somewhere in its `Subject:` field. This will match a longer subject, in uppercase or lowercase, like "Info-VAX Digest, issue 23". There are double quotes (`"`) around the argument because of the space in it. These messages are added to my MH folder named vax.

  The `/x/y` is the absolute pathname of the directory that holds the rcvstore program. See the NOTE in the Section The .maildelivery File in Detail.

- If neither entry above succeeded, line 6 will append the message to my system mailbox, /usr/spool/mail/jerry.

You can do a lot more than that simple example shows. The Section The .maildelivery File in Detail explains the syntax of .maildelivery. Sections after it cover rcvstore and other programs.