[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A conditional statement defines the control flow in the section. It allows to execute arbitrary actions depending on whether a certain condition is met. A conditional statement in its simplest form is:
if part [pattern-match-flags] cond-expr action-list-1 fi |
The optional pattern-match-flags alter the pattern matching type used in subsequent conditional expression. It will be described in detail in the section 6.5 Regular Expressions. The cond-expr is a conditional expression. It consists of a series of conditions joined together with boolean operators `and' or `or' (see section 6.4 Boolean Operators). Each condition is:
The simplest example:
if header [Subject] "^ *Re:" ... fi |
The actions represented by ... will be executed only if the `Subject:' header of the message starts with `Re:' optionally preceded by any amount of whitespace.
The more elaborate form of a conditional allows you to choose among the two different action sets depending on a given condition. The syntax is:
if part [flags] cond-expr action-list-1 else action-list-2 fi |
Here, the action-list-1 is executed if the condition cond-expr is met. Otherwise, action-list-2 is executed.
if part [flags] cond-expr action-list-1 else action-list-2 fi |
Note also, that in the examples above any of the statements action-list may contain conditionals, so that the conditional statements may be nested. This allows to create very sophisticated rule sets. As an example, consider the following statement:
if [List-Id] :re ".* |
This statement, depending on the value of List-Id
header, will
prepend the Subject
header with an identification string, or add
an X-Passed
header if no known List-Id
was found.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |