File: filter_20.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 (123 lines) | stat: -rw-r--r-- 4,449 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.52
     from filter on 25 November 2000 -->

<TITLE>Exim Filter Specification - String testing conditions</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_19.html">previous</A>, <A HREF="filter_21.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="SEC20" HREF="filter_toc.html#TOC20">String testing conditions</A></H2>

<P>
There are a number of conditions that operate on text strings, using the words
`begins', `ends', `is', `contains' and `matches'. If the condition names are
written in lower-case, the testing of letters is done without regard to case;
if they are written in upper-case (for example, `CONTAINS') then the case of
letters is significant.

<PRE>
     &#60;<EM>text1</EM>&#62; begins &#60;<EM>text2</EM>&#62;
     &#60;<EM>text1</EM>&#62; does not begin &#60;<EM>text2</EM>&#62;
e.g. $header_from: begins "Friend@"
</PRE>

<P>
A `begins' test checks for the presence of the second string at the start of
the first, both strings having been expanded.

<PRE>
     &#60;<EM>text1</EM>&#62; ends &#60;<EM>text2</EM>&#62;
     &#60;<EM>text1</EM>&#62; does not end &#60;<EM>text2</EM>&#62;
e.g. $header_from: ends "public.com"
</PRE>

<P>
An `ends' test checks for the presence of the second string at the end of
the first, both strings having been expanded.

<PRE>
     &#60;<EM>text1</EM>&#62; is &#60;<EM>text2</EM>&#62;
     &#60;<EM>text1</EM>&#62; is not &#60;<EM>text2</EM>&#62;
e.g. $local_part_suffix is "-foo"
</PRE>

<P>
An `is' test does an exact match between the strings, having first expanded
both strings.

<PRE>
     &#60;<EM>text1</EM>&#62; contains &#60;<EM>text2</EM>&#62;
     &#60;<EM>text1</EM>&#62; does not contain &#60;<EM>text2</EM>&#62;
e.g. $header_subject: contains "evolution"
</PRE>

<P>
A `contains' test does a partial string match, having expanded both strings.

<PRE>
     &#60;<EM>text1</EM>&#62; matches &#60;<EM>text2</EM>&#62;
     &#60;<EM>text2</EM>&#62; does not match &#60;<EM>text2</EM>&#62;
e.g. $sender_address matches "(Bill|John)@"
</PRE>

<P>
For a `matches' test, after expansion of both strings, the second one is
interpreted as a regular expression. Exim uses the PCRE regular expression
library, which provides regular expressions that are compatible with Perl.

</P>
<P>
Care must be taken if you need a backslash in a regular expression, because
backslashes are interpreted as escape characters both by the string expansion
code and by Exim's normal string reading code. For example, if you want to
test the sender address for a domain ending in <TT>`.com'</TT> the regular expression
is

<PRE>
\.com$
</PRE>

<P>
The backslash and dollar sign in that expression have to be escaped when used
in a filter command, as otherwise they would be interpreted by the expansion
code. Thus what you actually write is

<PRE>
if $sender_address matches \\.com\$
</PRE>

<P>
However, if the expression is given in quotes (mandatory only if it contains
white space) you have to write

<PRE>
if $sender_address matches "\\\\.com\\$"
</PRE>

<P>
with `\\\\' for a backslash and `\\$' for a dollar sign. Hence, if you
actually require the string `\$' in a regular expression that is given in
double quotes, you need to write `\\\\\\$'.

</P>
<P>
If the regular expression contains bracketed sub-expressions, then numeric
variable substitutions such as $<EM>1</EM> can be used in the subsequent actions
after a successful match. If the match fails, the values of the numeric
variables remain unchanged. Previous values are not restored after <TT>`endif'</TT> --
in other words, only one set of values is ever available. If the condition
contains several sub-conditions connected by <TT>`and'</TT> or <TT>`or'</TT>, it is the
strings extracted from the last successful match that are available in
subsequent actions. Numeric variables from any one sub-condition are also
available for use in subsequent sub-conditions, since string expansion of a
condition occurs just before it is tested.

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