Go to the first, previous, next, last section, table of contents.


Testing a list of addresses

There is a facility for looping through a list of addresses and applying a condition to each of them. It takes the form


foranyaddress <string> (<condition>)

where <string> is interpreted as a list of RFC 822 addresses, as in a typical header line, and <condition> is any valid filter condition or combination of conditions. The parentheses surrounding the condition are mandatory, to delimit it from possible further sub-conditions of the enclosing `if' command. Within the condition, the expansion variable `$thisaddress' is set to the non-comment portion of each of the addresses in the string in turn. For example, if the string is


B.Simpson <bart@springfield.tv>, lisa@springfield.tv (his sister)

then `$thisaddress' would take on the values `bart@springfield.tv' and `lisa@springfield.tv' in turn.

If there are no valid addresses in the list, the whole condition is false. If the internal condition is true for any one address, the overall condition is true and the loop ends. If the internal condition is false for all addresses in the list, the overall condition is false. This example tests for the presence of an eight-digit local part in any address in a `To:' header:


  if foranyaddress $h_to ( $thisaddress matches ^\\d{8}@ ) then ...

Header lines can be joined together if a check is to be applied to more than one of them. For example:


  if foranyaddress $h_to:,$h_cc ....

Note that the colon that terminates a header name can be omitted only for the last name in cases like this, since RFC 822 header names are permitted to contain a wide range of characters, including commas.


Go to the first, previous, next, last section, table of contents.