45.4. Creating and Editing Actions

As the introduction to this chapter explains, the Procmail configuration file consists of a series of actions. When email arrives, each is checked in order until one matches and its delivery mode is carried out. If no actions match (or none exist), the email is delivered to the default destination which is usually the user's mail file under /var/spool/mail.

To create a new action, follow these steps:

1.
Click on the Add a new filter action link below the list of existing actions on the module's main page. The form shown in Figure 45.2 will be displayed for entering its destination and conditions.

Figure 45.2. The Procmail action creation form.


2.
Select the type of destination for messages that match this action from the Delivery mode menu. The available options are:

Append to file Email will be appended in standard mailbox format to the file entered in the adjacent text field, such as /var/spool/mail/fred. To throw a message away, enter /dev/null as the file.

Write to maildir Matching email will be added to the Qmail-style mail directory whose path is entered in the text field. If this directory does not yet exist, Procmail will create it (and the needed subdirectories) for the user.

Write to MH folder Email will be added to the specified MH-style mail directory. This mail format also uses one file per message, but places them in all a single directory and gives message files incrementing numeric filenames, like 1, 2, 3 and so on.

Forward to address Email will be sent to the address or user entered in the adjacent text field, such as [email protected].

Feed to program Email messages that match will be fed as input to the program whose path and arguments are entered into the text box next to the menu.

If a nonabsolute mail filename or directory (like Mailbox or Maildir) is entered, Procmail will assume that it is relative to the home directory of the user to whom the email is being delivered.

3.
To have Procmail check the bodies of received messages rather than just the headers, check the Apply conditions to body box. This is necessary if any of the conditions you enter later need to match text in the email itself.

4.
Normally Procmail will ignore the case of headers when checking conditions. To change this, check the Case-sensitive matching box.

5.
If you want Procmail to continue on through the configuration file even if this action matches, check the Continue processing even if conditions match box. This can be used for delivering email to several different files or folders by turning on this option for all delivery rules except the last.

6.
Procmail will normally ignore the exit status of the program to which email is fed. To have it fail (and thus bounce the message) if the program fails, turn on the Wait for action program to finish, and check result option.

7.
If the delivery program that you entered reads in and then outputs email with some modifications, check the Action program is a filter box. The Continue processing even if conditions match option should also be enabled so that processing continues with the modified version of the message. This feature can be useful if you have written a program that checks and marks messages by adding or changing a header, which can then be checked by later actions.

8.
The Action conditions section of the form is for entering the conditions that determine which messages will be delivered by this action. If none are specified, messages that reach the action will always be delivered, and if more than one is entered they must all match for delivery to take place.

This section is actually a table that starts out with two blank rows. The menu in each row determines the type of condition and how the text in the box next to it is interpreted.

The available options are:

Matches regular expression For this condition to match, the message headers (and possibly the body too) must match the Perl-style regular expression entered in the text box. Remember that this expression is applied to all the headers as though they were a single block of text, so you should precede any header name with a ^ to indicate the start of a line. For example, to catch messages whose subject contains the word foo you could enter ^Subject:.*foo.*.

Doesn't match regular expression This condition type works just like the previous one, except that it matches messages that do not match the regular expression.

Evaluate output of command The shell command entered in the text box will be run, its output read by Procmail, and then interpreted again as an action line from the configuration file. This type of condition is extremely powerful as it allows you to create dynamically generated conditions—however, for everyday mail filtering you probably don't need to use it.

Check exit status of command This type of condition matches if the shell command entered has an exit status of zero, indicating success. It can be used to deliver mail to different destinations depending on the system's hostname, the time of day, or the existence of some file.

Mail is smaller than The condition will match if the total size of the message is smaller than the number of bytes entered in the adjacent text box.

Mail is bigger than As its name suggests, this type of condition is the opposite of the previous one.

9.
When you are done entering conditions, hit the Save button. The new action will be added to the list on the main page, and will starting being used on incoming email. To add more than two conditions you will need to re-edit the action so that two more empty rows appear in the Action conditions section.

An existing action can be edited by clicking on its entry in the Action to take column on the module's main page, which brings up an editing form similar to the one in Figure 45.2. From here you can make changes and then hit Save to activate them, or just hit Delete to remove the action altogether.

Because the ordering of actions matters, the module allows you to change their positions in the Procmail configuration with the up and down arrows next to each on the main page. Variable assignments, conditional blocks, and include files can also be moved in the same way.

By following the instructions above, you could easily create an action that delivers all email to the Qmail-style Maildir directory in user's home directories. Even though this mail format is preferable due to its superior reliability compared to the traditional files in /var/spool/mail, it is not much use unless mail clients or the POP3 server on your system know how to read it. The POP3 server that comes with most operating systems expects to find email under /var/spool/mail and so will have to be replaced or reconfigured to support any new mail format or location. Other mail clients that read user mail files directly (such as Pine, Elm, and Usermin) can be configured to use whatever new location you choose.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.74.55