Configuring procmail with The Dotfile Generator

Here's a follow-up article on TDG to show you the easy way to configure the procmail program.
The Conditions of a Recipe

The most common condition to set up is to match one of the header fields with a given regular expression, or to match the body of the letter with a given regular expression. A typical header is shown in Listing 1.

The very first line of the header is special and has been written by the program (often sendmail) sending the letter. This header field is always the same for a given mailing list, so to sort mail from a mailing list, it is a good idea to view the letter with an ordinary file reader (a mail reader will seldom show this line). Copy this information to the pattern field (Figure 4, label (6) ). As the element to match, you have to select "Sendmail from" in entry (5).

Three special macros exist in procmail. These may be used when matching header fields:

  1. TO: This macro matches every destination specification.

  2. FROM_DAEMON: This macro should match when the letter comes from a daemon (which includes mailing lists). It is useful to avoid creating a mail loop with some mailing lists.

  3. FROM_MAILER: Another regular expression, which should produce a match when the letter comes from the mail daemon.

To see what these macros stand for, please refer to the procmailrc man page.

There are many header fields to choose between in the pull down menu (5), but if the one you wish to select isn't located there, you may type it yourself.

The check box (4) may be used to negate the condition, i.e., if the pattern does not match, the condition is fulfilled.

Regular Expressions

So far, I have mentioned that you can type a regular expression in box (6). In most cases, it may not be necessary to know anything about regular expressions since the procmail module will take care of most of it for you. One thing may be worth knowing, and that is that you may match “anything” with ".*". This means that abc.*def will match anything which starts with abc and ends with def, e.g., abcdef or abcXXXXdef. To read a more detailed description of the set of regular expressions used by procmail, press the button labeled Description.

One common pitfall is to forget to match everything at the start of the line. If you wish to set up a regular expression for the From: field above, it is not enough to give the pattern: rick@helix.nih.gov, since this is not at the start of the line. Instead, to tell procmail that every mail message which includes the text rick@helix.nih.gov is to be handled, insert .* in front of the e-mail address.

External Programs

A final way to set up a condition is by using an external program to verify some conditions. This is done by pressing button (7) which brings up a window with a FillOut field like the one in Figure 3. This time, however, the entry has been replaced with a text box. In this text box, you can type some commands to read either the header or the body on standard input. These commands can refer to any header fields from the letter. The lines (separated by a newline) are joined together with a separating semicolon, making each line a separate command.

Procmail will consider the condition fulfilled only if the exit code from the program is 0. This behavior can be changed with the check button (4) in Figure 4.

Actions

The actions that this module can handle are split into six parts. These are described in detail below. To activate an action, you first have to select the check box that is located next to it, making it clear which actions are enabled for a given recipe.

1. Predesigned Filters

To set up a filter, press the button labeled Predesigned Filters in the window. This filter can change the header fields, add new header fields and/or remove existing header fields.

On this page you will find one custom-made filter: Remove signatures. With this filter, you may specify a signature for each e-mail address. If the text you specify is found (exactly), it will be removed from the letter. My intention is to add more custom-made filters as users send me their ideas and filters.

2. Handmade Filters

If you wish to create your own filter, you must go to the page Handmade Filters. On this page, you may send the header and/or the body of a letter through a command.

As an example, you may remove the header with the command

cat ->> /dev/null

or add a message to the body of a message with the command:

echo This letter has been resent to you, by my\
procmail filter!; cat -
If only the filter action is selected, the filter will change the letter permanently, i.e. the changes will affect the subsequent recipes (even on the delivered letter, if no recipes match). This may be useful if you use a mail reader that does not support MIME, and you have a filter to convert MIME-encoded text to 7-bit ASCII. If, however, one of the other actions is also enabled, the changes affect only this recipe.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

tdg home moved

Anonymous's picture

google lists this article pretty high but where can tdg be found nowdays?

Anonymous's picture
White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState