1 $Cambridge: exim/doc/doc-txt/README.SIEVE,v 1.8 2005/11/14 11:41:23 ph10 Exp $
3 Notes on the Sieve implementation for Exim
5 Exim Filter Versus Sieve Filter
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
12 The Exim filter contains more features, such as variable expansion, and
13 better integration with the host environment, like external processes
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.
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-04.txt) extension, the
27 "i;ascii-numeric" comparator (RFC 2244).
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
33 in the transport that stores it. The following routers and transport
34 show a typical use of Sieve:
40 domains = +localdomains
41 local_part_suffix = "-*"
42 local_part_suffix_optional
44 require_files = $home/.forward
49 domains = +localdomains
50 local_part_suffix = "-*"
51 local_part_suffix_optional
52 sieve_subaddress = "${sg{$local_part_suffix}{^-}{}}"
53 sieve_useraddress = "$local_part"
55 require_files = $home/.forward
59 file_transport = localuser
60 reply_transport = vacation
61 sieve_vacation_directory = $home/mail/vacation
68 file = ${if eq{$address_file}{inbox} \
69 {/var/mail/$local_part} \
70 {${if eq{${substr_0_1:$address_file}}{/} \
72 {$home/mail/$address_file} \
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
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
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.
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
113 The folder specified by "fileinto" must not contain the character
114 sequence ".." to avoid security problems. RFC 3028 does not specify the
115 syntax of folders apart from keep being equivalent to fileinto "INBOX".
116 This implementation uses "inbox" instead.
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.
123 The automatic replies generated by "vacation" do not contain an updated
124 "references" header field.
129 The keep command is equivalent to fileinto "inbox": It saves the
130 message and resets the implicit keep flag. It does not set the
131 implicit keep flag; there is no command to set it once it has
135 Semantics of Fileinto
137 RFC 3028 does not specify if "fileinto" tries to create a mail folder,
138 in case it does not exist. This implementation allows to configure
139 that aspect using the appendfile transport options "create_directory",
140 "create_file" and "file_must_exist". See the appendfile transport in
141 the Exim specification for details.
144 Sieve Syntax and Semantics
146 RFC 3028 confuses syntax and semantics sometimes. It uses a generic
147 grammar as syntax for commands and tests and performs many checks during
148 semantic analysis. Syntax is specified by grammar rules, semantics
149 by natural language, despite the latter often talking about syntax.
150 The intention was to provide a framework for the syntax that describes
151 current commands as well as future extensions, and describing commands
154 The following replacement for section 8.2 gives two grammars, one for
155 the framework, and one for specific commands, thus removing most of the
156 semantic analysis. Since the parser can not parse unsupported extensions,
157 the result is strict error checking of any executed and not executed code
158 until "stop" is executed or the end of the script is reached.
162 The atoms of the grammar are lexical tokens. White space or comments may
163 appear anywhere between lexical tokens, they are not part of the grammar.
164 The grammar is specified in ABNF with two extensions to describe tagged
165 arguments that can be reordered and grammar extensions: { } denotes a
166 sequence of symbols that may appear in any order. Example:
173 start = ( a b c ) / ( a c b ) / ( b a c ) / ( b c a ) / ( c a b ) / ( c b a )
175 The symbol =) is used to append to a rule:
184 All Sieve commands, including extensions, MUST be words of the following
185 generic grammar with the start symbol "start". They SHOULD be specified
186 using a specific grammar, though.
188 argument = string-list / number / tag
189 arguments = *argument [test / test-list]
190 block = "{" commands "}"
192 string = quoted-string / multi-line
193 string-list = "[" string *("," string) "]" / string
194 test = identifier arguments
195 test-list = "(" test *("," test) ")"
196 command = identifier arguments ( ";" / block )
199 The basic Sieve commands are specified using the following grammar, which
200 language is a subset of the generic grammar above. The start symbol is
203 address-part = ":localpart" / ":domain" / ":all"
204 comparator = ":comparator" string
205 match-type = ":is" / ":contains" / ":matches"
206 string = quoted-string / multi-line
207 string-list = "[" string *("," string) "]" / string
208 address-test = "address" { [address-part] [comparator] [match-type] }
209 string-list string-list
210 test-list = "(" test *("," test) ")"
211 allof-test = "allof" test-list
212 anyof-test = "anyof" test-list
213 exists-test = "exists" string-list
216 header-test = "header" { [comparator] [match-type] }
217 string-list string-list
218 not-test = "not" test
219 relop = ":over" / ":under"
220 size-test = "size" relop number
221 block = "{" commands "}"
222 if-command = "if" test block *( "elsif" test block ) [ "else" block ]
223 stop-command = "stop" { stop-options } ";"
225 keep-command = "keep" { keep-options } ";"
227 discard-command = "discard" { discard-options } ";"
229 redirect-command = "redirect" { redirect-options } string ";"
231 require-command = "require" { require-options } string-list ";"
233 test = address-test / allof-test / anyof-test / exists-test
234 / false-test / true-test / header-test / not-test
236 command = if-command / stop-command / keep-command
237 / discard-command / redirect-command
239 start = *require-command commands
241 The extensions "envelope" and "fileinto" are specified using the following
244 envelope-test = "envelope" { [comparator] [address-part] [match-type] }
245 string-list string-list
246 test =/ envelope-test
248 fileinto-command = "fileinto" { fileinto-options } string ";"
250 command =/ fileinto-command
252 The extension "copy" is specified as:
254 fileinto-options =) ":copy"
255 redirect-options =) ":copy"
258 The i;ascii-numeric Comparator
260 RFC 2244 describes this comparator and specifies that non-numeric strings
261 are considered equal with an ordinal value higher than any numeric string.
262 Although not stated explicitly, this includes the empty string. A range
263 of at least 2^31 is required. This implementation does not limit the
264 range, because it does not convert numbers to binary representation
265 before comparing them.
268 The vacation extension
270 The extension "vacation" is specified using the following grammar
273 vacation-command = "vacation" { vacation-options } <reason: string>
274 vacation-options = [":days" number]
277 [":addresses" string-list]
280 command =/ vacation-command
285 The draft does not specify how strings using MIME entities are used
286 to compose messages. As a result, different implementations generate
287 different mails. The Exim Sieve implementation splits the reason into
288 header and body. It adds the header to the mail header and uses the body
289 as mail body. Be aware, that other imlementations compose a multipart
290 structure with the reason as only part. Both conform to the specification
294 Semantics Of Not Using ":mime"
296 Sieve scripts are written in UTF-8, so is the reason string in this
297 case. This implementation adds MIME headers to indicate that. This
298 is not required by the vacation draft, which does not specify how
299 the UTF-8 reason is processed to compose the resulting message.
304 The draft specifies that the default message subject is "Auto: " plus
305 the old subject. Using this subject is dangerous, because many mailing
306 lists verify addresses by sending a secret key in the subject of a
307 message, asking to reply to the message for confirmation. Using the
308 default vacation subject confirms any subscription request of this kind,
309 allowing to subscribe a third party to any mailing list, either to annoy
310 the user or to declare spam as legitimate mail by proving to use opt-in.
313 Rate Limiting Responses
315 In absence of a handle, this implementation hashes the reason,
316 ":subject" option, ":mime" option and ":from" option and uses the hex
317 string representation as filename within the "sieve_vacation_directory"
318 to store the recipient addresses for this vacation parameter set.
320 The draft specifies that sites may define a minimum ":days" value than 1.
321 This implementation uses 1. The maximum value MUST greater than 7,
322 and SHOULD be greater than 30. This implementation uses a maximum of 31.
324 Vacation recipient address databases older than 31 days are automatically
325 removed. Users do not have to remove them manually when modifying their
326 scripts. Don't put anything but vacation databases in that directory
327 or you risk that it will be removed, too!
330 Global Reply Address Blacklist
332 The draft requires that each implementation offers a global black list
333 of addresses that will never be replied to. Exim offers this as option
334 "never_mail" in the autoreply transport.