Condition

From ESM Wiki
Jump to: navigation, search

Contents

Introduction

Condition is an expression that defines rules to calculate boolean (true/false) value of engine configuration options at each request processing transaction. Condition is used to define conditional processing logic. Like template it is a macro expression but it is evaluated not to string but to a boolean.

Syntax of condition reuses argument rule from syntax of template:

condition                   =   (*space unary_bool_operator 1*space condition)
			      | (*space (group | comparison) *(1*space binary_bool_operator 1*space condition) *space);
group			    = “{“ condition “}”;
unary_bool_operator         = “$NOT”;
binary_bool_operator        = “$AND” | “$OR”;
comparison                  = argument 1*space binary_comparison_operator 1*space argument;
binary_comparison_operator  = “$LT” | “$GT” | “$LE” | “$GE” | “$EQ” | “$NE”;

Comparison

Base building block of condition is comparison which compares result values of two templates specified as arguments. Single comparison is already valid condition. Comparison is done by the following principle:

  • argument values are converted to integers and integer comparison is done;
  • if conversion failed then float conversion and comparison is tried;
  • if this also failed then values are compared as strings in lexicographical order case sensitively.

The following binary comparison operators are available:

$LT – Less
$GT – Greater
$LE – Less or equal
$GE – Greater or equal
$EQ – Equal
$NE – Not equal

Examples of comparisons:

${field count} $GE 20             - evaluates to true if “count” field of mysql row is greater or equal then 20.
$recipient $EQ list@example.com   - evaluates to true if recipient is “list@example.com”

Boolean expression

Comparisons may be combined into boolean expression using boolean unary and binary operators. Operator precedence can be managed using curly braces (group construct). Default operator precedence is the following:

  • binary_comparison_operator
  • unary_bool_operator
  • $AND
  • $OR

Example of boolean expressions:

$NOT {    $body_part.malformed $EQ yes
      $OR $body_part.multipart $EQ yes}
$AND $body_part.size $GE 1024             - checks if body part is not malformed and is not multipart and its size greater or equal 1K

Engine-specific operators

Specific engine may extend a set of available operators. Such extension will be available only withing this engine. Extensions should be described in engine specification.

Personal tools