The compare() command checks values in header fields for a comparison value to be defined.
This command compares the content of a header (header-field) by means of a comparison operator (operator) with the indicated value (value).
Structure of the command
compare('header-field','operator','value');
Return value
positive |
if the condition is met |
negative |
if the condition is not met (please also refer to the note on value!) |
Parameters
header-field
Specifies the header field whose contents are to be compared against the contents of the parameter value. All headers in an email can be used as header fields.
Possible values:
•return-path •date •from •sender •reply-to •to •cc •subject •any X-header |
|
According to RFC, headers are case-insensitive. Nevertheless, the 'header-field’ to be compared is replaced in the entered notation. This can be a helpful if a downstream system – contrary to the RFC – expects upper and/or lower cases. |
operator
Possible values:
•equal |
compares for equality (case-sensitive) |
•match |
checks that a regular expression applies (case-insensitive!) |
•substitute |
the same as match, but removes the applicable part of value from the header-field |
|
Encoded fields are decoded before comparison. The special characters tabulator, carriage return, line feed, and end of page are removed before comparison with the operator equal. |
value
Specifies the value against which comparisons are to be made. This value can also be a regular expression.
|
If '’ is indicated as the value, "true" is also returned in cases in which the header indicated under header-field is not present at all! The following log entry is generated: Compare with empty string - skip and return true |
Example 1
Line |
Code |
|---|---|
01 |
if (compare('x-smenc','equal','yes')) { |
02 |
tagsubject('[confidential]'); |
03 |
} |
Explanation
This example checks whether the header x-smenc is present and includes precisely the value yes (line 01). This does not mean that the value yes is only present but that the value exclusively contains yes.
If the queried condition is given, the email is marked for encryption (line 02).
Example 2
Line |
Code |
|---|---|
01 |
if (compare('to','match','@customer\.com')) { |
02 |
tagsubject('[nosign]'); |
03 |
} |
Explanation
This example checks the header to of an outgoing email with the operator match for the existence of the domain @customer.com within the recipient's email address (line 01). If the email address of the recipient contains the string @customer.com the return value of compare() is true, and the key word (tag) [nosign] is added in the subject line (line 02). Depending on the basic configuration of the ruleset, this suppresses the signing of the email.
Example 3
Line |
Code |
|---|---|
01 |
compare('subject','substitute','(\s)*\[secure\]'); |
Explanation
This example checks the subject line (header subject) of an email for the presence of a character string [secure] (as a regular expression (\s)*\[secure\]). If this string is found within the subject line, it is removed.

