Scripted filtering provides a flexible and extensible means of creating complex filters. The scripting language used is similar to Microsoft VBScript and includes an in-built function for validating criteria. The variable called FilterResult is used as the return value from the filter and can be set at any time in the script. A FilterResult value of 0 indicates that the filter criteria were not met while a value of 1 indicates that the filter criteria were met, and the associated actions for the filter will be executed. Criteria within scripts can be formed using literal values or tests. Literal values are tokens that are placed in the script and are substituted with their corresponding value. For example, a literal value of [ME_SIZE] can be placed directly in the script for comparison and will be substituted with the message size when the filter is executed. Tests are performed using the CriteriaMet function, and is used for non-numeric values, such as when string comparisons are being made.
|
Token |
Value |
|
[ME_SPAM_PROBABILITY] |
Contains a numeric value of the
calculated Bayesian probability of a message being detected as spam. |
|
[ME_SIZE] |
The size of the message in bytes |
|
[ME_SENDERAUTH] |
Indicates whether the sender of
the message authenticated in order to dispatch the message to MailEnable.
The value is 1 if the sender authenticated, otherwise the value is 0. |
|
[ME_HASVIRUS] |
Indicates whether the message
contained a virus. The value is 1 if the message contained a virus,
otherwise the value is 0. When a virus is detected by filter criteria it
is automatically removed from the message. |
|
[ME_HASANATTACHMENT] |
Indicates whether the message has
an attachment. The value is 1 if the message has an attachment, otherwise
the value is 0. |
Literal enumeration example:
If ([ME_SENDERAUTH] = 0) Then
‘sender has not authenticated
End If
Extra literal values are also available for substitution. These are formatted differently because they are not evaluated as the filter is being executed, but read from the command file for the message being processed.
|
Token |
Value |
|
%IPADDRESS% |
The TCP/IP address of the
originating message |
|
%POSTOFFICE% |
The post office that can
reasonably be assigned to the message. |
|
%SENDER% |
The sender of the message in
Internal format of [CONNECTOR:Address]. E.g. [SMTP:xjz@mailenable.com] |
|
%RECIPIENTS% |
The recipient(s) of the message in
internal format of [CONNECTOR:Address];[CONNECTOR:Address2]. E.g. [SMTP:xjz@mailenable.com];[SMTP:def@mailenable.com] |
|
%SUBJECT% |
The subject of the message. |
|
Example 1: Check whether the
subject of a message contains the letters ABC |
|
If
InStr(1,UCase("%SUBJECT%"),"ABC") > 0 then
FilterResult=1 End If |
|
Example 2: Check if the Subject of
the message contains "Re" at the start of it |
|
If Left("%SUBJECT%",2) =
"Re" then
FilterResult=1 End If |
|
Token |
Value |
|
[ME_TO] |
The message envelope recipients or
the To: denoted in the message headers matches the designated criteria. |
|
[ME_CC] |
The Cc: denoted in the message
headers matches the designated criteria. |
|
[ME_ToorCC] |
The message envelope recipients or
the To: or Cc: denoted in the message headers matches the designated
criteria. |
|
[ME_FROM] |
The message envelope sender or the
From: denoted in the message headers matches the designated criteria. |
|
[ME_HEADERS_CONTAIN] |
The message headers contain data
matching the designated criteria. |
|
[ME_SUBJECT] |
The message subject contains data
matching the designated criteria. |
|
[ME_PRIORITY] |
The priority of the message meets
the designated criteria. |
|
[ME_SPF] |
The SPF response string associated
with the message meets the designated criteria. |
|
[ME_HASATTACHMENTSMATCHING] |
The message contains an attachment
with a file name that meets the designated criteria. |
|
[ME_BODY] |
The body of the message contains
text meeting the designated criteria. |
Literal Enumeration example:
If (CriteriaMet([ME_SUBJECT], "Viagra")) Then
'Do Stuff
End If
In cases where literal values return 1 or 0, it is possible to also use literal values with the CriteriaMet function, although there is no real reason to do so:
Example: CriteriaMet([ME_SENDERAUTH], 0) is the same as
([ME_SENDERAUTH] = 0)
But this is not the case for string values:
CriteriaMet([ME_SUBJECT], "Viagra") is not the same as
([ME_SUBJECT] = "Viagra") because string tokens cannot be used in this manner.
An example script for an advanced
filter is outlined below:
FilterResult=0
If Hour(Now) > 10 Then
If [ME_SIZE] > 1024 OR CriteriaMet([ME_BODY],"*123*") AND
_
CriteriaMet([ME_SUBJECT],"*123*") Then
FilterResult=1
End If
End If
This example script will have its
criteria met under the following circumstances. If it is after the 10th hour of
the day and the size of the message is greater than 1KB Or the
Body of the message contains the string 123.
A more complicated example script for
a filter is outlined below:
FilterResult=0
If Hour(Now) > 10 Then
If [ME_SIZE] > 1024 OR CriteriaMet([ME_BODY],"*123*") AND
_
(CriteriaMet([ME_SUBJECT],"*123*") OR _
CriteriaMet([ME_SUBJECT],"*456*")) AND _
CriteriaMet([ME_SIZE],123) Then
FilterResult=1
End If
End If
This script is similar to the one
above, with the exception of containing more comparisons.
Note: In the above example, the CriteriaMet([ME_SIZE],123)
line actually implicitly means that the message size is greater than 123 bytes.Reporting Matching Criteria
MailEnable logs a return result from
filters to the log file or as the [ME_CRITERIA] token replacement for actions.
For example, the action to add a header to an email can use the [ME_CRITERIA]
token which will be replaced with the string returned from the script. When not
using scripting for a filter, this return value is preset and cannot be
modified, but when a scripting filter is used the return value can be set within
the script. This is done by setting
the MEResultData variable within the script.
|
Example:
Setting the MEResultData variable within a scripted filter |
|
If
"%SUBJECT%" = "ABC" Then
MEResultData = "Subject matched ABC"
FilterResult=1 Else
If InStr(1,"%SUBJECT%","FRED") > 0 Then
MEResultData = "Subject contained Fred"
End If End
If |
If not using a scripted filter, then a
system-generated string is returned to denote which were the matching criteria.
An example string returned when a filter is matching the term 'Viagra' at
the beginning of the message subject follows:
CRITERIA=SUBJECT,
DATA=<MF-W>Viagra*</MF-W>
An extract from an example log file is
shown below. The filter column will show whether a scripted filter is being used
or not.
|
Time |
Action |
Message ID |
Connector |
Filter |
Result |
Account |
Sender |
IP Address |
Data |
|
08/21/06
21:42:15 |
Start |
- |
- |
- |
- |
- |
- |
- |
- |
|
08/21/06
21:42:31 |
Exec |
A.MAI |
SMTP |
Scripted |
ADD_HEADER, NOTIFY_SENDER |
|
[SMTP:user@mailenable.com] |
127.0.0.1 |
Subject
matched ABC |
|
08/21/06
21:43:37 |
Exec |
B.MAI |
SMTP |
Basic |
ADD_HEADER, NOTIFY_SENDER |
|
[SMTP:user@mailenable.com] |
127.0.0.1 |
CRITERIA=SUBJECT,
DATA=<MF-W>AB*</MF-W> |
This example shows messages A.MAI and
B.MAI being processed.
A.MAI was intercepted by a filter
called "Scripted" because the scripted filter reported that the subject
matched the term ABC.
B.MAI was intercepted by a filter
called "Basic" because the Subject of the message matched a criteria string
AB*. (Note: the <MF-W> mark-up around the term is used to indicate that
the term was sourced from word list criteria).