GNU Mailutils Manual (split by node):   Section:   Chapter:FastBack: Sieve Language   Up: Syntax   FastForward: Reporting Bugs   Contents: Table of ContentsIndex: Function Index

5.2.3 Control Flow

The only control flow statement Sieve has is if statement. In its simplest form it is:

if condition { … }

The effect of this statement is that the sequence of actions between the curly braces is executed only if the condition evaluates to true.

A more elaborate form of this statement allows to execute two different sets of actions depending on whether the condition is true or not:

if condition { … } else { … }

The most advanced form of the “if” statement allows to select an action depending on what condition from the set of conditions is met.

if cond1 { … } elsif cond2 { … } else { … }

There may be any number of “elsif” branches in an “if” statement. However it may have at most one “else” branch. Notes for C programmers:

  1. The braces surrounding each branch of an “if” statement are required.
  2. The “else if” construct is disallowed. Use “elsif” keyword instead.

Here’s an example of “if” statement:

if header :contains "from" "coyote"
  {
    discard;
  }
elsif header :contains ["subject"] ["$$$"]
  {
    discard;
  }
else
  {
    fileinto "INBOX";
  }

The following section describes in detail conditions used in “if” statements.

GNU Mailutils Manual (split by node):   Section:   Chapter:FastBack: Sieve Language   Up: Syntax   FastForward: Reporting Bugs   Contents: Table of ContentsIndex: Function Index