Using the MH/nmh inc program

The slocal program is part of MH/nmh. It uses a filter specification file .maildelivery in your home directory. Filtering is done based on strings that appear in mail headers. There are several things you can do with a message, but generally you file it into a folder where exmh will find it as unread.

There are two ways to integrate slocal and exmh:

Integration with exmh - .forward file

To run slocal from your .forward file, add a line like this to it:

 | /usr/lib/nmh/slocal -user username

In this case you want exmh to look for mail in the background with Flist. You can set up Flist as a background action under background processing. flist is also an MH program you can run from the command line to report on which folders have unseen messages.

Integration with exmh - presort or presort-multi

If you select presort style under Incorporate Mail preferences, then exmh will inc your mail into a MyIncTmp folder, and then run slocal against each message found there. Afterwards it will automatically highlight the folders that contain unseen messages.

If you select 'presort-multi style under Incorporate Mail preferences, then exmh will consult your .xmhcheck file for a list of hosts to contact via POP for mail. It will pull all the mail into the MyIncTmp folder and sort it with slocal, and then highlight the new mail. See [POP and exmh] for details about fetching mail via POP.

The .maildelivery filter file

Here are the first few lines of my ~/.maildelivery file. (Note that some versions of MH insist that this file is only writable by your account.) Primarily I just use + rules that cause mail to be put into folders. However, you can also run programs against mail, or file them into mbox files.

 #field  value                            action  result  command
 #-----  -----                            ------  ------  -------
 #*      -                               +       R       allmail
 delivered-to    brent.welch@interwoven  +       ?       urgent
 delivered-to    welch@scriptics         +       ?       urgent
 delivered-to    welch@ajubasolutions    +       ?       urgent
 # code red worm
 content-type    "Outlook_Express_message_boundary"       qpipe ? "/usr/bin/tclsh8.0 bin/codered.tcl"
 to      admin@lists.sourceforge         +       ?       urgent
 subject Xconq                           +       ?       xconq
 from    P4                              +       ?       p4
 from    perforce@                       +       ?       p4
 from    welch@panasas                   +       ?       inbox
 from    bugzilla                        +       ?       bugs
 from    @panasas                        +       ?       panasas
 # IMPORTANT to have a default rule at the end
 default -                               +       ?       default

The first column is a mail header, and the second column is a case-insensitive sub-string that must appear in that mail header for the rule to apply. In addition to normal headers, there are some special fields:

source
The out-of-band sender information (i.e., envelope sender). Sometimes useful because the From: line may not reflect the true sender.
addr
The address that caused delivery of this message to you.
default
Only applies if this message hasn't been delivered yet. It is very important to put a default rule at the end of your filters.
*
This always matches.

Each rule has an action:

folder
File the message into the named folder. This uses the rcvstore program that adds the message to the unseen sequence for the folder.
+
Same as folder
qpipe
Pipes the message into a program.
pipe
Pipes the message into a shell command.
file
Appends the message to a file in mbox format.
>
Same as file.
destroy
Use carefully!

Each rule has a result that determines if a rule should be applied, and if so, if the message should be considered delivered. You'll see that it is possible for more than one rule to be applied to a message.

?
Run the rule if the message has not already been delivered (and the pattern matches, of course). Then consider the message delivered.
A
Always run the rule, and then consider the message delivered.
R
Run the rule regardless of its delivered status. The message is not considered delivered. The sample rule that uses this, which is commented out, results in an extra copy of all messages in the allmail folder.

The complete description of the maildelivery file can be found in the mhook man page.

When you are starting out, you probably want most things to go to your inbox, with a few exceptions. The following .maildelivery will put mail from addresses in my company to its own folder, and everything else to inbox:

 #field  value                            action  result  command
 from    @panasas                         +       ?       panasas
 default -                                +       ?       inbox


Updated on 10 Mar 2003, 04:56 GMT
Search - Recent Changes - Reference - Index - Go to Beedub's Wiki - Help