Commit | Line | Data |
---|---|---|
420a0d19 CE |
1 | Exim's interfaces to mail filtering |
2 | ||
3 | Philip Hazel | |
4 | ||
5 | Copyright (c) 2014 University of Cambridge | |
6 | ||
7 | +-----------------------------------------------------------------------------+ | |
8 | +-------------------------------------+--------------------------------+------+ | |
9 | |Revision 4.84 |11 Aug 2014 |PH | | |
10 | +-------------------------------------+--------------------------------+------+ | |
11 | ------------------------------------------------------------------------------- | |
12 | ||
13 | TABLE OF CONTENTS | |
14 | ||
15 | 1. Forwarding and filtering in Exim | |
16 | ||
17 | 1.1. Introduction | |
18 | 1.2. Filter operation | |
19 | 1.3. Testing a new filter file | |
20 | 1.4. Installing a filter file | |
21 | 1.5. Testing an installed filter file | |
22 | 1.6. Details of filtering commands | |
23 | ||
24 | 2. Sieve filter files | |
25 | ||
26 | 2.1. Recognition of Sieve filters | |
27 | 2.2. Saving to specified folders | |
28 | 2.3. Strings containing header names | |
29 | 2.4. Exists test with empty list of headers | |
30 | 2.5. Header test with invalid MIME encoding in header | |
31 | 2.6. Address test for multiple addresses per header | |
32 | 2.7. Semantics of keep | |
33 | 2.8. Semantics of fileinto | |
34 | 2.9. Semantics of redirect | |
35 | 2.10. String arguments | |
36 | 2.11. Number units | |
37 | 2.12. RFC compliance | |
38 | ||
39 | 3. Exim filter files | |
40 | ||
41 | 3.1. Format of Exim filter files | |
42 | 3.2. Data values in filter commands | |
43 | 3.3. String expansion | |
44 | 3.4. Some useful general variables | |
45 | 3.5. Header variables | |
46 | 3.6. User variables | |
47 | 3.7. Current directory | |
48 | 3.8. Significant deliveries | |
49 | 3.9. Filter commands | |
50 | 3.10. The add command | |
51 | 3.11. The deliver command | |
52 | 3.12. The save command | |
53 | 3.13. The pipe command | |
54 | 3.14. Mail commands | |
55 | 3.15. Logging commands | |
56 | 3.16. The finish command | |
57 | 3.17. The testprint command | |
58 | 3.18. The fail command | |
59 | 3.19. The freeze command | |
60 | 3.20. The headers command | |
61 | 3.21. Obeying commands conditionally | |
62 | 3.22. String testing conditions | |
63 | 3.23. Numeric testing conditions | |
64 | 3.24. Testing for significant deliveries | |
65 | 3.25. Testing for error messages | |
66 | 3.26. Testing a list of addresses | |
67 | 3.27. Testing for personal mail | |
68 | 3.28. Alias addresses for the personal condition | |
69 | 3.29. Details of the personal condition | |
70 | 3.30. Testing delivery status | |
71 | 3.31. Multiple personal mailboxes | |
72 | 3.32. Ignoring delivery errors | |
73 | 3.33. Examples of Exim filter commands | |
74 | ||
75 | ||
76 | ||
77 | =============================================================================== | |
78 | 1. FORWARDING AND FILTERING IN EXIM | |
79 | ||
80 | This document describes the user interfaces to Exim's in-built mail filtering | |
81 | facilities, and is copyright (c) University of Cambridge 2014. It corresponds | |
82 | to Exim version 4.84. | |
83 | ||
84 | ||
85 | 1.1 Introduction | |
86 | ---------------- | |
87 | ||
88 | Most Unix mail transfer agents (programs that deliver mail) permit individual | |
89 | users to specify automatic forwarding of their mail, usually by placing a list | |
90 | of forwarding addresses in a file called .forward in their home directories. | |
91 | Exim extends this facility by allowing the forwarding instructions to be a set | |
92 | of rules rather than just a list of addresses, in effect providing ".forward | |
93 | with conditions". Operating the set of rules is called filtering, and the file | |
94 | that contains them is called a filter file. | |
95 | ||
96 | Exim supports two different kinds of filter file. An Exim filter contains | |
97 | instructions in a format that is unique to Exim. A Sieve filter contains | |
98 | instructions in the Sieve format that is defined by RFC 3028. As this is a | |
99 | standard format, Sieve filter files may already be familiar to some users. | |
100 | Sieve files should also be portable between different environments. However, | |
101 | the Exim filtering facility contains more features (such as variable | |
102 | expansion), and better integration with the host environment (such as the use | |
103 | of external processes and pipes). | |
104 | ||
105 | The choice of which kind of filter to use can be left to the end-user, provided | |
106 | that the system administrator has configured Exim appropriately for both kinds | |
107 | of filter. However, if interoperability is important, Sieve is the only choice. | |
108 | ||
109 | The ability to use filtering or traditional forwarding has to be enabled by the | |
110 | system administrator, and some of the individual facilities can be separately | |
111 | enabled or disabled. A local document should be provided to describe exactly | |
112 | what has been enabled. In the absence of this, consult your system | |
113 | administrator. | |
114 | ||
115 | This document describes how to use a filter file and the format of its | |
116 | contents. It is intended for use by end-users. Both Sieve filters and Exim | |
117 | filters are covered. However, for Sieve filters, only issues that relate to the | |
118 | Exim implementation are discussed, since Sieve itself is described elsewhere. | |
119 | ||
120 | The contents of traditional .forward files are not described here. They | |
121 | normally contain just a list of addresses, file names, or pipe commands, | |
122 | separated by commas or newlines, but other types of item are also available. | |
123 | The full details can be found in the chapter on the redirect router in the Exim | |
124 | specification, which also describes how the system administrator can set up and | |
125 | control the use of filtering. | |
126 | ||
127 | ||
128 | 1.2 Filter operation | |
129 | -------------------- | |
130 | ||
131 | It is important to realize that, in Exim, no deliveries are actually made while | |
132 | a filter or traditional .forward file is being processed. Running a filter or | |
133 | processing a traditional .forward file sets up future delivery operations, but | |
134 | does not carry them out. | |
135 | ||
136 | The result of filter or .forward file processing is a list of destinations to | |
137 | which a message should be delivered. The deliveries themselves take place | |
138 | later, along with all other deliveries for the message. This means that it is | |
139 | not possible to test for successful deliveries while filtering. It also means | |
140 | that any duplicate addresses that are generated are dropped, because Exim never | |
141 | delivers the same message to the same address more than once. | |
142 | ||
143 | ||
144 | 1.3 Testing a new filter file | |
145 | ----------------------------- | |
146 | ||
147 | Filter files, especially the more complicated ones, should always be tested, as | |
148 | it is easy to make mistakes. Exim provides a facility for preliminary testing | |
149 | of a filter file before installing it. This tests the syntax of the file and | |
150 | its basic operation, and can also be used with traditional .forward files. | |
151 | ||
152 | Because a filter can do tests on the content of messages, a test message is | |
153 | required. Suppose you have a new filter file called myfilter and a test message | |
154 | in a file called test-message. Assuming that Exim is installed with the | |
155 | conventional path name /usr/sbin/sendmail (some operating systems use /usr/lib/ | |
156 | sendmail), the following command can be used: | |
157 | ||
158 | /usr/sbin/sendmail -bf myfilter <test-message | |
159 | ||
160 | The -bf option tells Exim that the following item on the command line is the | |
161 | name of a filter file that is to be tested. There is also a -bF option, which | |
162 | is similar, but which is used for testing system filter files, as opposed to | |
163 | user filter files, and which is therefore of use only to the system | |
164 | administrator. | |
165 | ||
166 | The test message is supplied on the standard input. If there are no | |
167 | message-dependent tests in the filter, an empty file (/dev/null) can be used. A | |
168 | supplied message must start with header lines or the "From " message separator | |
169 | line that is found in many multi-message folder files. Note that blank lines at | |
170 | the start terminate the header lines. A warning is given if no header lines are | |
171 | read. | |
172 | ||
173 | The result of running this command, provided no errors are detected in the | |
174 | filter file, is a list of the actions that Exim would try to take if presented | |
175 | with the message for real. For example, for an Exim filter, the output | |
176 | ||
177 | Deliver message to: gulliver@lilliput.fict.example | |
178 | Save message to: /home/lemuel/mail/archive | |
179 | ||
180 | means that one copy of the message would be sent to | |
181 | gulliver@lilliput.fict.example, and another would be added to the file /home/ | |
182 | lemuel/mail/archive, if all went well. | |
183 | ||
184 | The actions themselves are not attempted while testing a filter file in this | |
185 | way; there is no check, for example, that any forwarding addresses are valid. | |
186 | For an Exim filter, if you want to know why a particular action is being taken, | |
187 | add the -v option to the command. This causes Exim to output the results of any | |
188 | conditional tests and to indent its output according to the depth of nesting of | |
189 | if commands. Further additional output from a filter test can be generated by | |
190 | the testprint command, which is described below. | |
191 | ||
192 | When Exim is outputting a list of the actions it would take, if any text | |
193 | strings are included in the output, non-printing characters therein are | |
194 | converted to escape sequences. In particular, if any text string contains a | |
195 | newline character, this is shown as "\n" in the testing output. | |
196 | ||
197 | When testing a filter in this way, Exim makes up an "envelope" for the message. | |
198 | The recipient is by default the user running the command, and so is the sender, | |
199 | but the command can be run with the -f option to supply a different sender. For | |
200 | example, | |
201 | ||
202 | /usr/sbin/sendmail -bf myfilter \ | |
203 | -f islington@never.where <test-message | |
204 | ||
205 | Alternatively, if the -f option is not used, but the first line of the supplied | |
206 | message is a "From " separator from a message folder file (not the same thing | |
207 | as a From: header line), the sender is taken from there. If -f is present, the | |
208 | contents of any "From " line are ignored. | |
209 | ||
210 | The "return path" is the same as the envelope sender, unless the message | |
211 | contains a Return-path: header, in which case it is taken from there. You need | |
212 | not worry about any of this unless you want to test out features of a filter | |
213 | file that rely on the sender address or the return path. | |
214 | ||
215 | It is possible to change the envelope recipient by specifying further options. | |
216 | The -bfd option changes the domain of the recipient address, while the -bfl | |
217 | option changes the "local part", that is, the part before the @ sign. An | |
218 | adviser could make use of these to test someone else's filter file. | |
219 | ||
220 | The -bfp and -bfs options specify the prefix or suffix for the local part. | |
221 | These are relevant only when support for multiple personal mailboxes is | |
222 | implemented; see the description in section 3.31 below. | |
223 | ||
224 | ||
225 | 1.4 Installing a filter file | |
226 | ---------------------------- | |
227 | ||
228 | A filter file is normally installed under the name .forward in your home | |
229 | directory - it is distinguished from a conventional .forward file by its first | |
230 | line (described below). However, the file name is configurable, and some system | |
231 | administrators may choose to use some different name or location for filter | |
232 | files. | |
233 | ||
234 | ||
235 | 1.5 Testing an installed filter file | |
236 | ------------------------------------ | |
237 | ||
238 | Testing a filter file before installation cannot find every potential problem; | |
239 | for example, it does not actually run commands to which messages are piped. | |
240 | Some "live" tests should therefore also be done once a filter is installed. | |
241 | ||
242 | If at all possible, test your filter file by sending messages from some other | |
243 | account. If you send a message to yourself from the filtered account, and | |
244 | delivery fails, the error message will be sent back to the same account, which | |
245 | may cause another delivery failure. It won't cause an infinite sequence of such | |
246 | messages, because delivery failure messages do not themselves generate further | |
247 | messages. However, it does mean that the failure won't be returned to you, and | |
248 | also that the postmaster will have to investigate the stuck message. | |
249 | ||
250 | If you have to test an Exim filter from the same account, a sensible precaution | |
251 | is to include the line | |
252 | ||
253 | if error_message then finish endif | |
254 | ||
255 | as the first filter command, at least while testing. This causes filtering to | |
256 | be abandoned for a delivery failure message, and since no destinations are | |
257 | generated, the message goes on to be delivered to the original address. Unless | |
258 | there is a good reason for not doing so, it is recommended that the above test | |
259 | be left in all Exim filter files. (This does not apply to Sieve files.) | |
260 | ||
261 | ||
262 | 1.6 Details of filtering commands | |
263 | --------------------------------- | |
264 | ||
265 | The filtering commands for Sieve and Exim filters are completely different in | |
266 | syntax and semantics. The Sieve mechanism is defined in RFC 3028; in the next | |
267 | chapter we describe how it is integrated into Exim. The subsequent chapter | |
268 | covers Exim filtering commands in detail. | |
269 | ||
270 | ||
271 | ||
272 | =============================================================================== | |
273 | 2. SIEVE FILTER FILES | |
274 | ||
275 | The code for Sieve filtering in Exim was contributed by Michael Haardt, and | |
276 | most of the content of this chapter is taken from the notes he provided. Since | |
277 | Sieve is an extensible language, it is important to understand "Sieve" in this | |
278 | context as "the specific implementation of Sieve for Exim". | |
279 | ||
280 | This chapter does not contain a description of Sieve, since that can be found | |
281 | in RFC 3028, which should be read in conjunction with these notes. | |
282 | ||
283 | The Exim Sieve implementation offers the core as defined by RFC 3028, | |
284 | comparison tests, the subaddress parameter, the copy, envelope, fileinto, | |
285 | notify, and vacation extensions, but not the reject extension. Exim does not | |
286 | support message delivery notifications (MDNs), so adding it just to the Sieve | |
287 | filter (as required for reject) makes little sense. | |
288 | ||
289 | In order for Sieve to work properly in Exim, the system administrator needs to | |
290 | make some adjustments to the Exim configuration. These are described in the | |
291 | chapter on the redirect router in the full Exim specification. | |
292 | ||
293 | ||
294 | 2.1 Recognition of Sieve filters | |
295 | -------------------------------- | |
296 | ||
297 | A filter file is interpreted as a Sieve filter if its first line is | |
298 | ||
299 | # Sieve filter | |
300 | ||
301 | This is what distinguishes it from a conventional .forward file or an Exim | |
302 | filter file. | |
303 | ||
304 | ||
305 | 2.2 Saving to specified folders | |
306 | ------------------------------- | |
307 | ||
308 | If the system administrator has set things up as suggested in the Exim | |
309 | specification, and you use keep or fileinto to save a mail into a folder, | |
310 | absolute files are stored where specified, relative files are stored relative | |
311 | to $home, and inbox goes to the standard mailbox location. | |
312 | ||
313 | ||
314 | 2.3 Strings containing header names | |
315 | ----------------------------------- | |
316 | ||
317 | RFC 3028 does not specify what happens if a string denoting a header field does | |
318 | not contain a valid header name, for example, it contains a colon. This | |
319 | implementation generates an error instead of ignoring the header field in order | |
320 | to ease script debugging, which fits in with the common picture of Sieve. | |
321 | ||
322 | ||
323 | 2.4 Exists test with empty list of headers | |
324 | ------------------------------------------ | |
325 | ||
326 | The exists test succeeds only if all the specified headers exist. RFC 3028 does | |
327 | not explicitly specify what happens on an empty list of headers. This | |
328 | implementation evaluates that condition as true, interpreting the RFC in a | |
329 | strict sense. | |
330 | ||
331 | ||
332 | 2.5 Header test with invalid MIME encoding in header | |
333 | ---------------------------------------------------- | |
334 | ||
335 | Some MUAs process invalid base64 encoded data, generating junk. Others ignore | |
336 | junk after seeing an equal sign in base64 encoded data. RFC 2047 does not | |
337 | specify how to react in this case, other than stating that a client must not | |
338 | forbid to process a message for that reason. RFC 2045 specifies that invalid | |
339 | data should be ignored (apparently looking at end of line characters). It also | |
340 | specifies that invalid data may lead to rejecting messages containing them (and | |
341 | there it appears to talk about true encoding violations), which is a clear | |
342 | contradiction to ignoring them. | |
343 | ||
344 | RFC 3028 does not specify how to process incorrect MIME words. This | |
345 | implementation treats them literally, as it does if the word is correct but its | |
346 | character set cannot be converted to UTF-8. | |
347 | ||
348 | ||
349 | 2.6 Address test for multiple addresses per header | |
350 | -------------------------------------------------- | |
351 | ||
352 | A header may contain multiple addresses. RFC 3028 does not explicitly specify | |
353 | how to deal with them, but since the address test checks if anything matches | |
354 | anything else, matching one address suffices to satisfy the condition. That | |
355 | makes it impossible to test if a header contains a certain set of addresses and | |
356 | no more, but it is more logical than letting the test fail if the header | |
357 | contains an additional address besides the one the test checks for. | |
358 | ||
359 | ||
360 | 2.7 Semantics of keep | |
361 | --------------------- | |
362 | ||
363 | The keep command is equivalent to | |
364 | ||
365 | fileinto "inbox"; | |
366 | ||
367 | It saves the message and resets the implicit keep flag. It does not set the | |
368 | implicit keep flag; there is no command to set it once it has been reset. | |
369 | ||
370 | ||
371 | 2.8 Semantics of fileinto | |
372 | ------------------------- | |
373 | ||
374 | RFC 3028 does not specify whether fileinto should try to create a mail folder | |
375 | if it does not exist. This implementation allows the sysadmin to configure that | |
376 | aspect using the appendfile transport options create_directory, create_file, | |
377 | and file_must_exist. See the appendfile transport in the Exim specification for | |
378 | details. | |
379 | ||
380 | ||
381 | 2.9 Semantics of redirect | |
382 | ------------------------- | |
383 | ||
384 | Sieve scripts are supposed to be interoperable between servers, so this | |
385 | implementation does not allow mail to be redirected to unqualified addresses, | |
386 | because the domain would depend on the system being used. On systems with | |
387 | virtual mail domains, the default domain is probably not what the user expects | |
388 | it to be. | |
389 | ||
390 | ||
391 | 2.10 String arguments | |
392 | --------------------- | |
393 | ||
394 | There has been confusion if the string arguments to require are to be matched | |
395 | case-sensitively or not. This implementation matches them with the match type | |
396 | :is (default, see section 2.7.1 of the RFC) and the comparator i;ascii-casemap | |
397 | (default, see section 2.7.3 of the RFC). The RFC defines the command defaults | |
398 | clearly, so any different implementations violate RFC 3028. The same is valid | |
399 | for comparator names, also specified as strings. | |
400 | ||
401 | ||
402 | 2.11 Number units | |
403 | ----------------- | |
404 | ||
405 | There is a mistake in RFC 3028: the suffix G denotes gibi-, not tebibyte. The | |
406 | mistake is obvious, because RFC 3028 specifies G to denote 2^30 (which is gibi, | |
407 | not tebi), and that is what this implementation uses as the scaling factor for | |
408 | the suffix G. | |
409 | ||
410 | ||
411 | 2.12 RFC compliance | |
412 | ------------------- | |
413 | ||
414 | Exim requires the first line of a Sieve filter to be | |
415 | ||
416 | # Sieve filter | |
417 | ||
418 | Of course the RFC does not specify that line. Do not expect examples to work | |
419 | without adding it, though. | |
420 | ||
421 | RFC 3028 requires the use of CRLF to terminate a line. The rationale was that | |
422 | CRLF is universally used in network protocols to mark the end of the line. This | |
423 | implementation does not embed Sieve in a network protocol, but uses Sieve | |
424 | scripts as part of the Exim MTA. Since all parts of Exim use LF as the newline | |
425 | character, this implementation does, too, by default, though the system | |
426 | administrator may choose (at Exim compile time) to use CRLF instead. | |
427 | ||
428 | Exim violates RFC 2822, section 3.6.8, by accepting 8-bit header names, so this | |
429 | implementation repeats this violation to stay consistent with Exim. This is in | |
430 | preparation for UTF-8 data. | |
431 | ||
432 | Sieve scripts cannot contain NUL characters in strings, but mail headers could | |
433 | contain MIME encoded NUL characters, which could never be matched by Sieve | |
434 | scripts using exact comparisons. For that reason, this implementation extends | |
435 | the Sieve quoted string syntax with \0 to describe a NUL character, violating \ | |
436 | 0 being the same as 0 in RFC 3028. Even without using \0, the following tests | |
437 | are all true in this implementation. Implementations that use C-style strings | |
438 | will only evaluate the first test as true. | |
439 | ||
440 | Subject: =?iso-8859-1?q?abc=00def | |
441 | ||
442 | header :contains "Subject" ["abc"] | |
443 | header :contains "Subject" ["def"] | |
444 | header :matches "Subject" ["abc?def"] | |
445 | ||
446 | Note that by considering Sieve to be an MUA, RFC 2047 can be interpreted in a | |
447 | way that NUL characters truncating strings is allowed for Sieve | |
448 | implementations, although not recommended. It is further allowed to use encoded | |
449 | NUL characters in headers, but that's not recommended either. The above example | |
450 | shows why. | |
451 | ||
452 | RFC 3028 states that if an implementation fails to convert a character set to | |
453 | UTF-8, two strings cannot be equal if one contains octets greater than 127. | |
454 | Assuming that all unknown character sets are one-byte character sets with the | |
455 | lower 128 octets being US-ASCII is not sound, so this implementation violates | |
456 | RFC 3028 and treats such MIME words literally. That way at least something | |
457 | could be matched. | |
458 | ||
459 | The folder specified by fileinto must not contain the character sequence ".." | |
460 | to avoid security problems. RFC 3028 does not specify the syntax of folders | |
461 | apart from keep being equivalent to | |
462 | ||
463 | fileinto "INBOX"; | |
464 | ||
465 | This implementation uses inbox instead. | |
466 | ||
467 | Sieve script errors currently cause messages to be silently filed into inbox. | |
468 | RFC 3028 requires that the user is notified of that condition. This may be | |
469 | implemented in the future by adding a header line to mails that are filed into | |
470 | inbox due to an error in the filter. | |
471 | ||
472 | ||
473 | ||
474 | =============================================================================== | |
475 | 3. EXIM FILTER FILES | |
476 | ||
477 | This chapter contains a full description of the contents of Exim filter files. | |
478 | ||
479 | ||
480 | 3.1 Format of Exim filter files | |
481 | ------------------------------- | |
482 | ||
483 | Apart from leading white space, the first text in an Exim filter file must be | |
484 | ||
485 | # Exim filter | |
486 | ||
487 | This is what distinguishes it from a conventional .forward file or a Sieve | |
488 | filter file. If the file does not have this initial line (or the equivalent for | |
489 | a Sieve filter), it is treated as a conventional .forward file, both when | |
490 | delivering mail and when using the -bf testing mechanism. The white space in | |
491 | the line is optional, and any capitalization may be used. Further text on the | |
492 | same line is treated as a comment. For example, you could have | |
493 | ||
494 | # Exim filter <<== do not edit or remove this line! | |
495 | ||
496 | The remainder of the file is a sequence of filtering commands, which consist of | |
497 | keywords and data values. For example, in the command | |
498 | ||
499 | deliver gulliver@lilliput.fict.example | |
500 | ||
501 | the keyword is "deliver" and the data value is | |
502 | "gulliver@lilliput.fict.example". White space or line breaks separate the | |
503 | components of a command, except in the case of conditions for the if command, | |
504 | where round brackets (parentheses) also act as separators. Complete commands | |
505 | are separated from each other by white space or line breaks; there are no | |
506 | special terminators. Thus, several commands may appear on one line, or one | |
507 | command may be spread over a number of lines. | |
508 | ||
509 | If the character # follows a separator anywhere in a command, everything from # | |
510 | up to the next newline is ignored. This provides a way of including comments in | |
511 | a filter file. | |
512 | ||
513 | ||
514 | 3.2 Data values in filter commands | |
515 | ---------------------------------- | |
516 | ||
517 | There are two ways in which a data value can be input: | |
518 | ||
519 | * If the text contains no white space, it can be typed verbatim. However, if | |
520 | it is part of a condition, it must also be free of round brackets | |
521 | (parentheses), as these are used for grouping in conditions. | |
522 | ||
523 | * Otherwise, text must be enclosed in double quotation marks. In this case, | |
524 | the character \ (backslash) is treated as an "escape character" within the | |
525 | string, causing the following character or characters to be treated | |
526 | specially: | |
527 | ||
528 | \n is replaced by a newline | |
529 | \r is replaced by a carriage return | |
530 | \t is replaced by a tab | |
531 | ||
532 | Backslash followed by up to three octal digits is replaced by the character | |
533 | specified by those digits, and "\x" followed by up to two hexadecimal digits is | |
534 | treated similarly. Backslash followed by any other character is replaced by the | |
535 | second character, so that in particular, "\"" becomes """ and "\\" becomes "\". | |
536 | A data item enclosed in double quotes can be continued onto the next line by | |
537 | ending the first line with a backslash. Any leading white space at the start of | |
538 | the continuation line is ignored. | |
539 | ||
540 | In addition to the escape character processing that occurs when strings are | |
541 | enclosed in quotes, most data values are also subject to string expansion (as | |
542 | described in the next section), in which case the characters "$" and "\" are | |
543 | also significant. This means that if a single backslash is actually required in | |
544 | such a string, and the string is also quoted, "\\\\" has to be entered. | |
545 | ||
546 | The maximum permitted length of a data string, before expansion, is 1024 | |
547 | characters. | |
548 | ||
549 | ||
550 | 3.3 String expansion | |
551 | -------------------- | |
552 | ||
553 | Most data values are expanded before use. Expansion consists of replacing | |
554 | substrings beginning with "$" with other text. The full expansion facilities | |
555 | available in Exim are extensive. If you want to know everything that Exim can | |
556 | do with strings, you should consult the chapter on string expansion in the Exim | |
557 | documentation. | |
558 | ||
559 | In filter files, by far the most common use of string expansion is the | |
560 | substitution of the contents of a variable. For example, the substring | |
561 | ||
562 | $reply_address | |
563 | ||
564 | is replaced by the address to which replies to the message should be sent. If | |
565 | such a variable name is followed by a letter or digit or underscore, it must be | |
566 | enclosed in curly brackets (braces), for example, | |
567 | ||
568 | ${reply_address} | |
569 | ||
570 | If a "$" character is actually required in an expanded string, it must be | |
571 | escaped with a backslash, and because backslash is also an escape character in | |
572 | quoted input strings, it must be doubled in that case. The following two | |
573 | examples illustrate two different ways of testing for a "$" character in a | |
574 | message: | |
575 | ||
576 | if $message_body contains \$ then ... | |
577 | if $message_body contains "\\$" then ... | |
578 | ||
579 | You can prevent part of a string from being expanded by enclosing it between | |
580 | two occurrences of "\N". For example, | |
581 | ||
582 | if $message_body contains \N$$$$\N then ... | |
583 | ||
584 | tests for a run of four dollar characters. | |
585 | ||
586 | ||
587 | 3.4 Some useful general variables | |
588 | --------------------------------- | |
589 | ||
590 | A complete list of the available variables is given in the Exim documentation. | |
591 | This shortened list contains the ones that are most likely to be useful in | |
592 | personal filter files: | |
593 | ||
594 | $body_linecount: The number of lines in the body of the message. | |
595 | ||
596 | $body_zerocount: The number of binary zero characters in the body of the | |
597 | message. | |
598 | ||
599 | $home: In conventional configurations, this variable normally contains the | |
600 | user's home directory. The system administrator can, however, change this. | |
601 | ||
602 | $local_part: The part of the email address that precedes the @ sign - normally | |
603 | the user's login name. If support for multiple personal mailboxes is enabled | |
604 | (see section 3.31 below) and a prefix or suffix for the local part was | |
605 | recognized, it is removed from the string in this variable. | |
606 | ||
607 | $local_part_prefix: If support for multiple personal mailboxes is enabled (see | |
608 | section 3.31 below), and a local part prefix was recognized, this variable | |
609 | contains the prefix. Otherwise it contains an empty string. | |
610 | ||
611 | $local_part_suffix: If support for multiple personal mailboxes is enabled (see | |
612 | section 3.31 below), and a local part suffix was recognized, this variable | |
613 | contains the suffix. Otherwise it contains an empty string. | |
614 | ||
615 | $message_body: The initial portion of the body of the message. By default, up | |
616 | to 500 characters are read into this variable, but the system administrator can | |
617 | configure this to some other value. Newlines in the body are converted into | |
618 | single spaces. | |
619 | ||
620 | $message_body_end: The final portion of the body of the message, formatted and | |
621 | limited in the same way as $message_body. | |
622 | ||
623 | $message_body_size: The size of the body of the message, in bytes. | |
624 | ||
625 | $message_exim_id: The message's local identification string, which is unique | |
626 | for each message handled by a single host. | |
627 | ||
628 | $message_headers: The header lines of the message, concatenated into a single | |
629 | string, with newline characters between them. | |
630 | ||
631 | $message_size: The size of the entire message, in bytes. | |
632 | ||
633 | $original_local_part: When an address that arrived with the message is being | |
634 | processed, this contains the same value as the variable $local_part. However, | |
635 | if an address generated by an alias, forward, or filter file is being | |
636 | processed, this variable contains the local part of the original address. | |
637 | ||
638 | $reply_address: The contents of the Reply-to: header, if the message has one; | |
639 | otherwise the contents of the From: header. It is the address to which normal | |
640 | replies to the message should be sent. | |
641 | ||
642 | $return_path: The return path - that is, the sender field that will be | |
643 | transmitted as part of the message's envelope if the message is sent to another | |
644 | host. This is the address to which delivery errors are sent. In many cases, | |
645 | this variable has the same value as $sender_address, but if, for example, an | |
646 | incoming message to a mailing list has been expanded, $return_path may have | |
647 | been changed to contain the address of the list maintainer. | |
648 | ||
649 | $sender_address: The sender address that was received in the envelope of the | |
650 | message. This is not necessarily the same as the contents of the From: or | |
651 | Sender: header lines. For delivery error messages ("bounce messages") there is | |
652 | no sender address, and this variable is empty. | |
653 | ||
654 | $tod_full: A full version of the time and date, for example: Wed, 18 Oct 1995 | |
655 | 09:51:40 +0100. The timezone is always given as a numerical offset from GMT. | |
656 | ||
657 | $tod_log: The time and date in the format used for writing Exim's log files, | |
658 | without the timezone, for example: 1995-10-12 15:32:29. | |
659 | ||
660 | $tod_zone: The local timezone offset, for example: +0100. | |
661 | ||
662 | ||
663 | 3.5 Header variables | |
664 | -------------------- | |
665 | ||
666 | There is a special set of expansion variables containing the header lines of | |
667 | the message being processed. These variables have names beginning with $header_ | |
668 | followed by the name of the header line, terminated by a colon. For example, | |
669 | ||
670 | $header_from: | |
671 | $header_subject: | |
672 | ||
673 | The whole item, including the terminating colon, is replaced by the contents of | |
674 | the message header line. If there is more than one header line with the same | |
675 | name, their contents are concatenated. For header lines whose data consists of | |
676 | a list of addresses (for example, From: and To:), a comma and newline is | |
677 | inserted between each set of data. For all other header lines, just a newline | |
678 | is used. | |
679 | ||
680 | Leading and trailing white space is removed from header line data, and if there | |
681 | are any MIME "words" that are encoded as defined by RFC 2047 (because they | |
682 | contain non-ASCII characters), they are decoded and translated, if possible, to | |
683 | a local character set. Translation is attempted only on operating systems that | |
684 | have the iconv() function. This makes the header line look the same as it would | |
685 | when displayed by an MUA. The default character set is ISO-8859-1, but this can | |
686 | be changed by means of the headers command (see below). | |
687 | ||
688 | If you want to see the actual characters that make up a header line, you can | |
689 | specify $rheader_ instead of $header_. This inserts the "raw" header line, | |
690 | unmodified. | |
691 | ||
692 | There is also an intermediate form, requested by $bheader_, which removes | |
693 | leading and trailing space and decodes MIME "words", but does not do any | |
694 | character translation. If an attempt to decode what looks superficially like a | |
695 | MIME "word" fails, the raw string is returned. If decoding produces a binary | |
696 | zero character, it is replaced by a question mark. | |
697 | ||
698 | The capitalization of the name following $header_ is not significant. Because | |
699 | any printing character except colon may appear in the name of a message's | |
700 | header (this is a requirement of RFC 2822, the document that describes the | |
701 | format of a mail message) curly brackets must not be used in this case, as they | |
702 | will be taken as part of the header name. Two shortcuts are allowed in naming | |
703 | header variables: | |
704 | ||
705 | * The initiating $header_, $rheader_, or $bheader_ can be abbreviated to $h_, | |
706 | $rh_, or $bh_, respectively. | |
707 | ||
708 | * The terminating colon can be omitted if the next character is white space. | |
709 | The white space character is retained in the expanded string. However, this | |
710 | is not recommended, because it makes it easy to forget the colon when it | |
711 | really is needed. | |
712 | ||
713 | If the message does not contain a header of the given name, an empty string is | |
714 | substituted. Thus it is important to spell the names of headers correctly. Do | |
715 | not use $header_Reply_to when you really mean $header_Reply-to. | |
716 | ||
717 | ||
718 | 3.6 User variables | |
719 | ------------------ | |
720 | ||
721 | There are ten user variables with names $n0 - $n9 that can be incremented by | |
722 | the add command (see section 3.10). These can be used for "scoring" messages in | |
723 | various ways. If Exim is configured to run a "system filter" on every message, | |
724 | the values left in these variables are copied into the variables $sn0 - $sn9 at | |
725 | the end of the system filter, thus making them available to users' filter | |
726 | files. How these values are used is entirely up to the individual installation. | |
727 | ||
728 | ||
729 | 3.7 Current directory | |
730 | --------------------- | |
731 | ||
732 | The contents of your filter file should not make any assumptions about the | |
733 | current directory. It is best to use absolute paths for file names; you can | |
734 | normally make use of the $home variable to refer to your home directory. The | |
735 | save command automatically inserts $home at the start of non-absolute paths. | |
736 | ||
737 | ||
738 | 3.8 Significant deliveries | |
739 | -------------------------- | |
740 | ||
741 | When in the course of delivery a message is processed by a filter file, what | |
742 | happens next, that is, after the filter file has been processed, depends on | |
743 | whether or not the filter sets up any significant deliveries. If at least one | |
744 | significant delivery is set up, the filter is considered to have handled the | |
745 | entire delivery arrangements for the current address, and no further processing | |
746 | of the address takes place. If, however, no significant deliveries are set up, | |
747 | Exim continues processing the current address as if there were no filter file, | |
748 | and typically sets up a delivery of a copy of the message into a local mailbox. | |
749 | In particular, this happens in the special case of a filter file containing | |
750 | only comments. | |
751 | ||
752 | The delivery commands deliver, save, and pipe are by default significant. | |
753 | However, if such a command is preceded by the word "unseen", its delivery is | |
754 | not considered to be significant. In contrast, other commands such as mail and | |
755 | vacation do not set up significant deliveries unless preceded by the word | |
756 | "seen". The following example commands set up significant deliveries: | |
757 | ||
758 | deliver jack@beanstalk.example | |
759 | pipe $home/bin/mymailscript | |
760 | seen mail subject "message discarded" | |
761 | seen finish | |
762 | ||
763 | The following example commands do not set up significant deliveries: | |
764 | ||
765 | unseen deliver jack@beanstalk.example | |
766 | unseen pipe $home/bin/mymailscript | |
767 | mail subject "message discarded" | |
768 | finish | |
769 | ||
770 | ||
771 | 3.9 Filter commands | |
772 | ------------------- | |
773 | ||
774 | The filter commands that are described in subsequent sections are listed below, | |
775 | with the section in which they are described in brackets: | |
776 | ||
777 | add increment a user variable (section 3.10) | |
778 | deliver deliver to an email address (section 3.11) | |
779 | fail force delivery failure (sysadmin use) (section 3.18) | |
780 | finish end processing (section 3.16) | |
781 | freeze freeze message (sysadmin use) (section 3.19) | |
782 | headers set the header character set (section 3.20) | |
783 | if test condition(s) (section 3.21) | |
784 | logfile define log file (section 3.15) | |
785 | logwrite write to log file (section 3.15) | |
786 | mail send a reply message (section 3.14) | |
787 | pipe pipe to a command (section 3.13) | |
788 | save save to a file (section 3.12) | |
789 | testprint print while testing (section 3.17) | |
790 | vacation tailored form of mail (section 3.14) | |
791 | ||
792 | The headers command has additional parameters that can be used only in a system | |
793 | filter. The fail and freeze commands are available only when Exim's filtering | |
794 | facilities are being used as a system filter, and are therefore usable only by | |
795 | the system administrator and not by ordinary users. They are mentioned only | |
796 | briefly in this document; for more information, see the main Exim | |
797 | specification. | |
798 | ||
799 | ||
800 | 3.10 The add command | |
801 | -------------------- | |
802 | ||
803 | add <number> to <user variable> | |
804 | e.g. add 2 to n3 | |
805 | ||
806 | There are 10 user variables of this type, with names $n0 - $n9. Their values | |
807 | can be obtained by the normal expansion syntax (for example $n3) in other | |
808 | commands. At the start of filtering, these variables all contain zero. Both | |
809 | arguments of the add command are expanded before use, making it possible to add | |
810 | variables to each other. Subtraction can be obtained by adding negative | |
811 | numbers. | |
812 | ||
813 | ||
814 | 3.11 The deliver command | |
815 | ------------------------ | |
816 | ||
817 | deliver <mail address> | |
818 | e.g. deliver "Dr Livingstone <David@somewhere.africa.example>" | |
819 | ||
820 | This command provides a forwarding operation. The delivery that it sets up is | |
821 | significant unless the command is preceded by "unseen" (see section 3.8). The | |
822 | message is sent on to the given address, exactly as happens if the address had | |
823 | appeared in a traditional .forward file. If you want to deliver the message to | |
824 | a number of different addresses, you can use more than one deliver command | |
825 | (each one may have only one address). However, duplicate addresses are | |
826 | discarded. | |
827 | ||
828 | To deliver a copy of the message to your normal mailbox, your login name can be | |
829 | given as the address. Once an address has been processed by the filtering | |
830 | mechanism, an identical generated address will not be so processed again, so | |
831 | doing this does not cause a loop. | |
832 | ||
833 | However, if you have a mail alias, you should not refer to it here. For | |
834 | example, if the mail address L.Gulliver is aliased to lg303 then all references | |
835 | in Gulliver's .forward file should be to lg303. A reference to the alias will | |
836 | not work for messages that are addressed to that alias, since, like .forward | |
837 | file processing, aliasing is performed only once on an address, in order to | |
838 | avoid looping. | |
839 | ||
840 | Following the new address, an optional second address, preceded by "errors_to" | |
841 | may appear. This changes the address to which delivery errors on the forwarded | |
842 | message will be sent. Instead of going to the message's original sender, they | |
843 | go to this new address. For ordinary users, the only value that is permitted | |
844 | for this address is the user whose filter file is being processed. For example, | |
845 | the user lg303 whose mailbox is in the domain lilliput.example could have a | |
846 | filter file that contains | |
847 | ||
848 | deliver jon@elsewhere.example errors_to lg303@lilliput.example | |
849 | ||
850 | Clearly, using this feature makes sense only in situations where not all | |
851 | messages are being forwarded. In particular, bounce messages must not be | |
852 | forwarded in this way, as this is likely to create a mail loop if something | |
853 | goes wrong. | |
854 | ||
855 | ||
856 | 3.12 The save command | |
857 | --------------------- | |
858 | ||
859 | save <file name> | |
860 | e.g. save $home/mail/bookfolder | |
861 | ||
862 | This command specifies that a copy of the message is to be appended to the | |
863 | given file (that is, the file is to be used as a mail folder). The delivery | |
864 | that save sets up is significant unless the command is preceded by "unseen" | |
865 | (see section 3.8). | |
866 | ||
867 | More than one save command may be obeyed; each one causes a copy of the message | |
868 | to be written to its argument file, provided they are different (duplicate save | |
869 | commands are ignored). | |
870 | ||
871 | If the file name does not start with a / character, the contents of the $home | |
872 | variable are prepended, unless it is empty, or the system administrator has | |
873 | disabled this feature. In conventional configurations, this variable is | |
874 | normally set in a user filter to the user's home directory, but the system | |
875 | administrator may set it to some other path. In some configurations, $home may | |
876 | be unset, or prepending may be disabled, in which case a non-absolute path name | |
877 | may be generated. Such configurations convert this to an absolute path when the | |
878 | delivery takes place. In a system filter, $home is never set. | |
879 | ||
880 | The user must of course have permission to write to the file, and the writing | |
881 | of the file takes place in a process that is running as the user, under the | |
882 | user's primary group. Any secondary groups to which the user may belong are not | |
883 | normally taken into account, though the system administrator can configure Exim | |
884 | to set them up. In addition, the ability to use this command at all is | |
885 | controlled by the system administrator - it may be forbidden on some systems. | |
886 | ||
887 | An optional mode value may be given after the file name. The value for the mode | |
888 | is interpreted as an octal number, even if it does not begin with a zero. For | |
889 | example: | |
890 | ||
891 | save /some/folder 640 | |
892 | ||
893 | This makes it possible for users to override the system-wide mode setting for | |
894 | file deliveries, which is normally 600. If an existing file does not have the | |
895 | correct mode, it is changed. | |
896 | ||
897 | An alternative form of delivery may be enabled on your system, in which each | |
898 | message is delivered into a new file in a given directory. If this is the case, | |
899 | this functionality can be requested by giving the directory name terminated by | |
900 | a slash after the save command, for example | |
901 | ||
902 | save separated/messages/ | |
903 | ||
904 | There are several different formats for such deliveries; check with your system | |
905 | administrator or local documentation to find out which (if any) are available | |
906 | on your system. If this functionality is not enabled, the use of a path name | |
907 | ending in a slash causes an error. | |
908 | ||
909 | ||
910 | 3.13 The pipe command | |
911 | --------------------- | |
912 | ||
913 | pipe <command> | |
914 | e.g. pipe "$home/bin/countmail $sender_address" | |
915 | ||
916 | This command specifies that the message is to be delivered to the specified | |
917 | command using a pipe. The delivery that it sets up is significant unless the | |
918 | command is preceded by "unseen" (see section 3.8). Remember, however, that no | |
919 | deliveries are done while the filter is being processed. All deliveries happen | |
920 | later on. Therefore, the result of running the pipe is not available to the | |
921 | filter. | |
922 | ||
923 | When the deliveries are done, a separate process is run, and a copy of the | |
924 | message is passed on its standard input. The process runs as the user, under | |
925 | the user's primary group. Any secondary groups to which the user may belong are | |
926 | not normally taken into account, though the system administrator can configure | |
927 | Exim to set them up. More than one pipe command may appear; each one causes a | |
928 | copy of the message to be written to its argument pipe, provided they are | |
929 | different (duplicate pipe commands are ignored). | |
930 | ||
931 | When the time comes to transport the message, the command supplied to pipe is | |
932 | split up by Exim into a command name and a number of arguments. These are | |
933 | delimited by white space except for arguments enclosed in double quotes, in | |
934 | which case backslash is interpreted as an escape, or in single quotes, in which | |
935 | case no escaping is recognized. Note that as the whole command is normally | |
936 | supplied in double quotes, a second level of quoting is required for internal | |
937 | double quotes. For example: | |
938 | ||
939 | pipe "$home/myscript \"size is $message_size\"" | |
940 | ||
941 | String expansion is performed on the separate components after the line has | |
942 | been split up, and the command is then run directly by Exim; it is not run | |
943 | under a shell. Therefore, substitution cannot change the number of arguments, | |
944 | nor can quotes, backslashes or other shell metacharacters in variables cause | |
945 | confusion. | |
946 | ||
947 | Documentation for some programs that are normally run via this kind of pipe | |
948 | often suggest that the command should start with | |
949 | ||
950 | IFS=" " | |
951 | ||
952 | This is a shell command, and should not be present in Exim filter files, since | |
953 | it does not normally run the command under a shell. | |
954 | ||
955 | However, there is an option that the administrator can set to cause a shell to | |
956 | be used. In this case, the entire command is expanded as a single string and | |
957 | passed to the shell for interpretation. It is recommended that this be avoided | |
958 | if at all possible, since it can lead to problems when inserted variables | |
959 | contain shell metacharacters. | |
960 | ||
961 | The default PATH set up for the command is determined by the system | |
962 | administrator, usually containing at least /bin and /usr/bin so that common | |
963 | commands are available without having to specify an absolute file name. | |
964 | However, it is possible for the system administrator to restrict the pipe | |
965 | facility so that the command name must not contain any / characters, and must | |
966 | be found in one of the directories in the configured PATH. It is also possible | |
967 | for the system administrator to lock out the use of the pipe command | |
968 | altogether. | |
969 | ||
970 | When the command is run, a number of environment variables are set up. The | |
971 | complete list for pipe deliveries may be found in the Exim reference manual. | |
972 | Those that may be useful for pipe deliveries from user filter files are: | |
973 | ||
974 | DOMAIN the domain of the address | |
975 | HOME your home directory | |
976 | LOCAL_PART see below | |
977 | LOCAL_PART_PREFIX see below | |
978 | LOCAL_PART_SUFFIX see below | |
979 | LOGNAME your login name | |
980 | MESSAGE_ID the unique id of the message | |
981 | PATH the command search path | |
982 | RECIPIENT the complete recipient address | |
983 | SENDER the sender of the message | |
984 | SHELL /bin/sh | |
985 | USER see below | |
986 | ||
987 | LOCAL_PART, LOGNAME, and USER are all set to the same value, namely, your login | |
988 | id. LOCAL_PART_PREFIX and LOCAL_PART_SUFFIX may be set if Exim is configured to | |
989 | recognize prefixes or suffixes in the local parts of addresses. For example, a | |
990 | message addressed to pat-suf2@domain.example may cause the filter for user pat | |
991 | to be run. If this sets up a pipe delivery, LOCAL_PART_SUFFIX is "-suf2" when | |
992 | the pipe command runs. The system administrator has to configure Exim specially | |
993 | for this feature to be available. | |
994 | ||
995 | If you run a command that is a shell script, be very careful in your use of | |
996 | data from the incoming message in the commands in your script. RFC 2822 is very | |
997 | generous in the characters that are permitted to appear in mail addresses, and | |
998 | in particular, an address may begin with a vertical bar or a slash. For this | |
999 | reason you should always use quotes round any arguments that involve data from | |
1000 | the message, like this: | |
1001 | ||
1002 | /some/command '$SENDER' | |
1003 | ||
1004 | so that inserted shell meta-characters do not cause unwanted effects. | |
1005 | ||
1006 | Remember that, as was explained earlier, the pipe command is not run at the | |
1007 | time the filter file is interpreted. The filter just defines what deliveries | |
1008 | are required for one particular addressee of a message. The deliveries | |
1009 | themselves happen later, once Exim has decided everything that needs to be done | |
1010 | for the message. | |
1011 | ||
1012 | A consequence of this is that you cannot inspect the return code from the pipe | |
1013 | command from within the filter. Nevertheless, the code returned by the command | |
1014 | is important, because Exim uses it to decide whether the delivery has succeeded | |
1015 | or failed. | |
1016 | ||
1017 | The command should return a zero completion code if all has gone well. Most | |
1018 | non-zero codes are treated by Exim as indicating a failure of the pipe. This is | |
1019 | treated as a delivery failure, causing the message to be returned to its | |
1020 | sender. However, there are some completion codes that are treated as temporary | |
1021 | errors. The message remains on Exim's spool disk, and the delivery is tried | |
1022 | again later, though it will ultimately time out if the delivery failures go on | |
1023 | too long. The completion codes to which this applies can be specified by the | |
1024 | system administrator; the default values are 73 and 75. | |
1025 | ||
1026 | The pipe command should not normally write anything to its standard output or | |
1027 | standard error file descriptors. If it does, whatever is written is normally | |
1028 | returned to the sender of the message as a delivery error, though this action | |
1029 | can be varied by the system administrator. | |
1030 | ||
1031 | ||
1032 | 3.14 Mail commands | |
1033 | ------------------ | |
1034 | ||
1035 | There are two commands that cause the creation of a new mail message, neither | |
1036 | of which count as a significant delivery unless the command is preceded by the | |
1037 | word "seen" (see section 3.8). This is a powerful facility, but it should be | |
1038 | used with care, because of the danger of creating infinite sequences of | |
1039 | messages. The system administrator can forbid the use of these commands | |
1040 | altogether. | |
1041 | ||
1042 | To help prevent runaway message sequences, these commands have no effect when | |
1043 | the incoming message is a bounce (delivery error) message, and messages sent by | |
1044 | this means are treated as if they were reporting delivery errors. Thus, they | |
1045 | should never themselves cause a bounce message to be returned. The basic | |
1046 | mail-sending command is | |
1047 | ||
1048 | mail [to <address-list>] | |
1049 | [cc <address-list>] | |
1050 | [bcc <address-list>] | |
1051 | [from <address>] | |
1052 | [reply_to <address>] | |
1053 | [subject <text>] | |
1054 | [extra_headers <text>] | |
1055 | [text <text>] | |
1056 | [[expand] file <filename>] | |
1057 | [return message] | |
1058 | [log <log file name>] | |
1059 | [once <note file name>] | |
1060 | [once_repeat <time interval>] | |
1061 | e.g. mail text "Your message about $h_subject: has been received" | |
1062 | ||
1063 | Each <address-list> can contain a number of addresses, separated by commas, in | |
1064 | the format of a To: or Cc: header line. In fact, the text you supply here is | |
1065 | copied exactly into the appropriate header line. It may contain additional | |
1066 | information as well as email addresses. For example: | |
1067 | ||
1068 | mail to "Julius Caesar <jc@rome.example>, \ | |
1069 | <ma@rome.example> (Mark A.)" | |
1070 | ||
1071 | Similarly, the texts supplied for from and reply_to are copied into their | |
1072 | respective header lines. | |
1073 | ||
1074 | As a convenience for use in one common case, there is also a command called | |
1075 | vacation. It behaves in the same way as mail, except that the defaults for the | |
1076 | subject, file, log, once, and once_repeat options are | |
1077 | ||
1078 | subject "On vacation" | |
1079 | expand file .vacation.msg | |
1080 | log .vacation.log | |
1081 | once .vacation | |
1082 | once_repeat 7d | |
1083 | ||
1084 | respectively. These are the same file names and repeat period used by the | |
1085 | traditional Unix vacation command. The defaults can be overridden by explicit | |
1086 | settings, but if a file name is given its contents are expanded only if | |
1087 | explicitly requested. | |
1088 | ||
1089 | Warning: The vacation command should always be used conditionally, subject to | |
1090 | at least the personal condition (see section 3.27 below) so as not to send | |
1091 | automatic replies to non-personal messages from mailing lists or elsewhere. | |
1092 | Sending an automatic response to a mailing list or a mailing list manager is an | |
1093 | Internet Sin. | |
1094 | ||
1095 | For both commands, the key/value argument pairs can appear in any order. At | |
1096 | least one of text or file must appear (except with vacation, where there is a | |
1097 | default for file); if both are present, the text string appears first in the | |
1098 | message. If expand precedes file, each line of the file is subject to string | |
1099 | expansion before it is included in the message. | |
1100 | ||
1101 | Several lines of text can be supplied to text by including the escape sequence | |
1102 | "\n" in the string wherever a newline is required. If the command is output | |
1103 | during filter file testing, newlines in the text are shown as "\n". | |
1104 | ||
1105 | Note that the keyword for creating a Reply-To: header is reply_to, because Exim | |
1106 | keywords may contain underscores, but not hyphens. If the from keyword is | |
1107 | present and the given address does not match the user who owns the forward | |
1108 | file, Exim normally adds a Sender: header to the message, though it can be | |
1109 | configured not to do this. | |
1110 | ||
1111 | The extra_headers keyword allows you to add custom header lines to the message. | |
1112 | The text supplied must be one or more syntactically valid RFC 2822 header | |
1113 | lines. You can use "\n" within quoted text to specify newlines between headers, | |
1114 | and also to define continued header lines. For example: | |
1115 | ||
1116 | extra_headers "h1: first\nh2: second\n continued\nh3: third" | |
1117 | ||
1118 | No newline should appear at the end of the final header line. | |
1119 | ||
1120 | If no to argument appears, the message is sent to the address in the | |
1121 | $reply_address variable (see section 3.3 above). An In-Reply-To: header is | |
1122 | automatically included in the created message, giving a reference to the | |
1123 | message identification of the incoming message. | |
1124 | ||
1125 | If return message is specified, the incoming message that caused the filter | |
1126 | file to be run is added to the end of the message, subject to a maximum size | |
1127 | limitation. | |
1128 | ||
1129 | If a log file is specified, a line is added to it for each message sent. | |
1130 | ||
1131 | If a once file is specified, it is used to hold a database for remembering who | |
1132 | has received a message, and no more than one message is ever sent to any | |
1133 | particular address, unless once_repeat is set. This specifies a time interval | |
1134 | after which another copy of the message is sent. The interval is specified as a | |
1135 | sequence of numbers, each followed by the initial letter of one of "seconds", | |
1136 | "minutes", "hours", "days", or "weeks". For example, | |
1137 | ||
1138 | once_repeat 5d4h | |
1139 | ||
1140 | causes a new message to be sent if at least 5 days and 4 hours have elapsed | |
1141 | since the last one was sent. There must be no white space in a time interval. | |
1142 | ||
1143 | Commonly, the file name specified for once is used as the base name for | |
1144 | direct-access (DBM) file operations. There are a number of different DBM | |
1145 | libraries in existence. Some operating systems provide one as a default, but | |
1146 | even in this case a different one may have been used when building Exim. With | |
1147 | some DBM libraries, specifying once results in two files being created, with | |
1148 | the suffixes .dir and .pag being added to the given name. With some others a | |
1149 | single file with the suffix .db is used, or the name is used unchanged. | |
1150 | ||
1151 | Using a DBM file for implementing the once feature means that the file grows as | |
1152 | large as necessary. This is not usually a problem, but some system | |
1153 | administrators want to put a limit on it. The facility can be configured not to | |
1154 | use a DBM file, but instead, to use a regular file with a maximum size. The | |
1155 | data in such a file is searched sequentially, and if the file fills up, the | |
1156 | oldest entry is deleted to make way for a new one. This means that some | |
1157 | correspondents may receive a second copy of the message after an unpredictable | |
1158 | interval. Consult your local information to see if your system is configured | |
1159 | this way. | |
1160 | ||
1161 | More than one mail or vacation command may be obeyed in a single filter run; | |
1162 | they are all honoured, even when they are to the same recipient. | |
1163 | ||
1164 | ||
1165 | 3.15 Logging commands | |
1166 | --------------------- | |
1167 | ||
1168 | A log can be kept of actions taken by a filter file. This facility is normally | |
1169 | available in conventional configurations, but there are some situations where | |
1170 | it might not be. Also, the system administrator may choose to disable it. Check | |
1171 | your local information if in doubt. | |
1172 | ||
1173 | Logging takes place while the filter file is being interpreted. It does not | |
1174 | queue up for later like the delivery commands. The reason for this is so that a | |
1175 | log file need be opened only once for several write operations. There are two | |
1176 | commands, neither of which constitutes a significant delivery. The first | |
1177 | defines a file to which logging output is subsequently written: | |
1178 | ||
1179 | logfile <file name> | |
1180 | e.g. logfile $home/filter.log | |
1181 | ||
1182 | The file name must be fully qualified. You can use $home, as in this example, | |
1183 | to refer to your home directory. The file name may optionally be followed by a | |
1184 | mode for the file, which is used if the file has to be created. For example, | |
1185 | ||
1186 | logfile $home/filter.log 0644 | |
1187 | ||
1188 | The number is interpreted as octal, even if it does not begin with a zero. The | |
1189 | default for the mode is 600. It is suggested that the logfile command normally | |
1190 | appear as the first command in a filter file. Once a log file has been obeyed, | |
1191 | the logwrite command can be used to write to it: | |
1192 | ||
1193 | logwrite "<some text string>" | |
1194 | e.g. logwrite "$tod_log $message_id processed" | |
1195 | ||
1196 | It is possible to have more than one logfile command, to specify writing to | |
1197 | different log files in different circumstances. Writing takes place at the end | |
1198 | of the file, and a newline character is added to the end of each string if | |
1199 | there isn't one already there. Newlines can be put in the middle of the string | |
1200 | by using the "\n" escape sequence. Lines from simultaneous deliveries may get | |
1201 | interleaved in the file, as there is no interlocking, so you should plan your | |
1202 | logging with this in mind. However, data should not get lost. | |
1203 | ||
1204 | ||
1205 | 3.16 The finish command | |
1206 | ----------------------- | |
1207 | ||
1208 | The command finish, which has no arguments, causes Exim to stop interpreting | |
1209 | the filter file. This is not a significant action unless preceded by "seen". A | |
1210 | filter file containing only "seen finish" is a black hole. | |
1211 | ||
1212 | ||
1213 | 3.17 The testprint command | |
1214 | -------------------------- | |
1215 | ||
1216 | It is sometimes helpful to be able to print out the values of variables when | |
1217 | testing filter files. The command | |
1218 | ||
1219 | testprint <text> | |
1220 | e.g. testprint "home=$home reply_address=$reply_address" | |
1221 | ||
1222 | does nothing when mail is being delivered. However, when the filtering code is | |
1223 | being tested by means of the -bf option (see section 1.3 above), the value of | |
1224 | the string is written to the standard output. | |
1225 | ||
1226 | ||
1227 | 3.18 The fail command | |
1228 | --------------------- | |
1229 | ||
1230 | When Exim's filtering facilities are being used as a system filter, the fail | |
1231 | command is available, to force delivery failure. Because this command is | |
1232 | normally usable only by the system administrator, and not enabled for use by | |
1233 | ordinary users, it is described in more detail in the main Exim specification | |
1234 | rather than in this document. | |
1235 | ||
1236 | ||
1237 | 3.19 The freeze command | |
1238 | ----------------------- | |
1239 | ||
1240 | When Exim's filtering facilities are being used as a system filter, the freeze | |
1241 | command is available, to freeze a message on the queue. Because this command is | |
1242 | normally usable only by the system administrator, and not enabled for use by | |
1243 | ordinary users, it is described in more detail in the main Exim specification | |
1244 | rather than in this document. | |
1245 | ||
1246 | ||
1247 | 3.20 The headers command | |
1248 | ------------------------ | |
1249 | ||
1250 | The headers command can be used to change the target character set that is used | |
1251 | when translating the contents of encoded header lines for insertion by the | |
1252 | $header_ mechanism (see section 3.5 above). The default can be set in the Exim | |
1253 | configuration; if not specified, ISO-8859-1 is used. The only currently | |
1254 | supported format for the headers command in user filters is as in this example: | |
1255 | ||
1256 | headers charset "UTF-8" | |
1257 | ||
1258 | That is, headers is followed by the word "charset" and then the name of a | |
1259 | character set. This particular example would be useful if you wanted to compare | |
1260 | the contents of a header to a UTF-8 string. | |
1261 | ||
1262 | In system filter files, the headers command can be used to add or remove header | |
1263 | lines from the message. These features are described in the main Exim | |
1264 | specification. | |
1265 | ||
1266 | ||
1267 | 3.21 Obeying commands conditionally | |
1268 | ----------------------------------- | |
1269 | ||
1270 | Most of the power of filtering comes from the ability to test conditions and | |
1271 | obey different commands depending on the outcome. The if command is used to | |
1272 | specify conditional execution, and its general form is | |
1273 | ||
1274 | if <condition> | |
1275 | then <commands> | |
1276 | elif <condition> | |
1277 | then <commands> | |
1278 | else <commands> | |
1279 | endif | |
1280 | ||
1281 | There may be any number of elif and then sections (including none) and the else | |
1282 | section is also optional. Any number of commands, including nested if commands, | |
1283 | may appear in any of the <commands> sections. | |
1284 | ||
1285 | Conditions can be combined by using the words and and or, and round brackets | |
1286 | (parentheses) can be used to specify how several conditions are to combine. | |
1287 | Without brackets, and is more binding than or. For example: | |
1288 | ||
1289 | if | |
1290 | $h_subject: contains "Make money" or | |
1291 | $h_precedence: is "junk" or | |
1292 | ($h_sender: matches ^\\d{8}@ and not personal) or | |
1293 | $message_body contains "this is not spam" | |
1294 | then | |
1295 | seen finish | |
1296 | endif | |
1297 | ||
1298 | A condition can be preceded by not to negate it, and there are also some | |
1299 | negative forms of condition that are more English-like. | |
1300 | ||
1301 | ||
1302 | 3.22 String testing conditions | |
1303 | ------------------------------ | |
1304 | ||
1305 | There are a number of conditions that operate on text strings, using the words | |
1306 | "begins", "ends", "is", "contains" and "matches". If you want to apply the same | |
1307 | test to more than one header line, you can easily concatenate them into a | |
1308 | single string for testing, as in this example: | |
1309 | ||
1310 | if "$h_to:, $h_cc:" contains me@domain.example then ... | |
1311 | ||
1312 | If a string-testing condition name is written in lower case, the testing of | |
1313 | letters is done without regard to case; if it is written in upper case (for | |
1314 | example, "CONTAINS"), the case of letters is taken into account. | |
1315 | ||
1316 | <text1> begins <text2> | |
1317 | <text1> does not begin <text2> | |
1318 | e.g. $header_from: begins "Friend@" | |
1319 | ||
1320 | A "begins" test checks for the presence of the second string at the start of | |
1321 | the first, both strings having been expanded. | |
1322 | ||
1323 | <text1> ends <text2> | |
1324 | <text1> does not end <text2> | |
1325 | e.g. $header_from: ends "public.com.example" | |
1326 | ||
1327 | An "ends" test checks for the presence of the second string at the end of the | |
1328 | first, both strings having been expanded. | |
1329 | ||
1330 | <text1> is <text2> | |
1331 | <text1> is not <text2> | |
1332 | e.g. $local_part_suffix is "-foo" | |
1333 | ||
1334 | An "is" test does an exact match between the strings, having first expanded | |
1335 | both strings. | |
1336 | ||
1337 | <text1> contains <text2> | |
1338 | <text1> does not contain <text2> | |
1339 | e.g. $header_subject: contains "evolution" | |
1340 | ||
1341 | A "contains" test does a partial string match, having expanded both strings. | |
1342 | ||
1343 | <text1> matches <text2> | |
1344 | <text1> does not match <text2> | |
1345 | e.g. $sender_address matches "(bill|john)@" | |
1346 | ||
1347 | For a "matches" test, after expansion of both strings, the second one is | |
1348 | interpreted as a regular expression. Exim uses the PCRE regular expression | |
1349 | library, which provides regular expressions that are compatible with Perl. | |
1350 | ||
1351 | The match succeeds if the regular expression matches any part of the first | |
1352 | string. If you want a regular expression to match only at the start or end of | |
1353 | the subject string, you must encode that requirement explicitly, using the "^" | |
1354 | or "$" metacharacters. The above example, which is not so constrained, matches | |
1355 | all these addresses: | |
1356 | ||
1357 | bill@test.example | |
1358 | john@some.example | |
1359 | spoonbill@example.com | |
1360 | littlejohn@example.com | |
1361 | ||
1362 | To match only the first two, you could use this: | |
1363 | ||
1364 | if $sender_address matches "^(bill|john)@" then ... | |
1365 | ||
1366 | Care must be taken if you need a backslash in a regular expression, because | |
1367 | backslashes are interpreted as escape characters both by the string expansion | |
1368 | code and by Exim's normal processing of strings in quotes. For example, if you | |
1369 | want to test the sender address for a domain ending in .com the regular | |
1370 | expression is | |
1371 | ||
1372 | \.com$ | |
1373 | ||
1374 | The backslash and dollar sign in that expression have to be escaped when used | |
1375 | in a filter command, as otherwise they would be interpreted by the expansion | |
1376 | code. Thus, what you actually write is | |
1377 | ||
1378 | if $sender_address matches \\.com\$ | |
1379 | ||
1380 | An alternative way of handling this is to make use of the "\N" expansion flag | |
1381 | for suppressing expansion: | |
1382 | ||
1383 | if $sender_address matches \N\.com$\N | |
1384 | ||
1385 | Everything between the two occurrences of "\N" is copied without change by the | |
1386 | string expander (and in fact you do not need the final one, because it is at | |
1387 | the end of the string). If the regular expression is given in quotes (mandatory | |
1388 | only if it contains white space) you have to write either | |
1389 | ||
1390 | if $sender_address matches "\\\\.com\\$" | |
1391 | ||
1392 | or | |
1393 | ||
1394 | if $sender_address matches "\\N\\.com$\\N" | |
1395 | ||
1396 | If the regular expression contains bracketed sub-expressions, numeric variable | |
1397 | substitutions such as $1 can be used in the subsequent actions after a | |
1398 | successful match. If the match fails, the values of the numeric variables | |
1399 | remain unchanged. Previous values are not restored after endif. In other words, | |
1400 | only one set of values is ever available. If the condition contains several | |
1401 | sub-conditions connected by and or or, it is the strings extracted from the | |
1402 | last successful match that are available in subsequent actions. Numeric | |
1403 | variables from any one sub-condition are also available for use in subsequent | |
1404 | sub-conditions, because string expansion of a condition occurs just before it | |
1405 | is tested. | |
1406 | ||
1407 | ||
1408 | 3.23 Numeric testing conditions | |
1409 | ------------------------------- | |
1410 | ||
1411 | The following conditions are available for performing numerical tests: | |
1412 | ||
1413 | <number1> is above <number2> | |
1414 | <number1> is not above <number2> | |
1415 | <number1> is below <number2> | |
1416 | <number1> is not below <number2> | |
1417 | e.g. $message_size is not above 10k | |
1418 | ||
1419 | The <number> arguments must expand to strings of digits, optionally followed by | |
1420 | one of the letters K or M (upper case or lower case) which cause multiplication | |
1421 | by 1024 and 1024x1024 respectively. | |
1422 | ||
1423 | ||
1424 | 3.24 Testing for significant deliveries | |
1425 | --------------------------------------- | |
1426 | ||
1427 | You can use the delivered condition to test whether or not any previously | |
1428 | obeyed filter commands have set up a significant delivery. For example: | |
1429 | ||
1430 | if not delivered then save mail/anomalous endif | |
1431 | ||
1432 | "Delivered" is perhaps a poor choice of name for this condition, because the | |
1433 | message has not actually been delivered; rather, a delivery has been set up for | |
1434 | later processing. | |
1435 | ||
1436 | ||
1437 | 3.25 Testing for error messages | |
1438 | ------------------------------- | |
1439 | ||
1440 | The condition error_message is true if the incoming message is a bounce (mail | |
1441 | delivery error) message. Putting the command | |
1442 | ||
1443 | if error_message then finish endif | |
1444 | ||
1445 | at the head of your filter file is a useful insurance against things going | |
1446 | wrong in such a way that you cannot receive delivery error reports. Note: | |
1447 | error_message is a condition, not an expansion variable, and therefore is not | |
1448 | preceded by "$". | |
1449 | ||
1450 | ||
1451 | 3.26 Testing a list of addresses | |
1452 | -------------------------------- | |
1453 | ||
1454 | There is a facility for looping through a list of addresses and applying a | |
1455 | condition to each of them. It takes the form | |
1456 | ||
1457 | foranyaddress <string> (<condition>) | |
1458 | ||
1459 | where <string> is interpreted as a list of RFC 2822 addresses, as in a typical | |
1460 | header line, and <condition> is any valid filter condition or combination of | |
1461 | conditions. The "group" syntax that is defined for certain header lines that | |
1462 | contain addresses is supported. | |
1463 | ||
1464 | The parentheses surrounding the condition are mandatory, to delimit it from | |
1465 | possible further sub-conditions of the enclosing if command. Within the | |
1466 | condition, the expansion variable $thisaddress is set to the non-comment | |
1467 | portion of each of the addresses in the string in turn. For example, if the | |
1468 | string is | |
1469 | ||
1470 | B.Simpson <bart@sfld.example>, lisa@sfld.example (his sister) | |
1471 | ||
1472 | then $thisaddress would take on the values "bart@sfld.example" and | |
1473 | "lisa@sfld.example" in turn. | |
1474 | ||
1475 | If there are no valid addresses in the list, the whole condition is false. If | |
1476 | the internal condition is true for any one address, the overall condition is | |
1477 | true and the loop ends. If the internal condition is false for all addresses in | |
1478 | the list, the overall condition is false. This example tests for the presence | |
1479 | of an eight-digit local part in any address in a To: header: | |
1480 | ||
1481 | if foranyaddress $h_to: ( $thisaddress matches ^\\d{8}@ ) then ... | |
1482 | ||
1483 | When the overall condition is true, the value of $thisaddress in the commands | |
1484 | that follow then is the last value it took on inside the loop. At the end of | |
1485 | the if command, the value of $thisaddress is reset to what it was before. It is | |
1486 | best to avoid the use of multiple occurrences of foranyaddress, nested or | |
1487 | otherwise, in a single if command, if the value of $thisaddress is to be used | |
1488 | afterwards, because it isn't always clear what the value will be. Nested if | |
1489 | commands should be used instead. | |
1490 | ||
1491 | Header lines can be joined together if a check is to be applied to more than | |
1492 | one of them. For example: | |
1493 | ||
1494 | if foranyaddress $h_to:,$h_cc: .... | |
1495 | ||
1496 | This scans through the addresses in both the To: and the Cc: headers. | |
1497 | ||
1498 | ||
1499 | 3.27 Testing for personal mail | |
1500 | ------------------------------ | |
1501 | ||
1502 | A common requirement is to distinguish between incoming personal mail and mail | |
1503 | from a mailing list, or from a robot or other automatic process (for example, a | |
1504 | bounce message). In particular, this test is normally required for "vacation | |
1505 | messages". | |
1506 | ||
1507 | The personal condition checks that the message is not a bounce message and that | |
1508 | the current user's email address appears in the To: header. It also checks that | |
1509 | the sender is not the current user or one of a number of common daemons, and | |
1510 | that there are no header lines starting List- in the message. Finally, it | |
1511 | checks the content of the Precedence: header line, if there is one. | |
1512 | ||
1513 | You should always use the personal condition when generating automatic | |
1514 | responses. This example shows the use of personal in a filter file that is | |
1515 | sending out vacation messages: | |
1516 | ||
1517 | if personal then | |
1518 | mail to $reply_address | |
1519 | subject "I am on holiday" | |
1520 | file $home/vacation/message | |
1521 | once $home/vacation/once | |
1522 | once_repeat 10d | |
1523 | endif | |
1524 | ||
1525 | It is tempting, when writing commands like the above, to quote the original | |
1526 | subject in the reply. For example: | |
1527 | ||
1528 | subject "Re: $h_subject:" | |
1529 | ||
1530 | There is a danger in doing this, however. It may allow a third party to | |
1531 | subscribe you to an opt-in mailing list, provided that the list accepts bounce | |
1532 | messages as subscription confirmations. (Messages sent from filters are always | |
1533 | sent as bounce messages.) Well-managed lists require a non-bounce message to | |
1534 | confirm a subscription, so the danger is relatively small. | |
1535 | ||
1536 | If prefixes or suffixes are in use for local parts - something which depends on | |
1537 | the configuration of Exim (see section 3.31 below) - the tests for the current | |
1538 | user are done with the full address (including the prefix and suffix, if any) | |
1539 | as well as with the prefix and suffix removed. If the system is configured to | |
1540 | rewrite local parts of mail addresses, for example, to rewrite "dag46" as | |
1541 | "Dirk.Gently", the rewritten form of the address is also used in the tests. | |
1542 | ||
1543 | ||
1544 | 3.28 Alias addresses for the personal condition | |
1545 | ----------------------------------------------- | |
1546 | ||
1547 | It is quite common for people who have mail accounts on a number of different | |
1548 | systems to forward all their mail to one system, and in this case a check for | |
1549 | personal mail should test all their various mail addresses. To allow for this, | |
1550 | the personal condition keyword can be followed by | |
1551 | ||
1552 | alias <address> | |
1553 | ||
1554 | any number of times, for example: | |
1555 | ||
1556 | if personal alias smith@else.where.example | |
1557 | alias jones@other.place.example | |
1558 | then ... | |
1559 | ||
1560 | The alias addresses are treated as alternatives to the current user's email | |
1561 | address when testing the contents of header lines. | |
1562 | ||
1563 | ||
1564 | 3.29 Details of the personal condition | |
1565 | -------------------------------------- | |
1566 | ||
1567 | The basic personal test is roughly equivalent to the following: | |
1568 | ||
1569 | not error_message and | |
1570 | $message_headers does not contain "\nList-Id:" and | |
1571 | $message_headers does not contain "\nList-Help:" and | |
1572 | $message_headers does not contain "\nList-Subscribe:" and | |
1573 | $message_headers does not contain "\nList-Unsubscribe:" and | |
1574 | $message_headers does not contain "\nList-Post:" and | |
1575 | $message_headers does not contain "\nList-Owner:" and | |
1576 | $message_headers does not contain "\nList-Archive:" and | |
1577 | ( | |
1578 | "${if def:h_auto-submitted:{present}{absent}}" is "absent" or | |
1579 | $header_auto-submitted: is "no" | |
1580 | ) and | |
1581 | $header_precedence: does not contain "bulk" and | |
1582 | $header_precedence: does not contain "list" and | |
1583 | $header_precedence: does not contain "junk" and | |
1584 | foranyaddress $header_to: | |
1585 | ( $thisaddress contains "$local_part$domain" ) and | |
1586 | not foranyaddress $header_from: | |
1587 | ( | |
1588 | $thisaddress contains "$local_part@$domain" or | |
1589 | $thisaddress contains "server@" or | |
1590 | $thisaddress contains "daemon@" or | |
1591 | $thisaddress contains "root@" or | |
1592 | $thisaddress contains "listserv@" or | |
1593 | $thisaddress contains "majordomo@" or | |
1594 | $thisaddress contains "-request@" or | |
1595 | $thisaddress matches "^owner-[^@]+@" | |
1596 | ) | |
1597 | ||
1598 | The variable $local_part contains the local part of the mail address of the | |
1599 | user whose filter file is being run - it is normally your login id. The $domain | |
1600 | variable contains the mail domain. As explained above, if aliases or rewriting | |
1601 | are defined, or if prefixes or suffixes are in use, the tests for the current | |
1602 | user are also done with alternative addresses. | |
1603 | ||
1604 | ||
1605 | 3.30 Testing delivery status | |
1606 | ---------------------------- | |
1607 | ||
1608 | There are two conditions that are intended mainly for use in system filter | |
1609 | files, but which are available in users' filter files as well. The condition | |
1610 | first_delivery is true if this is the first process that is attempting to | |
1611 | deliver the message, and false otherwise. This indicator is not reset until the | |
1612 | first delivery process successfully terminates; if there is a crash or a power | |
1613 | failure (for example), the next delivery attempt is also a "first delivery". | |
1614 | ||
1615 | In a user filter file first_delivery will be false if there was previously an | |
1616 | error in the filter, or if a delivery for the user failed owing to, for | |
1617 | example, a quota error, or if forwarding to a remote address was deferred for | |
1618 | some reason. | |
1619 | ||
1620 | The condition manually_thawed is true if the message was "frozen" for some | |
1621 | reason, and was subsequently released by the system administrator. It is | |
1622 | unlikely to be of use in users' filter files. | |
1623 | ||
1624 | ||
1625 | 3.31 Multiple personal mailboxes | |
1626 | -------------------------------- | |
1627 | ||
1628 | The system administrator can configure Exim so that users can set up variants | |
1629 | on their email addresses and handle them separately. Consult your system | |
1630 | administrator or local documentation to see if this facility is enabled on your | |
1631 | system, and if so, what the details are. | |
1632 | ||
1633 | The facility involves the use of a prefix or a suffix on an email address. For | |
1634 | example, all mail addressed to lg303-<something> would be the property of user | |
1635 | lg303, who could determine how it was to be handled, depending on the value of | |
1636 | <something>. | |
1637 | ||
1638 | There are two possible ways in which this can be set up. The first possibility | |
1639 | is the use of multiple .forward files. In this case, mail to lg303-foo, for | |
1640 | example, is handled by looking for a file called .forward-foo in lg303's home | |
1641 | directory. If such a file does not exist, delivery fails and the message is | |
1642 | returned to its sender. | |
1643 | ||
1644 | The alternative approach is to pass all messages through a single .forward | |
1645 | file, which must be a filter file so that it can distinguish between the | |
1646 | different cases by referencing the variables $local_part_prefix or | |
1647 | $local_part_suffix, as in the final example in section 3.33 below. | |
1648 | ||
1649 | It is possible to configure Exim to support both schemes at once. In this case, | |
1650 | a specific .forward-foo file is first sought; if it is not found, the basic | |
1651 | .forward file is used. | |
1652 | ||
1653 | The personal test (see section 3.27) includes prefixes and suffixes in its | |
1654 | checking. | |
1655 | ||
1656 | ||
1657 | 3.32 Ignoring delivery errors | |
1658 | ----------------------------- | |
1659 | ||
1660 | As was explained above, filtering just sets up addresses for delivery - no | |
1661 | deliveries are actually done while a filter file is active. If any of the | |
1662 | generated addresses subsequently suffers a delivery failure, an error message | |
1663 | is generated in the normal way. However, if a filter command that sets up a | |
1664 | delivery is preceded by the word "noerror", errors for that delivery, and any | |
1665 | deliveries consequent on it (that is, from alias, forwarding, or filter files | |
1666 | it invokes) are ignored. | |
1667 | ||
1668 | ||
1669 | 3.33 Examples of Exim filter commands | |
1670 | ------------------------------------- | |
1671 | ||
1672 | Simple forwarding: | |
1673 | ||
1674 | # Exim filter | |
1675 | deliver baggins@rivendell.middle-earth.example | |
1676 | ||
1677 | Vacation handling using traditional means, assuming that the .vacation.msg and | |
1678 | other files have been set up in your home directory: | |
1679 | ||
1680 | # Exim filter | |
1681 | unseen pipe "/usr/ucb/vacation \"$local_part\"" | |
1682 | ||
1683 | Vacation handling inside Exim, having first created a file called .vacation.msg | |
1684 | in your home directory: | |
1685 | ||
1686 | # Exim filter | |
1687 | if personal then vacation endif | |
1688 | ||
1689 | File some messages by subject: | |
1690 | ||
1691 | # Exim filter | |
1692 | if $header_subject: contains "empire" or | |
1693 | $header_subject: contains "foundation" | |
1694 | then | |
1695 | save $home/mail/f+e | |
1696 | endif | |
1697 | ||
1698 | Save all non-urgent messages by weekday: | |
1699 | ||
1700 | # Exim filter | |
1701 | if $header_subject: does not contain "urgent" and | |
1702 | $tod_full matches "^(...)," | |
1703 | then | |
1704 | save $home/mail/$1 | |
1705 | endif | |
1706 | ||
1707 | Throw away all mail from one site, except from postmaster: | |
1708 | ||
1709 | # Exim filter | |
1710 | if $reply_address contains "@spam.site.example" and | |
1711 | $reply_address does not contain "postmaster@" | |
1712 | then | |
1713 | seen finish | |
1714 | endif | |
1715 | ||
1716 | Handle multiple personal mailboxes: | |
1717 | ||
1718 | # Exim filter | |
1719 | if $local_part_suffix is "-foo" | |
1720 | then | |
1721 | save $home/mail/foo | |
1722 | elif $local_part_suffix is "-bar" | |
1723 | then | |
1724 | save $home/mail/bar | |
1725 | endif | |
1726 |