The compareattr() command checks attributes/system variables for a comparison value to be defined.
This command compares the content of a variable (attribute) by means of a comparison operator (operator) with the indicated value (value).
Structure of the command
compareattr('attribute','operator','value');
Return value
positive |
if the condition is met |
negative |
if the condition is not met |
Parameters
attribute
Possible values:
•connect_from |
displays the IP address of the system from which an email was sent to the appliance. |
•SENDER |
displays the envelope sender of an email.
|
•use_lfm |
detects the use of LFT even if no headers/subject tags are used and the threshold values are applied |
•unsafe_lfm |
detects the use of the LFT plain mode |
When comparing variables, it is to be ensured that they are entered without the normally prefixed "$". |
operator
Possible values:
•equal |
compares for equality of an expression (string) |
•match |
checks that a regular expression applies (case-insensitive!) |
value
Value to be compared against.
Example 1
Line |
Code |
|---|---|
01 |
if (compareattr('connect_from','equal','172.16.161.1')) { |
02 |
log(1,'Message comes from 172.16.161.1'); |
03 |
} |
Explanation
This example checks whether the email to be processed comes from a specific email server (with the IP address 172.16.161.1). Here, the system variable connect_from is evaluated (line 01).
If the email comes from the server in question, a corresponding log entry is created (line 02).
Example 2
Line |
Code |
|---|---|
01 |
if (compareattr('connect_from','match','172\.16\.161\.[1-2]')) { |
02 |
log(1,'Message comes from 172.16.161.1/2'); |
03 |
} |
Explanation
This example checks whether the email to be processed comes from one of the two email servers with the IP address 172.16.161.1 or 172.16.161.2. Here, the system variable connect_from is evaluated (line 01).
If the email comes from the server in question, a corresponding log entry is created (line 02).
Example 3
Line |
Code |
|---|---|
01 |
if (compareattr('SENDER','equal','<>')) { |
02 |
log(1,'Message has empty envelope sender'); |
03 |
} |
Explanation
This example checks whether the sender in the envelope of the email to be processed is empty. Here, the system variable connect_from is evaluated (line 01).
If the sender in the envelope is empty, a corresponding log entry is created (line 02).
Example 4
Line |
Code |
|---|---|
01 |
if (compareattr('use_lfm','equal','1')) { |
02 |
log(1,'Message is LFT'); |
03 |
if (compareattr('unsafe_lfm','equal','1')) { |
04 |
log(1,'LFT Plain mode is used'); |
05 |
} else { |
06 |
log(1,'LFT Secure mode is used'); |
07 |
} |
08 |
} else { |
09 |
log(1,'No LFT message'); |
10 |
} |
Explanation
This example checks whether the email to be processed is an LFT message (line 01). If not, a corresponding message is issued (line 09), otherwise, a corresponding log message is issued first (line 02) and it is continued to be checked whether the LFT plain mode is used (line 03). If this is the case, a corresponding log entry is generated (line 04), otherwise, a log message indicating that the secure mode is used is issued (line 06).

