File: filter_32.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 (400 lines) | stat: -rw-r--r-- 9,693 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
<HTML>
<HEAD>
<!-- This HTML file has been created by texi2html 1.52
     from filter on 25 November 2000 -->

<TITLE>Exim Filter Specification - Expansion operators</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_31.html">previous</A>, <A HREF="filter_33.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="SEC32" HREF="filter_toc.html#TOC32">Expansion operators</A></H2>

<P>
<A NAME="IDX12"></A>
The following operations can be performed on portions of an expanded string.
The substring is first expanded before the operation is applied to it.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${domain:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
<A NAME="IDX13"></A>
The string is interpreted as an RFC 822 address and the domain is extracted
from it. If the string does not parse successfully, the result is empty.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${escape:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
If the string contains any non-printing characters, they are converted to
escape sequences starting with a backslash.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${expand:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
The <EM>expand</EM> operator causes a string to be expanded for a second time. For
example,

<PRE>
${expand:${lookup{$domain}dbm{/some/file}{$value}}}
</PRE>

<P>
first looks up a string in a file while expanding the operand for <EM>expand</EM>, and
then re-expands what it has found.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${hash_&#60;<EM>n</EM>&#62;_&#60;<EM>m</EM>&#62;:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
<A NAME="IDX14"></A>
The two items &#60;<EM>n</EM>&#62; and &#60;<EM>m</EM>&#62; are numbers. If &#60;<EM>n</EM>&#62; is greater than or equal to
the length of the string, the operator returns the string. Otherwise it
computes a new string of length &#60;<EM>n</EM>&#62; by applying a hashing function to the
string. The new string consists of characters taken from the first &#60;<EM>m</EM>&#62;
characters of the string

<PRE>
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQWRSTUVWXYZ0123456789
</PRE>

<P>
and if &#60;<EM>m</EM>&#62; is not present the value 26 is used, so that only lower case
letters appear. These examples:

<PRE>
${hash_3:monty}
${hash_5:monty}
${hash_4_62:monty python}
</PRE>

<P>
yield

<PRE>
jmg
monty
fbWx
</PRE>

<P>
respectively. The abbreviation <EM>h</EM> can be used instead of <EM>hash</EM>.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${nhash_&#60;<EM>n</EM>&#62;:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
<A NAME="IDX15"></A>
<A NAME="IDX16"></A>
The string is processed by a hash function which returns a numeric value in the
<font color=green>
range 0--&#60;<EM>n</EM>&#62;-1.
</font>

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${nhash_&#60;<EM>n</EM>&#62;_&#60;<EM>m</EM>&#62;:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
The string is processed by a div/mod hash function which returns two numbers,
separated by a slash, in the ranges
<font color=green>
0--&#60;<EM>n</EM>&#62;-1 and 0--&#60;<EM>m</EM>&#62;-1,
</font>
respectively. For example,

<PRE>
${nhash_8_64:supercalifragilisticexpialidocious}
</PRE>

<P>
returns the string `6/33'.

</P>

<P>
<A NAME="IDX17"></A>
<A NAME="IDX18"></A>
<A NAME="IDX19"></A>

</P>

<PRE>
<font color=blue>______________________________________________________________</font>

<b>${lc:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
This forces the letters in the string into lower-case, for example:

<PRE>
${lc:$local_part}
</PRE>

<P>
<A NAME="IDX20"></A>

</P>

<PRE>
<font color=blue>______________________________________________________________</font>

<b>${uc:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
This forces the letters in the string into upper-case.

</P>


<PRE>
<b>${length_&#60;<EM>number</EM>&#62;:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
The <EM>length</EM> operator can be used to extract the initial portion of a string.
It is followed by an underscore and the number of characters required. For
example

<PRE>
${length_50:$message_body}
</PRE>

<P>
The result of this operator is either the first &#60;<EM>number</EM>&#62; characters or the
whole string, whichever is the shorter. The abbreviation <EM>l</EM> can be used
instead of <EM>length</EM>.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${local_part:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
The string is interpreted as an RFC 822 address and the local part is extracted
from it. If the string does not parse successfully, the result is empty.

</P>


<PRE>
<b>${mask:&#60;<EM>IP address</EM>&#62;/&#60;<EM>bit count</EM>&#62;}</b>
</PRE>

<P>
<A NAME="IDX21"></A>
<A NAME="IDX22"></A>
If the form of the string to be operated on is not an IP address followed by a
slash and an integer, the expansion fails. Otherwise, this operator converts
the IP address to binary, masks off the least significant bits according to the
bit count, and converts the result back to text, with mask appended. For
example,

<PRE>
${mask:10.111.131.206/28}
</PRE>

<P>
returns the string `10.111.131.192/28'. Since this operation is expected to be
mostly used for looking up masked addresses in files, the result for an IPv6
address uses fullstops (periods) to separate components instead of colons,
because colon terminates a key string in lsearch files. So, for example,

<PRE>
${mask:5f03:1200:836f:0a00:000a:0800:200a:c031/99}
</PRE>

<P>
returns the string

<PRE>
5f03.1200.836f.0a00.000a.0800.2000.0000/99
</PRE>

<P>
Letters in IPv6 addresses are always output in lower case.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${quote:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
<A NAME="IDX23"></A>
The <EM>quote</EM> operator puts its argument into double quotes if it contains
anything other than letters, digits, underscores, full stops (periods), and
hyphens. Any occurrences of double quotes and backslashes are escaped with a
backslash. For example,

<PRE>
${quote:ab"*"cd}
</PRE>

<P>
becomes

<PRE>
"ab\"*\"cd"
</PRE>

<P>
The place where this is useful is when the argument is a substitution from a
variable or a message header.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${quote_&#60;<EM>lookup-type</EM>&#62;:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
<A NAME="IDX24"></A>
This operator applies lookup-specific quoting rules to the string. Each
query-style lookup type has its own quoting rules which are described with
the lookups in chapter . For example,

<PRE>
${quote_ldap:two + two}
</PRE>

<P>
returns `two%20%5C+%20two'. For single-key lookup types, no quoting is
necessary and this operator yields an unchanged string.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${rxquote:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
<A NAME="IDX25"></A>
<A NAME="IDX26"></A>
The <EM>rxquote</EM> operator inserts a backslash before any non-alphanumeric
characters in its argument. This is useful when substituting the values of
variables or headers inside regular expressions.

</P>


<PRE>
<font color=blue>______________________________________________________________</font>

<b>${substr_&#60;<EM>start</EM>&#62;_&#60;<EM>length</EM>&#62;:&#60;<EM>string</EM>&#62;}</b>
</PRE>

<P>
<A NAME="IDX27"></A>
<A NAME="IDX28"></A>
The <EM>substr</EM> operator can be used to extract more general substrings than
<EM>length</EM>. It is followed by an underscore and the starting offset, then a
second underscore and the length required. For example

<PRE>
${substr_3_2:$local_part}
</PRE>

<P>
If the starting offset is greater than the string length the result is the null
string; if the length plus starting offset is greater than the string length,
the result is the right-hand part of the string, starting from the given
offset. The first character in the string has offset zero. The abbreviation <EM>s</EM>
can be used instead of <EM>substr</EM>.

</P>
<P>
The <EM>substr</EM> expansion operator can take negative offset values to count
from the righthand end of its operand. The last character is offset -1, the
second-last is offset -2, and so on. Thus, for example,

<PRE>
${substr_-5_2:1234567}
</PRE>

<P>
yields `34'. If the absolute value of a negative offset is greater than the
length of the string, the substring starts at the beginning of the string, and
the length is reduced by the amount of overshoot. Thus, for example,

<PRE>
${substr_-5_2:12}
</PRE>

<P>
yields an empty string, but

<PRE>
${substr_-3_2:12}
</PRE>

<P>
yields `1'.

</P>
<P>
If the second number is omitted from <EM>substr</EM>, the remainder of the string is
taken if the offset was positive. If it was negative, all characters in the
string preceding the offset point are taken. For example, an offset of -1 and
no length yields all but the last character of the string.

</P>

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