Running Linux, 5th Edition - Matthias Kalle Dalheimer [441]
If it starts with a {, then everything until the matching } is considered a nested block. Nested blocks consist of a number of recipes.
Anything else is considered a mailbox name.
The flags are a combination of a number of one-letter flags. The flags are described in Table 23-1 (taken from the procmailrc manpage). There is no need to read the table in detail now; instead, simply look back to it as we show examples in the following sections.
Table 23-1. Procmail flags
Flag
Function
H
Perform an extended regular expression search on the header (default).
B
Perform an extended regular expression search on the body.
D
Check against the regular expression in a case-sensitive manner (default is case-insensitive).
A
Execute the recipe only if there was a match on the most recent recipe without an A or a flag in the current block nesting level.
a
Same as A, but the preceding recipe must have completed successfully.
E
Execute the recipe only if the immediately preceding recipe was not executed. Execution of this recipe also disables any immediately following recipes with the E flag. This allows you to specify else if actions.
e
Execute the recipe only if the immediately preceding recipe was executed but did not complete successfully.
h
Send contents of header to the pipe, file, or mail destination (default).
b
Send contents of body to the pipe, file, or mail destination (default).
c
Create a copy of the mail message so it can be further processed by a later recipe, or delivered.
w
Wait for processing program and check its exit code.
W
Same as w, but suppresses any Program failure message.
i
Ignore any write errors (usually due to a closed pipe).
r
Raw mode. Do not ensure that message ends with an empty line.
Conditions are generally regular expressions found in the header or body of the email. Regular expressions are covered in Chapter 19. But some other special conditions can be used. To select them, the condition must start with one of the flags shown in Table 23-2.
Table 23-2. Procmail condition flags
Condition
Function
!
Act only if the specified condition is false.
$
Interpret text with double quotes in the rest of this condition as it would be interpreted in the bash shell
?
Use the exit code.
<
Run recipe on messages with a total length less than the following number.
>
Run recipe on messages with a total length greater than the following number.
variable
Match the following text against the value of this variable, which can be an environment variable or a combination of B for body and H for header
\
Escapes (leaves as a plain character) any of the entries in this table when it should start the line as a plain character without special meaning.
Examples
Procmail recipes are most easily understood through a number of examples, so the rest of this section will show examples of normal Procmail usage. See the manpage procmailex for more examples.
Each of the examples are simple recipes, not complete Procmail scripts, so you still need the initial content shown in "Preparing Procmail for Use."
Finally, when playing with recipes, remember that Procmail processes them in order. Thus, if a recipe marks mail as delivered, it doesn't show up with other recipes.
Making a backup of all incoming mail
When you are playing around with Procmail, there is a risk that you might develop a recipe that throws away messages that should not have been thrown away. It is therefore a very good idea to use the following recipe which is supposed to be the very first recipe in your Procmail setup:
:0c:
backup
The first line of this recipe has the flag c, which says that even though this recipe matches (which it always will, as the recipe has no conditions), the mail should continue on to other recipes, rather than be stopped here.
After the flag, there is a colon, indicating that the recipe should use a local lock. Thus, before the actions