Commit | Line | Data |
---|---|---|
1c59d63b | 1 | $Cambridge: exim/doc/doc-txt/README.SIEVE,v 1.7 2005/08/30 10:55:52 ph10 Exp $ |
495ae4b0 PH |
2 | |
3 | Notes on the Sieve implementation for Exim | |
4 | ||
5 | Exim Filter Versus Sieve Filter | |
6 | ||
7 | Exim supports two incompatible filters: The traditional Exim filter and | |
8 | the Sieve filter. Since Sieve is a extensible language, it is important | |
9 | to understand "Sieve" in this context as "the specific implementation | |
10 | of Sieve for Exim". | |
11 | ||
12 | The Exim filter contains more features, such as variable expansion, and | |
13 | better integration with the host environment, like external processes | |
14 | and pipes. | |
15 | ||
16 | Sieve is a standard for interoperable filters, defined in RFC 3028, | |
17 | with multiple implementations around. If interoperability is important, | |
18 | then there is no way around it. | |
19 | ||
20 | ||
21 | Exim Implementation | |
22 | ||
1c59d63b PH |
23 | The Exim Sieve implementation offers the core as defined by draft |
24 | 3028bis-4 (next version of RFC 3028 that fixes specification mistakes), | |
25 | the "envelope" (3028bis), the "fileinto" (3028bis), the "copy" (RFC 3894) | |
26 | and the "vacation" (draft-ietf-sieve-vacation-02.txt) extension, the | |
27 | "i;ascii-numeric" comparator (RFC 2244). | |
495ae4b0 PH |
28 | |
29 | The Sieve filter is integrated in Exim and works very similar to the | |
30 | Exim filter: Sieve scripts are recognized by the first line containing | |
31 | "# sieve filter". When using "keep" or "fileinto" to save a mail into a | |
32 | folder, the resulting string is available as the variable $address_file | |
1c59d63b PH |
33 | in the transport that stores it. The following routers and transport |
34 | show a typical use of Sieve: | |
35 | ||
36 | begin routers | |
37 | ||
38 | localuser_verify: | |
39 | driver = accept | |
40 | domains = +localdomains | |
41 | local_part_suffix = "-*" | |
42 | local_part_suffix_optional | |
43 | check_local_user | |
44 | require_files = $home/.forward | |
45 | verify_only = true | |
46 | ||
47 | localuser_deliver: | |
48 | driver = redirect | |
49 | domains = +localdomains | |
50 | local_part_suffix = "-*" | |
51 | local_part_suffix_optional | |
52 | sieve_subaddress = "${sg{$local_part_suffix}{^-}{}}" | |
53 | sieve_useraddress = "$local_part" | |
54 | check_local_user | |
55 | require_files = $home/.forward | |
56 | file = $home/.forward | |
57 | check_ancestor | |
58 | allow_filter | |
59 | file_transport = localuser | |
60 | reply_transport = vacation | |
61 | sieve_vacation_directory = $home/mail/vacation | |
62 | verify = false | |
63 | ||
64 | begin transports | |
495ae4b0 PH |
65 | |
66 | localuser: | |
67 | driver = appendfile | |
68 | file = ${if eq{$address_file}{inbox} \ | |
69 | {/var/mail/$local_part} \ | |
70 | {${if eq{${substr_0_1:$address_file}}{/} \ | |
71 | {$address_file} \ | |
1c59d63b | 72 | {$home/mail/$address_file} \ |
495ae4b0 PH |
73 | }} \ |
74 | } | |
75 | delivery_date_add | |
76 | envelope_to_add | |
77 | return_path_add | |
78 | mode = 0600 | |
79 | ||
1c59d63b PH |
80 | vacation: |
81 | driver = autoreply | |
495ae4b0 | 82 | |
1c59d63b PH |
83 | Absolute files are stored where specified, relative files are stored |
84 | relative to $home/mail and "inbox" goes to the standard mailbox location. | |
85 | To enable "vacation", sieve_vacation_directory is set to the directory | |
86 | where vacation databases are held (don't put anything else in that | |
87 | directory) and point reply_transport to an autoreply transport. | |
88 | Setting the Sieve useraddress and subaddress allows to use the subaddress | |
89 | extension. | |
495ae4b0 PH |
90 | |
91 | ||
92 | RFC Compliance | |
93 | ||
94 | Exim requires the first line to be "# sieve filter". Of course the RFC | |
95 | does not enforce that line. Don't expect examples to work without adding | |
96 | it, though. | |
97 | ||
98 | RFC 3028 requires using CRLF to terminate the end of a line. | |
99 | The rationale was that CRLF is universally used in network protocols | |
100 | to mark the end of the line. This implementation does not embed Sieve | |
101 | in a network protocol, but uses Sieve scripts as part of the Exim MTA. | |
102 | Since all parts of Exim use \n as newline character, this implementation | |
103 | does, too. You can change this by defining the macro RFC_EOL at compile | |
104 | time to enforce CRLF being used. | |
105 | ||
495ae4b0 PH |
106 | Sieve scripts can not contain NUL characters in strings, but mail |
107 | headers could contain MIME encoded NUL characters, which could never | |
108 | be matched by Sieve scripts using exact comparisons. For that reason, | |
109 | this implementation extends the Sieve quoted string syntax with \0 | |
110 | to describe a NUL character, violating \0 being the same as 0 in | |
1c59d63b | 111 | RFC 3028. |
495ae4b0 PH |
112 | |
113 | The folder specified by "fileinto" must not contain the character | |
1c59d63b | 114 | sequence ".." to avoid security problems. RFC 3028 does not specify the |
495ae4b0 PH |
115 | syntax of folders apart from keep being equivalent to fileinto "INBOX". |
116 | This implementation uses "inbox" instead. | |
117 | ||
118 | Sieve script errors currently cause that messages are silently filed into | |
119 | "inbox". RFC 3028 requires that the user is notified of that condition. | |
120 | This may be implemented in future by adding a header line to mails that | |
121 | are filed into "inbox" due to an error in the filter. | |
122 | ||
123 | ||
495ae4b0 PH |
124 | Semantics Of Keep |
125 | ||
126 | The keep command is equivalent to fileinto "inbox": It saves the | |
127 | message and resets the implicit keep flag. It does not set the | |
128 | implicit keep flag; there is no command to set it once it has | |
129 | been reset. | |
130 | ||
131 | ||
132 | Semantics of Fileinto | |
133 | ||
134 | RFC 3028 does not specify if "fileinto" tries to create a mail folder, | |
135 | in case it does not exist. This implementation allows to configure | |
136 | that aspect using the appendfile transport options "create_directory", | |
137 | "create_file" and "file_must_exist". See the appendfile transport in | |
138 | the Exim specification for details. | |
139 | ||
140 | ||
495ae4b0 PH |
141 | Sieve Syntax and Semantics |
142 | ||
143 | RFC 3028 confuses syntax and semantics sometimes. It uses a generic | |
1c59d63b PH |
144 | grammar as syntax for commands and tests and performs many checks during |
145 | semantic analysis. Syntax is specified by grammar rules, semantics | |
146 | by natural language, despite the latter often talking about syntax. | |
495ae4b0 PH |
147 | The intention was to provide a framework for the syntax that describes |
148 | current commands as well as future extensions, and describing commands | |
31c4e005 | 149 | by semantics. |
495ae4b0 | 150 | |
1c59d63b | 151 | The following replacement for section 8.2 gives two grammars, one for |
495ae4b0 PH |
152 | the framework, and one for specific commands, thus removing most of the |
153 | semantic analysis. Since the parser can not parse unsupported extensions, | |
1c59d63b PH |
154 | the result is strict error checking of any executed and not executed code |
155 | until "stop" is executed or the end of the script is reached. | |
495ae4b0 PH |
156 | |
157 | 8.2. Grammar | |
158 | ||
159 | The atoms of the grammar are lexical tokens. White space or comments may | |
160 | appear anywhere between lexical tokens, they are not part of the grammar. | |
161 | The grammar is specified in ABNF with two extensions to describe tagged | |
162 | arguments that can be reordered and grammar extensions: { } denotes a | |
163 | sequence of symbols that may appear in any order. Example: | |
164 | ||
1c59d63b PH |
165 | options = a b c |
166 | start = { options } | |
495ae4b0 PH |
167 | |
168 | is equivalent to: | |
169 | ||
1c59d63b | 170 | start = ( a b c ) / ( a c b ) / ( b a c ) / ( b c a ) / ( c a b ) / ( c b a ) |
495ae4b0 PH |
171 | |
172 | The symbol =) is used to append to a rule: | |
173 | ||
174 | start = a | |
175 | start =) b | |
176 | ||
177 | is equivalent to | |
178 | ||
179 | start = a b | |
180 | ||
181 | All Sieve commands, including extensions, MUST be words of the following | |
182 | generic grammar with the start symbol "start". They SHOULD be specified | |
183 | using a specific grammar, though. | |
184 | ||
185 | argument = string-list / number / tag | |
186 | arguments = *argument [test / test-list] | |
187 | block = "{" commands "}" | |
188 | commands = *command | |
189 | string = quoted-string / multi-line | |
190 | string-list = "[" string *("," string) "]" / string | |
191 | test = identifier arguments | |
192 | test-list = "(" test *("," test) ")" | |
193 | command = identifier arguments ( ";" / block ) | |
194 | start = command | |
195 | ||
196 | The basic Sieve commands are specified using the following grammar, which | |
197 | language is a subset of the generic grammar above. The start symbol is | |
198 | "start". | |
199 | ||
200 | address-part = ":localpart" / ":domain" / ":all" | |
201 | comparator = ":comparator" string | |
202 | match-type = ":is" / ":contains" / ":matches" | |
203 | string = quoted-string / multi-line | |
204 | string-list = "[" string *("," string) "]" / string | |
205 | address-test = "address" { [address-part] [comparator] [match-type] } | |
206 | string-list string-list | |
207 | test-list = "(" test *("," test) ")" | |
208 | allof-test = "allof" test-list | |
209 | anyof-test = "anyof" test-list | |
210 | exists-test = "exists" string-list | |
211 | false-test = "false" | |
212 | true=test = "true" | |
213 | header-test = "header" { [comparator] [match-type] } | |
214 | string-list string-list | |
215 | not-test = "not" test | |
216 | relop = ":over" / ":under" | |
217 | size-test = "size" relop number | |
218 | block = "{" commands "}" | |
219 | if-command = "if" test block *( "elsif" test block ) [ "else" block ] | |
220 | stop-command = "stop" { stop-options } ";" | |
221 | stop-options = | |
222 | keep-command = "keep" { keep-options } ";" | |
223 | keep-options = | |
224 | discard-command = "discard" { discard-options } ";" | |
225 | discard-options = | |
226 | redirect-command = "redirect" { redirect-options } string ";" | |
227 | redirect-options = | |
228 | require-command = "require" { require-options } string-list ";" | |
229 | require-options = | |
230 | test = address-test / allof-test / anyof-test / exists-test | |
231 | / false-test / true-test / header-test / not-test | |
232 | / size-test | |
233 | command = if-command / stop-command / keep-command | |
234 | / discard-command / redirect-command | |
235 | commands = *command | |
236 | start = *require-command commands | |
237 | ||
238 | The extensions "envelope" and "fileinto" are specified using the following | |
239 | grammar extension. | |
240 | ||
241 | envelope-test = "envelope" { [comparator] [address-part] [match-type] } | |
242 | string-list string-list | |
243 | test =/ envelope-test | |
244 | ||
245 | fileinto-command = "fileinto" { fileinto-options } string ";" | |
246 | fileinto-options = | |
247 | command =/ fileinto-command | |
248 | ||
249 | The extension "copy" is specified as: | |
250 | ||
251 | fileinto-options =) ":copy" | |
252 | redirect-options =) ":copy" | |
253 | ||
254 | ||
255 | The i;ascii-numeric Comparator | |
256 | ||
257 | RFC 2244 describes this comparator and specifies that non-numeric strings | |
258 | are considered equal with an ordinal value higher than any numeric string. | |
259 | Although not stated explicitly, this includes the empty string. A range | |
260 | of at least 2^31 is required. This implementation does not limit the | |
261 | range, because it does not convert numbers to binary representation | |
262 | before comparing them. | |
263 | ||
264 | ||
265 | The vacation extension | |
266 | ||
267 | The extension "vacation" is specified using the following grammar | |
268 | extension. | |
269 | ||
270 | vacation-command = "vacation" { vacation-options } <reason: string> | |
271 | vacation-options = [":days" number] | |
495ae4b0 | 272 | [":subject" string] |
f656d135 PH |
273 | [":from" string] |
274 | [":addresses" string-list] | |
495ae4b0 | 275 | [":mime"] |
f656d135 | 276 | [":handle" string] |
495ae4b0 PH |
277 | command =/ vacation-command |
278 | ||
279 | ||
280 | Semantics Of ":mime" | |
281 | ||
f656d135 PH |
282 | The draft does not specify how strings using MIME entities are used |
283 | to compose messages. As a result, different implementations generate | |
284 | different mails. The Exim Sieve implementation splits the reason into | |
285 | header and body. It adds the header to the mail header and uses the body | |
286 | as mail body. Be aware, that other imlementations compose a multipart | |
287 | structure with the reason as only part. Both conform to the specification | |
288 | (or lack thereof). | |
495ae4b0 PH |
289 | |
290 | ||
291 | Semantics Of Not Using ":mime" | |
292 | ||
293 | Sieve scripts are written in UTF-8, so is the reason string in this | |
294 | case. This implementation adds MIME headers to indicate that. This | |
295 | is not required by the vacation draft, which does not specify how | |
296 | the UTF-8 reason is processed to compose the resulting message. | |
297 | ||
298 | ||
495ae4b0 PH |
299 | Default Subject |
300 | ||
5ea81592 PH |
301 | The draft specifies that the default message subject is "Auto: " plus |
302 | the old subject. Using this subject is dangerous, because many mailing | |
303 | lists verify addresses by sending a secret key in the subject of a | |
304 | message, asking to reply to the message for confirmation. Using the | |
305 | default vacation subject confirms any subscription request of this kind, | |
306 | allowing to subscribe a third party to any mailing list, either to annoy | |
307 | the user or to declare spam as legitimate mail by proving to use opt-in. | |
495ae4b0 PH |
308 | |
309 | ||
310 | Rate Limiting Responses | |
311 | ||
f656d135 PH |
312 | In absence of a handle, this implementation hashes the reason, |
313 | ":subject" option, ":mime" option and ":from" option and uses the hex | |
314 | string representation as filename within the "sieve_vacation_directory" | |
315 | to store the recipient addresses for this vacation parameter set. | |
495ae4b0 PH |
316 | |
317 | The draft specifies that sites may define a minimum ":days" value than 1. | |
318 | This implementation uses 1. The maximum value MUST greater than 7, | |
319 | and SHOULD be greater than 30. This implementation uses a maximum of 31. | |
320 | ||
321 | Vacation recipient address databases older than 31 days are automatically | |
322 | removed. Users do not have to remove them manually when modifying their | |
323 | scripts. Don't put anything but vacation databases in that directory | |
324 | or you risk that it will be removed, too! | |
325 | ||
326 | ||
327 | Global Reply Address Blacklist | |
328 | ||
329 | The draft requires that each implementation offers a global black list | |
330 | of addresses that will never be replied to. Exim offers this as option | |
331 | "never_mail" in the autoreply transport. |