MailEnable Enterprise Guide
Message Filtering / Scripted Filtering / Advanced Script Example
In This Topic
    Advanced Script Example
    In This Topic

    A more complicated example script for a filter is outlined below:

    Advanced Script Example
    Copy Code
    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 basic one, 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.

    Setting the MEResultData variable within a scripted filter
    Copy Code
    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).