6.7.4.6. Making complex decisions with the CombineMatcher

CombineMatcher uses the results of multiple matchers to make a decision. The results of the individual matchers can be combined using the logic operations AND, OR and NOT. Both existing matcher policies (Matcher policy) and policies defined only within the particular CombineMatcher (Matcher instance) can be used.

CombineMatcher

Figure 6.69. CombineMatcher

New matchers can be added with the Add button. Each line in the main window of the CombineMatcher configuration panel corresponds to a matcher. To use an existing matcher policy, set the combobox on the left to Matcher policy. After that, clicking the ... icon opens a dialog window where the matcher to be used can be selected.

Tip

Matchers can also be configured whenever needed: set the combobox to Matcher instance, click on the ... icon, and select and configure the matcher as required.

Each matcher can be taken into consideration either with its regular, or with its inverted result using the Not checkbox. The individual matchers (or their inverses) can be combined with the logical AND, and OR operations. This can be set in the Logic combobox:

  • If all criteria are met: It corresponds to the logical AND; the CombineMatcher will return the TRUE value only if all criteria are TRUE.

  • If any criteria are met: It corresponds to the logical OR; the CombineMatcher will return the TRUE value if at least one criteria is TRUE.

  • If all criteria are the same: CombineMatcher will return the TRUE value if all criteria have the same value (either TRUE or FALSE).

Tip

A CombineMatcher can also be used to combine the results of other CombineMatchers, thus very complex decisions can also be made.

Example 6.12. Blacklisting e-mail recipients

A simple use for CombineMatcher is to filter the recipients of e-mail addresses using the following process:

  1. An SmtpInvalidMatcher (called SmtpCheckrecipient) verifies that the recipient exists.

  2. A RegexpMatcher (called SmtpWhitelist) or RegexpFileMatcher is used to check if the address is on a predefined list. This list is either a whitelist (permitted addresses) or a blacklist (addresses to be rejected).

  3. A CombineMatcher (called SmtpCombineMatcher) sums up the results of the matchers with a logical AND operation (If all criteria are met). If the list of the RegexpMatcher is a blacklist, the result of the RegexpMatcher should be inverted by checking the Not checkbox.

  4. An SmtpProxy (called SmtpRecipientMatcherProxy) references SmtpCombineMatcher in its recipient_matcher attribute.

Python:
class SmtpRecipientMatcherProxy(SmtpProxy):
  recipient_matcher="SmtpCombineMatcher"
  def config(self):
    SmtpProxy.config(self)

MatcherPolicy(name="SmtpCombineMatcher", matcher=CombineMatcher\
(expr=(Z_AND, "SmtpCheckrecipient", "SmtpWhitelist")))
MatcherPolicy(name="SmtpWhitelist", matcher=RegexpMatcher\
(match_list=("info@example.com",), ignore_list=None))
MatcherPolicy(name="SmtpCheckrecipient", matcher=SmtpInvalidRecipientMatcher\
(server_port=25, cache_timeout=60, attempt_delivery=FALSE, \
force_delivery_attempt=FALSE, server_name="recipientcheck.example.com"))