File: filter_26.html

package info (click to toggle)
exim-html 3.20-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge, woody
  • size: 2,868 kB
  • ctags: 4,188
  • sloc: makefile: 40; sh: 19
file content (77 lines) | stat: -rw-r--r-- 3,053 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.52
     from filter on 25 November 2000 -->

<TITLE>Exim Filter Specification - Testing a list of addresses</TITLE>
</HEAD>
<body bgcolor="#FFFFFF" text="#00005A" link="#FF6600" alink="#FF9933" vlink="#990000">
Go to the <A HREF="filter_1.html">first</A>, <A HREF="filter_25.html">previous</A>, <A HREF="filter_27.html">next</A>, <A HREF="filter_34.html">last</A> section, <A HREF="filter_toc.html">table of contents</A>.
<P><HR><P>


<H2><A NAME="SEC26" HREF="filter_toc.html#TOC26">Testing a list of addresses</A></H2>

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

<PRE>
foranyaddress &#60;<EM>string</EM>&#62; (&#60;<EM>condition</EM>&#62;)
</PRE>

<P>
where &#60;<EM>string</EM>&#62; is interpreted as a list of RFC 822 addresses, as in a typical
header line, and &#60;<EM>condition</EM>&#62; 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 <EM>if</EM> command. Within
the condition, the expansion variable $<EM>thisaddress</EM> is set to the non-comment
portion of each of the addresses in the string in turn. For example, if the
string is

<PRE>
B.Simpson &#60;bart@springfield&#62;, lisa@springfield (his sister)
</PRE>

<P>
then $<EM>thisaddress</EM> would take on the values <TT>`bart@springfield'</TT> and
<TT>`lisa@springfield'</TT> in turn.

</P>
<P>
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 <EM>To:</EM> header:

<PRE>
if foranyaddress $h_to: ( $thisaddress matches ^\\d{8}@ ) then ...
</PRE>

<P>
When the overall condition is true, the value of $<EM>thisaddress</EM> in the
commands that follow <EM>then</EM> is the last value it took on inside the loop. At
the end of the <EM>if</EM> command, its value is reset to what it was before. It is
best to avoid the use of multiple occurrences of <EM>foranyaddress</EM>, nested or
otherwise, in a single <EM>if</EM> command, if the value of $<EM>thisaddress</EM> is to be
used afterwards, because it isn't always clear what the value will be. Nested
<EM>if</EM> commands should be used instead.

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

<PRE>
if foranyaddress $h_to:,$h_cc: ....
</PRE>

<P>
scans through the addresses in both the <EM>To:</EM> and the <EM>Cc:</EM> headers.

</P>
<P><HR><P>
Go to the <A HREF="filter_1.html">first</A>, <A HREF="filter_25.html">previous</A>, <A HREF="filter_27.html">next</A>, <A HREF="filter_34.html">last</A> section, <A HREF="filter_toc.html">table of contents</A>.
</BODY>
</HTML>