Sieve adjustcounter extension

New in 8.0, a set of eight signed, 64 bit counters has been added to the MTA&#x27;s counters. The values of this set of counters can be adjusted from system Sieve scripts, and later be displayed or accessed via the usual counters display and access facilities. These counters have no predefined meanings; they can be used for any purpose.

A nonstandard Sieve action " " has been added to manipulate these counters, with syntax: adjustcounter &#x5b;:duplicate&#x5d; &#x5b;:channel channel-string&#x5d; counter &#x5b;value&#x5d; where " " specifies the counter to operate on (an integer in the range 1-8). " " is the amount by which to adjust the counter; if omitted, it defaults to 1.

The counters associated with the current source channel are affected by default. The " " nonpositional parameter can be used to switch to some other channel. Note that variable substitution can be used on the " " argument to select a channel computed by the script. Also note that the channel must be defined in the configuration;  arbitrary channel  names are not allowed.

The " " action can only be used in system-level Sieves; an error will occur if an attempt is made to use it from user-level sieves.

Sieve scripts may be reevaluated multiple times, e.g., when a message is sent to multiple recipients and the script employs an envelope "to" test. When this happens it is normally not desirable for the counter operation to be repeated, so counter adjustments are suppressed by default when scripts are reevaluated. This default can be overridden by specifying the " " nonpositional parameter.

The counters show up in " "  output as follows: Sieve counter &#x5b;1&#x5d;               1 Sieve counter &#x5b;2&#x5d;               10 Sieve counter &#x5b;3&#x5d;               10 Sieve counter &#x5b;8&#x5d;               -15 Note that counters can have negative values. Also note that counters with a value of 0 are suppressed from the display.

These counters can also be retrieved through the   routine in the PMDF API.

As an example, the following script fragment, if implemented in a system Sieve on a system that has OpenDKIM set up as a milter, will keep track of DKIM verification operations: require &#x5b;"variables", "environment"&#x5d;; if environment :matches "host" "&#x2a;" {set "host" "${0}";} if header :matches :index 1 "authentication-results" "&#x2a;${host}&#x2a;dkim&#x2a;" { if header :contains :index 1 "authentication-results" "dkim=pass" { adjustcounter 1; } else { adjustcounter 2; }  adjustcounter 3; } else { adjustcounter 4; } Counter 1 will contain the number of successful verifications performed, counter 2 will contain the number of failed verifications, counter 3 will contain the total verifications, and counter 4 will count the number of messages without a local DKIM result.

See also:
 * Available channels
 * MTA counters
 * Sieve envelope extension
 * counters -show utility
 * Milter spamfilterN_config_file
 * Sieve filters
 * Sieve supported extensions