Sieve variables extension

As of MS 6.2, the MTA added initial support for the Sieve variables extension, modified in MS 6.3 as the initial variables draft changed, eventually to become RFC 5229 (Sieve Email Filtering: Variables Extension). Note that as part of allowing use of string variables, the variables extension also adds to the Sieve language a " " action and a " " test.  Also, when variables are enabled, the MTA&#x27;s Sieve implementation allows the use of assignment statements of the forms: var-name := string-expression; var-name = string-expression; That is, either " " or " " is supported as the assignment operator. (Note that the semi-colon terminating the statement may be omitted if the statement is at the end of a block.)

The capability string is " ": require "variables"; Several items of note regarding variables:





Variable substitutions are not allowed in   test arguments. If they are used, an error is likely to occur. For example, this Sieve script will fail: require &#x5b;"variables", "body"&#x5d;; set "a" "testing" if body :contains "${a}" { discard; } This restriction exists so that a list of all arguments to body in all scripts can be computed in advance and searched for in a single pass. If this restriction were to be lifted, it would be easy to construct scripts that would require an arbitrary number of passes over the message, which is unacceptable in a server environment. As such, this should be considered to be a permanent restriction.



 The MTA has a private extension to the Sieve external lists extension, which is that the MTA also supports properties associated with list entries. When Sieve variables are enabled, properties may be returned in additional variables. 

 The " " action&#x27;s " " modifier was first implemented in MS 6.3. However, for MS 7.0.4 the name of the modifier was changed (in the mistaken expectation of a name change in the RFC) to " ". As of the 8.0 release, either modifier name, " " or " ", will be accepted. 

 When the Sieve notify extension of RFC 5435 (capability " ") is enabled also, it adds an " " modifier to the variables " " action. 

 When the Sieve regex extension is enabled also, it adds a " " modifier to the variables " " action. 

 Sieve  match type tests  now set variables in the same way that   match type test do. Note that unlike glob-style matches (as when   is used), where the default is to store whatever matched any wildcard that appears in the pattern, in   match type tests only those regular expressions enclosed in parentheses are stored. If parentheses are needed but storage is not desired, then the  form may be used. 

 The maximum number of variables that the MTA will permit in a Sieve script is controlled by the  MTA option, by default 128. 

 The maximum length that the MTA will permit for a variable name is 128 characters; this is not configurable. </li>

 The MTA does not currently support the use of variable namespaces, so variable names may not contain any periods. </li>



As of the MS 8.0 release, the MTA supports user-defined routines (subroutines) in system-level Sieve filters. Inside such Sieve subroutines, local variables are supported; local variables are declared in a routine by specifying the " " control command immediately preceeding the first use of the variable; e.g.: sub fib(n) {my s = &#x5b;1, 1&#x5d;; my a = 1; my b = 1; loop {exitif --n &#x3c; 2; my c = a + b;                        s .= c;                         a = b;                         b = c;} return s;} </li>



As of the 8.0 release, the MTA supports integer and list variable values in all levels of Sieves; previously, integer and list values were only supported in system-level Sieves. Integer and list values can only be assigned to variables with regular assignment statements, e.g., a = 1; b = &#x5b;"a", "b", "c"&#x5d;; a = a + 1; b .= &#x5b;"d"&#x5d;; Such assignment statements are an extension to Sieve syntax. The " " action provided by the variables extension always produces a variable with a string value.

</li>

</ul>

Examples of using variables can be found in discussions of the Sieve editheader extension, Sieve body extension, Sieve external lists, Sieve mime extension, and Sieve custom tests via mappings.

See also:
 * max_variables MTA Option
 * Sieve body extension
 * Sieve notify extension
 * Sieve editheader extension
 * Sieve external lists
 * Sieve regex extension
 * Sieve custom tests via mappings
 * Sieve filters
 * Sieve supported extensions