Open topic with navigation

# Filter Messages using a Lua Script

You can configure the Exchange Connector to retrieve messages that have a specific set of properties. To retrieve messages that have specific properties, use the `MessageFilterLua` configuration parameter.

The `MessageFilterLua` parameter specifies the location of a Lua script to filter the messages in the repository.

The Lua script must include the following functions:

- The `requiredMapiProperties` function extracts message properties that you want to use for filtering the messages.
- The `filter` function compares the properties to one or more values and determines whether the message is retrieved. If `filter` returns `true`, the message is retrieved. If `filter` returns `false`, the message is ignored.

NOTE:

The message properties returned by the `requiredMapiProperties` function are returned as an array: `properties[MapiProperty][value]`.

Some properties have a single value, for example, the subject of an e-mail message would be returned as `properties[0x0037001E][1]`.

If a property has multiple values, these can be accessed as `properties[MapiProperty][2]`, `properties[MapiProperty][3]`, and so on.

## Example: Single Property

You could use the following script to retrieve messages sent to brian@example.com. All other messages are ignored.

    function requiredMapiProperties()
       return {0x0E04001F};
    end

    function filter(properties)
       return properties[0x0E04001F][1]=="brian@example.com";
    end

## Example: Multiple Properties

The following script demonstrates how to evaluate more than one property. This example retrieves all messages that were sent to one@autonomy.com or two@autonomy.com, and have the subject Important.

The `search` function searches every value of the specified property for acceptable strings. This means that messages sent to more than one recipient are retrieved, as long as one of the required addresses is found.

    function filter(properties)
       local addresses={ "one@autonomy.com" , "two@autonomy.com" }
       local subjects={ "Important" }

       local to=search(properties[0x0E04001F],addresses)
       local subject=search(properties[0x0037001E],subjects)

       local result = to and subject;
       return result;
    end

    function requiredMapiProperties()
       return {0x0E04001F,0x0037001E};
    end

    function search(property,values)
       for a,b in pairs(property) do
          for k,v in pairs(values) do
             if string.find(b,v)~=nil then
                return true;
             end
          end
       end

       return false;
    end

© 2018 Micro Focus or one of its affiliates | Send documentation feedback to Micro Focus Close Send documentation feedback To open the configured email client on this computer, open an email window. Otherwise, copy the information below to a web mail client, and send this email to swpdl.idoldocsfeedback@microfocus.com. We appreciate your feedback! Product: Topic Title: Help Topic: Feedback:

_FT_HTML5_bannerTitle.htm