The description of a condition in the chainmail configuration file consists of one more more primitive conditions joined by boolean operators and, or and not. Usual operator precedence applies. You may also use parentheses to change precedence.
Each primitive condition usually consists of a keyword — condition name — followed by zero, one or several quoted strings — condition parameters. Note that parameters must by double-quoted and separated by blanks. The only exception to this rule is expression condition, described last in this section.
Chainmail knows about the following primitive conditions:
Header "HeaderName" "HeaderRegex". This condition matches when the message has a header named "HeaderName" with value matching the regular expression "HeaderRegex"
Example:
Header "From" "@.*foobar.com"
BodyMatch "BodyRegex". This condition matches when message body matches the regular expression "BodyRegex".
Example:
BodyMatch "[Ll]ow [Rr]ate [Mm]ortgage"
EnvSender "Regex". This condition matches when the envelope sender of the message matches the regular expression "Regex".
Example:
EnvSender "postmaster@"
EnvRcpt "Regex". This condition matches when the envelope recipient of the message matches the regular expression "Regex".
Example:
EnvRcpt "root@"
Sender "Regex". This condition matches when either the envelope sender of the message or the address in the "From" header match the regular expression "Regex".
Example:
Sender "postmaster@"
Rcpt "Regex". This condition matches when either the envelope recipient of the message or any address in the "To", "Cc" and "Bcc" headers match the regular expression "Regex".
Example:
Rcpt "root@"
ClientAddr "Mask". This condition matches when the message is received from a host that has IP address matching the "Mask". The mask may be specified in any of the well-known formats for specifying IP address ranges, such as:
base_address/netmask, e.g. 1.2.3.4/255.255.0.0
base_address/number_of_network_bits, e.g. 1.2.3.4/16
prefix with trailing dot, e.g. 1.2.
Examples:
ClientAddr "1.2.3.4/255.255.255.0"
or
ClientAddr "1.2.3.4/16"
or
ClientAddr "1.2."
All the examples above match all IP addresses with first two bytes 1 and 2.
ClientName "Mask". This condition matches when the message is received from a host that has DNS name matching the "Mask". "Mask" may be either full domain name, or a a wildcard with a leading asterisk (see examples).
Examples:
ClientName "foo.com"
matches messages received from host foo.com
ClientName "*foo.com"
matches messages received from host foo.com or any host in domain foo.com.
Expression conditions. This kind of condition has a different syntax. It has the form:
value1 operator value2
where value1 and value2 are either double-quoted strings or Sendmail® macros specified (as in sendmail.cf) as ${macroname} and operator is either == for equality or != for inequality. Expression conditions allow you to select messages based on Sendmail® internal macro values. Refer to Sendmail® documentation for description of its macros. Note that not all macros can be available to milters; refer to libmilter documentation for more information.
Examples:
${daemon_name} == "MTA" ${j} != "mail.something.com"
Examples of comlex conditions, comprised of several primitive conditions:
The following matches when the message sender has address in the "customer.com" domain and recipient is not "support@mycompany.com"
Sender "@customer.com" and not Rcpt "support@mycompany.com"
The following matches when the message is received from a host in 192.168.1. subnet and the message subject contains the word "support" (with the first letter in upper- or lowercase) followed by the word "request".
ClientAddr "192.168.1." and Header "Subject" "[Ss]upport.*request"
The following matches when the recipient is not postmaster, and either message body contains the phrase "low rate mortgage" or message is received from a host in the (hypothetical) spam.com domain.
not Rcpt "postmaster@" and (BodyMatch "low rate mortgage" or ClientName "*.spam.com")