rfc5182.Sieve_and_extensions.txt 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355
  1. Network Working Group P. Guenther, Ed.
  2. Request for Comments: 5228 Sendmail, Inc.
  3. Obsoletes: 3028 T. Showalter, Ed.
  4. Category: Standards Track January 2008
  5. Sieve: An Email Filtering Language
  6. Status of This Memo
  7. This document specifies an Internet standards track protocol for the
  8. Internet community, and requests discussion and suggestions for
  9. improvements. Please refer to the current edition of the "Internet
  10. Official Protocol Standards" (STD 1) for the standardization state
  11. and status of this protocol. Distribution of this memo is unlimited.
  12. Abstract
  13. This document describes a language for filtering email messages at
  14. time of final delivery. It is designed to be implementable on either
  15. a mail client or mail server. It is meant to be extensible, simple,
  16. and independent of access protocol, mail architecture, and operating
  17. system. It is suitable for running on a mail server where users may
  18. not be allowed to execute arbitrary programs, such as on black box
  19. Internet Message Access Protocol (IMAP) servers, as the base language
  20. has no variables, loops, or ability to shell out to external
  21. programs.
  22. Guenther & Showalter Standards Track [Page 1]
  23. RFC 5228 Sieve: An Email Filtering Language January 2008
  24. Table of Contents
  25. 1. Introduction ....................................................4
  26. 1.1. Conventions Used in This Document ..........................4
  27. 1.2. Example Mail Messages ......................................5
  28. 2. Design ..........................................................6
  29. 2.1. Form of the Language .......................................6
  30. 2.2. Whitespace .................................................7
  31. 2.3. Comments ...................................................7
  32. 2.4. Literal Data ...............................................7
  33. 2.4.1. Numbers .............................................7
  34. 2.4.2. Strings .............................................8
  35. 2.4.2.1. String Lists ...............................9
  36. 2.4.2.2. Headers ....................................9
  37. 2.4.2.3. Addresses .................................10
  38. 2.4.2.4. Encoding Characters Using
  39. "encoded-character" .......................10
  40. 2.5. Tests .....................................................11
  41. 2.5.1. Test Lists .........................................12
  42. 2.6. Arguments .................................................12
  43. 2.6.1. Positional Arguments ...............................12
  44. 2.6.2. Tagged Arguments ...................................12
  45. 2.6.3. Optional Arguments .................................13
  46. 2.6.4. Types of Arguments .................................13
  47. 2.7. String Comparison .........................................13
  48. 2.7.1. Match Type .........................................14
  49. 2.7.2. Comparisons across Character Sets ..................15
  50. 2.7.3. Comparators ........................................15
  51. 2.7.4. Comparisons against Addresses ......................16
  52. 2.8. Blocks ....................................................17
  53. 2.9. Commands ..................................................17
  54. 2.10. Evaluation ...............................................18
  55. 2.10.1. Action Interaction ................................18
  56. 2.10.2. Implicit Keep .....................................18
  57. 2.10.3. Message Uniqueness in a Mailbox ...................19
  58. 2.10.4. Limits on Numbers of Actions ......................19
  59. 2.10.5. Extensions and Optional Features ..................19
  60. 2.10.6. Errors ............................................20
  61. 2.10.7. Limits on Execution ...............................20
  62. 3. Control Commands ...............................................21
  63. 3.1. Control if ................................................21
  64. 3.2. Control require ...........................................22
  65. 3.3. Control stop ..............................................22
  66. 4. Action Commands ................................................23
  67. 4.1. Action fileinto ...........................................23
  68. 4.2. Action redirect ...........................................23
  69. 4.3. Action keep ...............................................24
  70. 4.4. Action discard ............................................25
  71. Guenther & Showalter Standards Track [Page 2]
  72. RFC 5228 Sieve: An Email Filtering Language January 2008
  73. 5. Test Commands ..................................................26
  74. 5.1. Test address ..............................................26
  75. 5.2. Test allof ................................................27
  76. 5.3. Test anyof ................................................27
  77. 5.4. Test envelope .............................................27
  78. 5.5. Test exists ...............................................28
  79. 5.6. Test false ................................................28
  80. 5.7. Test header ...............................................29
  81. 5.8. Test not ..................................................29
  82. 5.9. Test size .................................................29
  83. 5.10. Test true ................................................30
  84. 6. Extensibility ..................................................30
  85. 6.1. Capability String .........................................31
  86. 6.2. IANA Considerations .......................................31
  87. 6.2.1. Template for Capability Registrations ..............32
  88. 6.2.2. Handling of Existing Capability Registrations ......32
  89. 6.2.3. Initial Capability Registrations ...................32
  90. 6.3. Capability Transport ......................................33
  91. 7. Transmission ...................................................33
  92. 8. Parsing ........................................................34
  93. 8.1. Lexical Tokens ............................................34
  94. 8.2. Grammar ...................................................36
  95. 8.3. Statement Elements ........................................36
  96. 9. Extended Example ...............................................37
  97. 10. Security Considerations .......................................38
  98. 11. Acknowledgments ...............................................39
  99. 12. Normative References ..........................................39
  100. 13. Informative References ........................................40
  101. 14. Changes from RFC 3028 .........................................41
  102. Guenther & Showalter Standards Track [Page 3]
  103. RFC 5228 Sieve: An Email Filtering Language January 2008
  104. 1. Introduction
  105. This memo documents a language that can be used to create filters for
  106. electronic mail. It is not tied to any particular operating system
  107. or mail architecture. It requires the use of [IMAIL]-compliant
  108. messages, but should otherwise generalize to many systems.
  109. The language is powerful enough to be useful but limited in order to
  110. allow for a safe server-side filtering system. The intention is to
  111. make it impossible for users to do anything more complex (and
  112. dangerous) than write simple mail filters, along with facilitating
  113. the use of graphical user interfaces (GUIs) for filter creation and
  114. manipulation. The base language was not designed to be Turing-
  115. complete: it does not have a loop control structure or functions.
  116. Scripts written in Sieve are executed during final delivery, when the
  117. message is moved to the user-accessible mailbox. In systems where
  118. the Mail Transfer Agent (MTA) does final delivery, such as
  119. traditional Unix mail, it is reasonable to filter when the MTA
  120. deposits mail into the user's mailbox.
  121. There are a number of reasons to use a filtering system. Mail
  122. traffic for most users has been increasing due to increased usage of
  123. email, the emergence of unsolicited email as a form of advertising,
  124. and increased usage of mailing lists.
  125. Experience at Carnegie Mellon has shown that if a filtering system is
  126. made available to users, many will make use of it in order to file
  127. messages from specific users or mailing lists. However, many others
  128. did not make use of the Andrew system's FLAMES filtering language
  129. [FLAMES] due to difficulty in setting it up.
  130. Because of the expectation that users will make use of filtering if
  131. it is offered and easy to use, this language has been made simple
  132. enough to allow many users to make use of it, but rich enough that it
  133. can be used productively. However, it is expected that GUI-based
  134. editors will be the preferred way of editing filters for a large
  135. number of users.
  136. 1.1. Conventions Used in This Document
  137. In the sections of this document that discuss the requirements of
  138. various keywords and operators, the following conventions have been
  139. adopted.
  140. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
  141. "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
  142. document are to be interpreted as described in [KEYWORDS].
  143. Guenther & Showalter Standards Track [Page 4]
  144. RFC 5228 Sieve: An Email Filtering Language January 2008
  145. Each section on a command (test, action, or control) has a line
  146. labeled "Usage:". This line describes the usage of the command,
  147. including its name and its arguments. Required arguments are listed
  148. inside angle brackets ("<" and ">"). Optional arguments are listed
  149. inside square brackets ("[" and "]"). Each argument is followed by
  150. its type, so "<key: string>" represents an argument called "key" that
  151. is a string. Literal strings are represented with double-quoted
  152. strings. Alternatives are separated with slashes, and parentheses
  153. are used for grouping, similar to [ABNF].
  154. In the "Usage:" line, there are three special pieces of syntax that
  155. are frequently repeated, MATCH-TYPE, COMPARATOR, and ADDRESS-PART.
  156. These are discussed in sections 2.7.1, 2.7.3, and 2.7.4,
  157. respectively.
  158. The formal grammar for these commands is defined in section 8 and is
  159. the authoritative reference on how to construct commands, but the
  160. formal grammar does not specify the order, semantics, number or types
  161. of arguments to commands, or the legal command names. The intent is
  162. to allow for extension without changing the grammar.
  163. 1.2. Example Mail Messages
  164. The following mail messages will be used throughout this document in
  165. examples.
  166. Message A
  167. -----------------------------------------------------------
  168. Date: Tue, 1 Apr 1997 09:06:31 -0800 (PST)
  169. From: coyote@desert.example.org
  170. To: roadrunner@acme.example.com
  171. Subject: I have a present for you
  172. Look, I'm sorry about the whole anvil thing, and I really
  173. didn't mean to try and drop it on you from the top of the
  174. cliff. I want to try to make it up to you. I've got some
  175. great birdseed over here at my place--top of the line
  176. stuff--and if you come by, I'll have it all wrapped up
  177. for you. I'm really sorry for all the problems I've caused
  178. for you over the years, but I know we can work this out.
  179. --
  180. Wile E. Coyote "Super Genius" coyote@desert.example.org
  181. -----------------------------------------------------------
  182. Guenther & Showalter Standards Track [Page 5]
  183. RFC 5228 Sieve: An Email Filtering Language January 2008
  184. Message B
  185. -----------------------------------------------------------
  186. From: youcouldberich!@reply-by-postal-mail.invalid
  187. Sender: b1ff@de.res.example.com
  188. To: rube@landru.example.com
  189. Date: Mon, 31 Mar 1997 18:26:10 -0800
  190. Subject: $$$ YOU, TOO, CAN BE A MILLIONAIRE! $$$
  191. YOU MAY HAVE ALREADY WON TEN MILLION DOLLARS, BUT I DOUBT
  192. IT! SO JUST POST THIS TO SIX HUNDRED NEWSGROUPS! IT WILL
  193. GUARANTEE THAT YOU GET AT LEAST FIVE RESPONSES WITH MONEY!
  194. MONEY! MONEY! COLD HARD CASH! YOU WILL RECEIVE OVER
  195. $20,000 IN LESS THAN TWO MONTHS! AND IT'S LEGAL!!!!!!!!!
  196. !!!!!!!!!!!!!!!!!!111111111!!!!!!!11111111111!!1 JUST
  197. SEND $5 IN SMALL, UNMARKED BILLS TO THE ADDRESSES BELOW!
  198. -----------------------------------------------------------
  199. 2. Design
  200. 2.1. Form of the Language
  201. The language consists of a set of commands. Each command consists of
  202. a set of tokens delimited by whitespace. The command identifier is
  203. the first token and it is followed by zero or more argument tokens.
  204. Arguments may be literal data, tags, blocks of commands, or test
  205. commands.
  206. With the exceptions of strings and comments, the language is limited
  207. to US-ASCII characters. Strings and comments may contain octets
  208. outside the US-ASCII range. Specifically, they will normally be in
  209. UTF-8, as specified in [UTF-8]. NUL (US-ASCII 0) is never permitted
  210. in scripts, while CR and LF can only appear as the CRLF line ending.
  211. Note: While this specification permits arbitrary octets to appear
  212. in Sieve scripts inside strings and comments, this has made it
  213. difficult to robustly handle Sieve scripts in programs that are
  214. sensitive to the encodings used. The "encoded-character"
  215. capability (section 2.4.2.4) provides an alternative means of
  216. representing such octets in strings using just US-ASCII
  217. characters. As such, the use of non-UTF-8 text in scripts should
  218. be considered a deprecated feature that may be abandoned.
  219. Tokens other than strings are considered case-insensitive.
  220. Guenther & Showalter Standards Track [Page 6]
  221. RFC 5228 Sieve: An Email Filtering Language January 2008
  222. 2.2. Whitespace
  223. Whitespace is used to separate tokens. Whitespace is made up of
  224. tabs, newlines (CRLF, never just CR or LF), and the space character.
  225. The amount of whitespace used is not significant.
  226. 2.3. Comments
  227. Two types of comments are offered. Comments are semantically
  228. equivalent to whitespace and can be used anyplace that whitespace is
  229. (with one exception in multi-line strings, as described in the
  230. grammar).
  231. Hash comments begin with a "#" character that is not contained within
  232. a string and continue until the next CRLF.
  233. Example: if size :over 100k { # this is a comment
  234. discard;
  235. }
  236. Bracketed comments begin with the token "/*" and end with "*/"
  237. outside of a string. Bracketed comments may span multiple lines.
  238. Bracketed comments do not nest.
  239. Example: if size :over 100K { /* this is a comment
  240. this is still a comment */ discard /* this is a comment
  241. */ ;
  242. }
  243. 2.4. Literal Data
  244. Literal data means data that is not executed, merely evaluated "as
  245. is", to be used as arguments to commands. Literal data is limited to
  246. numbers, strings, and string lists.
  247. 2.4.1. Numbers
  248. Numbers are given as ordinary decimal numbers. As a shorthand for
  249. expressing larger values, such as message sizes, a suffix of "K",
  250. "M", or "G" MAY be appended to indicate a multiple of a power of two.
  251. To be comparable with the power-of-two-based versions of SI units
  252. that computers frequently use, "K" specifies kibi-, or 1,024 (2^10)
  253. times the value of the number; "M" specifies mebi-, or 1,048,576
  254. (2^20) times the value of the number; and "G" specifies gibi-, or
  255. 1,073,741,824 (2^30) times the value of the number [BINARY-SI].
  256. Guenther & Showalter Standards Track [Page 7]
  257. RFC 5228 Sieve: An Email Filtering Language January 2008
  258. Implementations MUST support integer values in the inclusive range
  259. zero to 2,147,483,647 (2^31 - 1), but MAY support larger values.
  260. Only non-negative integers are permitted by this specification.
  261. 2.4.2. Strings
  262. Scripts involve large numbers of string values as they are used for
  263. pattern matching, addresses, textual bodies, etc. Typically, short
  264. quoted strings suffice for most uses, but a more convenient form is
  265. provided for longer strings such as bodies of messages.
  266. A quoted string starts and ends with a single double quote (the <">
  267. character, US-ASCII 34). A backslash ("\", US-ASCII 92) inside of a
  268. quoted string is followed by either another backslash or a double
  269. quote. These two-character sequences represent a single backslash or
  270. double quote within the value, respectively.
  271. Scripts SHOULD NOT escape other characters with a backslash.
  272. An undefined escape sequence (such as "\a" in a context where "a" has
  273. no special meaning) is interpreted as if there were no backslash (in
  274. this case, "\a" is just "a"), though that may be changed by
  275. extensions.
  276. Non-printing characters such as tabs, CRLF, and control characters
  277. are permitted in quoted strings. Quoted strings MAY span multiple
  278. lines. An unencoded NUL (US-ASCII 0) is not allowed in strings; see
  279. section 2.4.2.4 for how it can be encoded.
  280. As message header data is converted to [UTF-8] for comparison (see
  281. section 2.7.2), most string values will use the UTF-8 encoding.
  282. However, implementations MUST accept all strings that match the
  283. grammar in section 8. The ability to use non-UTF-8 encoded strings
  284. matches existing practice and has proven to be useful both in tests
  285. for invalid data and in arguments containing raw MIME parts for
  286. extension actions that generate outgoing messages.
  287. For entering larger amounts of text, such as an email message, a
  288. multi-line form is allowed. It starts with the keyword "text:",
  289. followed by a CRLF, and ends with the sequence of a CRLF, a single
  290. period, and another CRLF. The CRLF before the final period is
  291. considered part of the value. In order to allow the message to
  292. contain lines with a single dot, lines are dot-stuffed. That is,
  293. when composing a message body, an extra '.' is added before each line
  294. that begins with a '.'. When the server interprets the script, these
  295. extra dots are removed. Note that a line that begins with a dot
  296. followed by a non-dot character is not interpreted as dot-stuffed;
  297. Guenther & Showalter Standards Track [Page 8]
  298. RFC 5228 Sieve: An Email Filtering Language January 2008
  299. that is, ".foo" is interpreted as ".foo". However, because this is
  300. potentially ambiguous, scripts SHOULD be properly dot-stuffed so such
  301. lines do not appear.
  302. Note that a hashed comment or whitespace may occur in between the
  303. "text:" and the CRLF, but not within the string itself. Bracketed
  304. comments are not allowed here.
  305. 2.4.2.1. String Lists
  306. When matching patterns, it is frequently convenient to match against
  307. groups of strings instead of single strings. For this reason, a list
  308. of strings is allowed in many tests, implying that if the test is
  309. true using any one of the strings, then the test is true.
  310. For instance, the test 'header :contains ["To", "Cc"]
  311. ["me@example.com", "me00@landru.example.com"]' is true if either a To
  312. header or Cc header of the input message contains either of the email
  313. addresses "me@example.com" or "me00@landru.example.com".
  314. Conversely, in any case where a list of strings is appropriate, a
  315. single string is allowed without being a member of a list: it is
  316. equivalent to a list with a single member. This means that the test
  317. 'exists "To"' is equivalent to the test 'exists ["To"]'.
  318. 2.4.2.2. Headers
  319. Headers are a subset of strings. In the Internet Message
  320. Specification [IMAIL], each header line is allowed to have whitespace
  321. nearly anywhere in the line, including after the field name and
  322. before the subsequent colon. Extra spaces between the header name
  323. and the ":" in a header field are ignored.
  324. A header name never contains a colon. The "From" header refers to a
  325. line beginning "From:" (or "From :", etc.). No header will match
  326. the string "From:" due to the trailing colon.
  327. Similarly, no header will match a syntactically invalid header name.
  328. An implementation MUST NOT cause an error for syntactically invalid
  329. header names in tests.
  330. Header lines are unfolded as described in [IMAIL] section 2.2.3.
  331. Interpretation of header data SHOULD be done according to [MIME3]
  332. section 6.2 (see section 2.7.2 below for details).
  333. Guenther & Showalter Standards Track [Page 9]
  334. RFC 5228 Sieve: An Email Filtering Language January 2008
  335. 2.4.2.3. Addresses
  336. A number of commands call for email addresses, which are also a
  337. subset of strings. When these addresses are used in outbound
  338. contexts, addresses must be compliant with [IMAIL], but are further
  339. constrained within this document. Using the symbols defined in
  340. [IMAIL], section 3, the syntax of an address is:
  341. sieve-address = addr-spec ; simple address
  342. / phrase "<" addr-spec ">" ; name & addr-spec
  343. That is, routes and group syntax are not permitted. If multiple
  344. addresses are required, use a string list. Named groups are not
  345. permitted.
  346. It is an error for a script to execute an action with a value for use
  347. as an outbound address that doesn't match the "sieve-address" syntax.
  348. 2.4.2.4. Encoding Characters Using "encoded-character"
  349. When the "encoded-character" extension is in effect, certain
  350. character sequences in strings are replaced by their decoded value.
  351. This happens after escape sequences are interpreted and dot-
  352. unstuffing has been done. Implementations SHOULD support "encoded-
  353. character".
  354. Arbitrary octets can be embedded in strings by using the syntax
  355. encoded-arb-octets. The sequence is replaced by the octets with the
  356. hexadecimal values given by each hex-pair.
  357. blank = WSP / CRLF
  358. encoded-arb-octets = "${hex:" hex-pair-seq "}"
  359. hex-pair-seq = *blank hex-pair *(1*blank hex-pair) *blank
  360. hex-pair = 1*2HEXDIG
  361. Where WSP and HEXDIG non-terminals are defined in Appendix B.1 of
  362. [ABNF].
  363. It may be inconvenient or undesirable to enter Unicode characters
  364. verbatim, and for these cases the syntax encoded-unicode-char can be
  365. used. The sequence is replaced by the UTF-8 encoding of the
  366. specified Unicode characters, which are identified by the hexadecimal
  367. value of unicode-hex.
  368. encoded-unicode-char = "${unicode:" unicode-hex-seq "}"
  369. unicode-hex-seq = *blank unicode-hex
  370. *(1*blank unicode-hex) *blank
  371. unicode-hex = 1*HEXDIG
  372. Guenther & Showalter Standards Track [Page 10]
  373. RFC 5228 Sieve: An Email Filtering Language January 2008
  374. It is an error for a script to use a hexadecimal value that isn't in
  375. either the range 0 to D7FF or the range E000 to 10FFFF. (The range
  376. D800 to DFFF is excluded as those character numbers are only used as
  377. part of the UTF-16 encoding form and are not applicable to the UTF-8
  378. encoding that the syntax here represents.)
  379. Note: Implementations MUST NOT raise an error for an out-of-range
  380. Unicode value unless the sequence containing it is well-formed
  381. according to the grammar.
  382. The capability string for use with the require command is "encoded-
  383. character".
  384. In the following script, message B is discarded, since the specified
  385. test string is equivalent to "$$$".
  386. Example: require "encoded-character";
  387. if header :contains "Subject" "$${hex:24 24}" {
  388. discard;
  389. }
  390. The following examples demonstrate valid and invalid encodings and
  391. how they are handled:
  392. "$${hex:40}" -> "$@"
  393. "${hex: 40 }" -> "@"
  394. "${HEX: 40}" -> "@"
  395. "${hex:40" -> "${hex:40"
  396. "${hex:400}" -> "${hex:400}"
  397. "${hex:4${hex:30}}" -> "${hex:40}"
  398. "${unicode:40}" -> "@"
  399. "${ unicode:40}" -> "${ unicode:40}"
  400. "${UNICODE:40}" -> "@"
  401. "${UnICoDE:0000040}" -> "@"
  402. "${Unicode:40}" -> "@"
  403. "${Unicode:Cool}" -> "${Unicode:Cool}"
  404. "${unicode:200000}" -> error
  405. "${Unicode:DF01} -> error
  406. 2.5. Tests
  407. Tests are given as arguments to commands in order to control their
  408. actions. In this document, tests are given to if/elsif to decide
  409. which block of code is run.
  410. Guenther & Showalter Standards Track [Page 11]
  411. RFC 5228 Sieve: An Email Filtering Language January 2008
  412. 2.5.1. Test Lists
  413. Some tests ("allof" and "anyof", which implement logical "and" and
  414. logical "or", respectively) may require more than a single test as an
  415. argument. The test-list syntax element provides a way of grouping
  416. tests as a comma-separated list in parentheses.
  417. Example: if anyof (not exists ["From", "Date"],
  418. header :contains "from" "fool@example.com") {
  419. discard;
  420. }
  421. 2.6. Arguments
  422. In order to specify what to do, most commands take arguments. There
  423. are three types of arguments: positional, tagged, and optional.
  424. It is an error for a script, on a single command, to use conflicting
  425. arguments or to use a tagged or optional argument more than once.
  426. 2.6.1. Positional Arguments
  427. Positional arguments are given to a command that discerns their
  428. meaning based on their order. When a command takes positional
  429. arguments, all positional arguments must be supplied and must be in
  430. the order prescribed.
  431. 2.6.2. Tagged Arguments
  432. This document provides for tagged arguments in the style of
  433. CommonLISP. These are also similar to flags given to commands in
  434. most command-line systems.
  435. A tagged argument is an argument for a command that begins with ":"
  436. followed by a tag naming the argument, such as ":contains". This
  437. argument means that zero or more of the next tokens have some
  438. particular meaning depending on the argument. These next tokens may
  439. be literal data, but they are never blocks.
  440. Tagged arguments are similar to positional arguments, except that
  441. instead of the meaning being derived from the command, it is derived
  442. from the tag.
  443. Tagged arguments must appear before positional arguments, but they
  444. may appear in any order with other tagged arguments. For simplicity
  445. of the specification, this is not expressed in the syntax definitions
  446. Guenther & Showalter Standards Track [Page 12]
  447. RFC 5228 Sieve: An Email Filtering Language January 2008
  448. with commands, but they still may be reordered arbitrarily provided
  449. they appear before positional arguments. Tagged arguments may be
  450. mixed with optional arguments.
  451. Tagged arguments SHOULD NOT take tagged arguments as arguments.
  452. 2.6.3. Optional Arguments
  453. Optional arguments are exactly like tagged arguments except that they
  454. may be left out, in which case a default value is implied. Because
  455. optional arguments tend to result in shorter scripts, they have been
  456. used far more than tagged arguments.
  457. One particularly noteworthy case is the ":comparator" argument, which
  458. allows the user to specify which comparator [COLLATION] will be used
  459. to compare two strings, since different languages may impose
  460. different orderings on UTF-8 [UTF-8] strings.
  461. 2.6.4. Types of Arguments
  462. Abstractly, arguments may be literal data, tests, or blocks of
  463. commands. In this way, an "if" control structure is merely a command
  464. that happens to take a test and a block as arguments and may execute
  465. the block of code.
  466. However, this abstraction is ambiguous from a parsing standpoint.
  467. The grammar in section 8.2 presents a parsable version of this:
  468. Arguments are string lists (string-lists), numbers, and tags, which
  469. may be followed by a test or a test list (test-list), which may be
  470. followed by a block of commands. No more than one test or test list,
  471. or more than one block of commands, may be used, and commands that
  472. end with a block of commands do not end with semicolons.
  473. 2.7. String Comparison
  474. When matching one string against another, there are a number of ways
  475. of performing the match operation. These are accomplished with three
  476. types of matches: an exact match, a substring match, and a wildcard
  477. glob-style match. These are described below.
  478. In order to provide for matches between character sets and case
  479. insensitivity, Sieve uses the comparators defined in the Internet
  480. Application Protocol Collation Registry [COLLATION].
  481. Guenther & Showalter Standards Track [Page 13]
  482. RFC 5228 Sieve: An Email Filtering Language January 2008
  483. However, when a string represents the name of a header, the
  484. comparator is never user-specified. Header comparisons are always
  485. done with the "i;ascii-casemap" operator, i.e., case-insensitive
  486. comparisons, because this is the way things are defined in the
  487. message specification [IMAIL].
  488. 2.7.1. Match Type
  489. Commands that perform string comparisons may have an optional match
  490. type argument. The three match types in this specification are
  491. ":contains", ":is", and ":matches".
  492. The ":contains" match type describes a substring match. If the value
  493. argument contains the key argument as a substring, the match is true.
  494. For instance, the string "frobnitzm" contains "frob" and "nit", but
  495. not "fbm". The empty key ("") is contained in all values.
  496. The ":is" match type describes an absolute match; if the contents of
  497. the first string are absolutely the same as the contents of the
  498. second string, they match. Only the string "frobnitzm" is the string
  499. "frobnitzm". The empty key ("") only ":is" matches with the empty
  500. value.
  501. The ":matches" match type specifies a wildcard match using the
  502. characters "*" and "?"; the entire value must be matched. "*"
  503. matches zero or more characters in the value and "?" matches a single
  504. character in the value, where the comparator that is used (see
  505. section 2.7.3) defines what a character is. For example, the
  506. comparators "i;octet" and "i;ascii-casemap" define a character to be
  507. a single octet, so "?" will always match exactly one octet when one
  508. of those comparators is in use. In contrast, a Unicode-based
  509. comparator would define a character to be any UTF-8 octet sequence
  510. encoding one Unicode character and thus "?" may match more than one
  511. octet. "?" and "*" may be escaped as "\\?" and "\\*" in strings to
  512. match against themselves. The first backslash escapes the second
  513. backslash; together, they escape the "*". This is awkward, but it is
  514. commonplace in several programming languages that use globs and
  515. regular expressions.
  516. In order to specify what type of match is supposed to happen,
  517. commands that support matching take optional arguments ":matches",
  518. ":is", and ":contains". Commands default to using ":is" matching if
  519. no match type argument is supplied. Note that these modifiers
  520. interact with comparators; in particular, only comparators that
  521. support the "substring match" operation are suitable for matching
  522. with ":contains" or ":matches". It is an error to use a comparator
  523. with ":contains" or ":matches" that is not compatible with it.
  524. Guenther & Showalter Standards Track [Page 14]
  525. RFC 5228 Sieve: An Email Filtering Language January 2008
  526. It is an error to give more than one of these arguments to a given
  527. command.
  528. For convenience, the "MATCH-TYPE" syntax element is defined here as
  529. follows:
  530. Syntax: ":is" / ":contains" / ":matches"
  531. 2.7.2. Comparisons across Character Sets
  532. Messages may involve a number of character sets. In order for
  533. comparisons to work across character sets, implementations SHOULD
  534. implement the following behavior:
  535. Comparisons are performed on octets. Implementations convert text
  536. from header fields in all charsets [MIME3] to Unicode, encoded as
  537. UTF-8, as input to the comparator (see section 2.7.3).
  538. Implementations MUST be capable of converting US-ASCII, ISO-8859-
  539. 1, the US-ASCII subset of ISO-8859-* character sets, and UTF-8.
  540. Text that the implementation cannot convert to Unicode for any
  541. reason MAY be treated as plain US-ASCII (including any [MIME3]
  542. syntax) or processed according to local conventions. An encoded
  543. NUL octet (character zero) SHOULD NOT cause early termination of
  544. the header content being compared against.
  545. If implementations fail to support the above behavior, they MUST
  546. conform to the following:
  547. No two strings can be considered equal if one contains octets
  548. greater than 127.
  549. 2.7.3. Comparators
  550. In order to allow for language-independent, case-independent matches,
  551. the match type may be coupled with a comparator name. The Internet
  552. Application Protocol Collation Registry [COLLATION] provides the
  553. framework for describing and naming comparators.
  554. All implementations MUST support the "i;octet" comparator (simply
  555. compares octets) and the "i;ascii-casemap" comparator (which treats
  556. uppercase and lowercase characters in the US-ASCII subset of UTF-8 as
  557. the same). If left unspecified, the default is "i;ascii-casemap".
  558. Some comparators may not be usable with substring matches; that is,
  559. they may only work with ":is". It is an error to try to use a
  560. comparator with ":matches" or ":contains" that is not compatible with
  561. it.
  562. Guenther & Showalter Standards Track [Page 15]
  563. RFC 5228 Sieve: An Email Filtering Language January 2008
  564. Sieve treats a comparator result of "undefined" the same as a result
  565. of "no-match". That is, this base specification does not provide any
  566. means to directly detect invalid comparator input.
  567. A comparator is specified by the ":comparator" option with commands
  568. that support matching. This option is followed by a string providing
  569. the name of the comparator to be used. For convenience, the syntax
  570. of a comparator is abbreviated to "COMPARATOR", and (repeated in
  571. several tests) is as follows:
  572. Syntax: ":comparator" <comparator-name: string>
  573. So in this example,
  574. Example: if header :contains :comparator "i;octet" "Subject"
  575. "MAKE MONEY FAST" {
  576. discard;
  577. }
  578. would discard any message with subjects like "You can MAKE MONEY
  579. FAST", but not "You can Make Money Fast", since the comparator used
  580. is case-sensitive.
  581. Comparators other than "i;octet" and "i;ascii-casemap" must be
  582. declared with require, as they are extensions. If a comparator
  583. declared with require is not known, it is an error, and execution
  584. fails. If the comparator is not declared with require, it is also an
  585. error, even if the comparator is supported. (See section 2.10.5.)
  586. Both ":matches" and ":contains" match types are compatible with the
  587. "i;octet" and "i;ascii-casemap" comparators and may be used with
  588. them.
  589. It is an error to give more than one of these arguments to a given
  590. command.
  591. 2.7.4. Comparisons against Addresses
  592. Addresses are one of the most frequent things represented as strings.
  593. These are structured, and being able to compare against the local-
  594. part or the domain of an address is useful, so some tests that act
  595. exclusively on addresses take an additional optional argument that
  596. specifies what the test acts on.
  597. These optional arguments are ":localpart", ":domain", and ":all",
  598. which act on the local-part (left side), the domain-part (right
  599. side), and the whole address.
  600. Guenther & Showalter Standards Track [Page 16]
  601. RFC 5228 Sieve: An Email Filtering Language January 2008
  602. If an address is not syntactically valid, then it will not be matched
  603. by tests specifying ":localpart" or ":domain".
  604. The kind of comparison done, such as whether or not the test done is
  605. case-insensitive, is specified as a comparator argument to the test.
  606. If an optional address-part is omitted, the default is ":all".
  607. It is an error to give more than one of these arguments to a given
  608. command.
  609. For convenience, the "ADDRESS-PART" syntax element is defined here as
  610. follows:
  611. Syntax: ":localpart" / ":domain" / ":all"
  612. 2.8. Blocks
  613. Blocks are sets of commands enclosed within curly braces and supplied
  614. as the final argument to a command. Such a command is a control
  615. structure: when executed it has control over the number of times the
  616. commands in the block are executed.
  617. With the commands supplied in this memo, there are no loops. The
  618. control structures supplied--if, elsif, and else--run a block either
  619. once or not at all.
  620. 2.9. Commands
  621. Sieve scripts are sequences of commands. Commands can take any of
  622. the tokens above as arguments, and arguments may be either tagged or
  623. positional arguments. Not all commands take all arguments.
  624. There are three kinds of commands: test commands, action commands,
  625. and control commands.
  626. The simplest is an action command. An action command is an
  627. identifier followed by zero or more arguments, terminated by a
  628. semicolon. Action commands do not take tests or blocks as arguments.
  629. The actions referenced in this document are:
  630. - keep, to save the message in the default location
  631. - fileinto, to save the message in a specific mailbox
  632. - redirect, to forward the message to another address
  633. - discard, to silently throw away the message
  634. Guenther & Showalter Standards Track [Page 17]
  635. RFC 5228 Sieve: An Email Filtering Language January 2008
  636. A control command is a command that affects the parsing or the flow
  637. of execution of the Sieve script in some way. A control structure is
  638. a control command that ends with a block instead of a semicolon.
  639. A test command is used as part of a control command. It is used to
  640. specify whether or not the block of code given to the control command
  641. is executed.
  642. 2.10. Evaluation
  643. 2.10.1. Action Interaction
  644. Some actions cannot be used with other actions because the result
  645. would be absurd. These restrictions are noted throughout this memo.
  646. Extension actions MUST state how they interact with actions defined
  647. in this specification.
  648. 2.10.2. Implicit Keep
  649. Previous experience with filtering systems suggests that cases tend
  650. to be missed in scripts. To prevent errors, Sieve has an "implicit
  651. keep".
  652. An implicit keep is a keep action (see section 4.3) performed in
  653. absence of any action that cancels the implicit keep.
  654. An implicit keep is performed if a message is not written to a
  655. mailbox, redirected to a new address, or explicitly thrown out. That
  656. is, if a fileinto, a keep, a redirect, or a discard is performed, an
  657. implicit keep is not.
  658. Some actions may be defined to not cancel the implicit keep. These
  659. actions may not directly affect the delivery of a message, and are
  660. used for their side effects. None of the actions specified in this
  661. document meet that criteria, but extension actions may.
  662. For instance, with any of the short messages offered above, the
  663. following script produces no actions.
  664. Example: if size :over 500K { discard; }
  665. As a result, the implicit keep is taken.
  666. Guenther & Showalter Standards Track [Page 18]
  667. RFC 5228 Sieve: An Email Filtering Language January 2008
  668. 2.10.3. Message Uniqueness in a Mailbox
  669. Implementations SHOULD NOT deliver a message to the same mailbox more
  670. than once, even if a script explicitly asks for a message to be
  671. written to a mailbox twice.
  672. The test for equality of two messages is implementation-defined.
  673. If a script asks for a message to be written to a mailbox twice, it
  674. MUST NOT be treated as an error.
  675. 2.10.4. Limits on Numbers of Actions
  676. Site policy MAY limit the number of actions taken and MAY impose
  677. restrictions on which actions can be used together. In the event
  678. that a script hits a policy limit on the number of actions taken for
  679. a particular message, an error occurs.
  680. Implementations MUST allow at least one keep or one fileinto. If
  681. fileinto is not implemented, implementations MUST allow at least one
  682. keep.
  683. 2.10.5. Extensions and Optional Features
  684. Because of the differing capabilities of many mail systems, several
  685. features of this specification are optional. Before any of these
  686. extensions can be executed, they must be declared with the "require"
  687. action.
  688. If an extension is not enabled with "require", implementations MUST
  689. treat it as if they did not support it at all. This protects scripts
  690. from having their behavior altered by extensions that the script
  691. author might not have even been aware of.
  692. Implementations MUST NOT execute any Sieve script test or command
  693. subsequent to "require" if one of the required extensions is
  694. unavailable.
  695. Note: The reason for this restriction is that prior experiences
  696. with languages such as LISP and Tcl suggest that this is a
  697. workable way of noting that a given script uses an extension.
  698. Extensions that define actions MUST state how they interact with
  699. actions discussed in the base specification.
  700. Guenther & Showalter Standards Track [Page 19]
  701. RFC 5228 Sieve: An Email Filtering Language January 2008
  702. 2.10.6. Errors
  703. In any programming language, there are compile-time and run-time
  704. errors.
  705. Compile-time errors are ones in syntax that are detectable if a
  706. syntax check is done.
  707. Run-time errors are not detectable until the script is run. This
  708. includes transient failures like disk full conditions, but also
  709. includes issues like invalid combinations of actions.
  710. When an error occurs in a Sieve script, all processing stops.
  711. Implementations MAY choose to do a full parse, then evaluate the
  712. script, then do all actions. Implementations might even go so far as
  713. to ensure that execution is atomic (either all actions are executed
  714. or none are executed).
  715. Other implementations may choose to parse and run at the same time.
  716. Such implementations are simpler, but have issues with partial
  717. failure (some actions happen, others don't).
  718. Implementations MUST perform syntactic, semantic, and run-time checks
  719. on code that is actually executed. Implementations MAY perform those
  720. checks or any part of them on code that is not reached during
  721. execution.
  722. When an error happens, implementations MUST notify the user that an
  723. error occurred and which actions (if any) were taken, and do an
  724. implicit keep.
  725. 2.10.7. Limits on Execution
  726. Implementations may limit certain constructs. However, this
  727. specification places a lower bound on some of these limits.
  728. Implementations MUST support fifteen levels of nested blocks.
  729. Implementations MUST support fifteen levels of nested test lists.
  730. Guenther & Showalter Standards Track [Page 20]
  731. RFC 5228 Sieve: An Email Filtering Language January 2008
  732. 3. Control Commands
  733. Control structures are needed to allow for multiple and conditional
  734. actions.
  735. 3.1. Control if
  736. There are three pieces to if: "if", "elsif", and "else". Each is
  737. actually a separate command in terms of the grammar. However, an
  738. elsif or else MUST only follow an if or elsif. An error occurs if
  739. these conditions are not met.
  740. Usage: if <test1: test> <block1: block>
  741. Usage: elsif <test2: test> <block2: block>
  742. Usage: else <block3: block>
  743. The semantics are similar to those of any of the many other
  744. programming languages these control structures appear in. When the
  745. interpreter sees an "if", it evaluates the test associated with it.
  746. If the test is true, it executes the block associated with it.
  747. If the test of the "if" is false, it evaluates the test of the first
  748. "elsif" (if any). If the test of "elsif" is true, it runs the
  749. elsif's block. An elsif may be followed by an elsif, in which case,
  750. the interpreter repeats this process until it runs out of elsifs.
  751. When the interpreter runs out of elsifs, there may be an "else" case.
  752. If there is, and none of the if or elsif tests were true, the
  753. interpreter runs the else's block.
  754. This provides a way of performing exactly one of the blocks in the
  755. chain.
  756. In the following example, both messages A and B are dropped.
  757. Example: require "fileinto";
  758. if header :contains "from" "coyote" {
  759. discard;
  760. } elsif header :contains ["subject"] ["$$$"] {
  761. discard;
  762. } else {
  763. fileinto "INBOX";
  764. }
  765. Guenther & Showalter Standards Track [Page 21]
  766. RFC 5228 Sieve: An Email Filtering Language January 2008
  767. When the script below is run over message A, it redirects the message
  768. to acm@example.com; message B, to postmaster@example.com; any other
  769. message is redirected to field@example.com.
  770. Example: if header :contains ["From"] ["coyote"] {
  771. redirect "acm@example.com";
  772. } elsif header :contains "Subject" "$$$" {
  773. redirect "postmaster@example.com";
  774. } else {
  775. redirect "field@example.com";
  776. }
  777. Note that this definition prohibits the "... else if ..." sequence
  778. used by C. This is intentional, because this construct produces a
  779. shift-reduce conflict.
  780. 3.2. Control require
  781. Usage: require <capabilities: string-list>
  782. The require action notes that a script makes use of a certain
  783. extension. Such a declaration is required to use the extension, as
  784. discussed in section 2.10.5. Multiple capabilities can be declared
  785. with a single require.
  786. The require command, if present, MUST be used before anything other
  787. than a require can be used. An error occurs if a require appears
  788. after a command other than require.
  789. Example: require ["fileinto", "reject"];
  790. Example: require "fileinto";
  791. require "vacation";
  792. 3.3. Control stop
  793. Usage: stop
  794. The "stop" action ends all processing. If the implicit keep has not
  795. been cancelled, then it is taken.
  796. Guenther & Showalter Standards Track [Page 22]
  797. RFC 5228 Sieve: An Email Filtering Language January 2008
  798. 4. Action Commands
  799. This document supplies four actions that may be taken on a message:
  800. keep, fileinto, redirect, and discard.
  801. Implementations MUST support the "keep", "discard", and "redirect"
  802. actions.
  803. Implementations SHOULD support "fileinto".
  804. Implementations MAY limit the number of certain actions taken (see
  805. section 2.10.4).
  806. 4.1. Action fileinto
  807. Usage: fileinto <mailbox: string>
  808. The "fileinto" action delivers the message into the specified
  809. mailbox. Implementations SHOULD support fileinto, but in some
  810. environments this may be impossible. Implementations MAY place
  811. restrictions on mailbox names; use of an invalid mailbox name MAY be
  812. treated as an error or result in delivery to an implementation-
  813. defined mailbox. If the specified mailbox doesn't exist, the
  814. implementation MAY treat it as an error, create the mailbox, or
  815. deliver the message to an implementation-defined mailbox. If the
  816. implementation uses a different encoding scheme than UTF-8 for
  817. mailbox names, it SHOULD reencode the mailbox name from UTF-8 to its
  818. encoding scheme. For example, the Internet Message Access Protocol
  819. [IMAP] uses modified UTF-7, such that a mailbox argument of "odds &
  820. ends" would appear in IMAP as "odds &- ends".
  821. The capability string for use with the require command is "fileinto".
  822. In the following script, message A is filed into mailbox
  823. "INBOX.harassment".
  824. Example: require "fileinto";
  825. if header :contains ["from"] "coyote" {
  826. fileinto "INBOX.harassment";
  827. }
  828. 4.2. Action redirect
  829. Usage: redirect <address: string>
  830. The "redirect" action is used to send the message to another user at
  831. a supplied address, as a mail forwarding feature does. The
  832. "redirect" action makes no changes to the message body or existing
  833. Guenther & Showalter Standards Track [Page 23]
  834. RFC 5228 Sieve: An Email Filtering Language January 2008
  835. headers, but it may add new headers. In particular, existing
  836. Received headers MUST be preserved and the count of Received headers
  837. in the outgoing message MUST be larger than the same count on the
  838. message as received by the implementation. (An implementation that
  839. adds a Received header before processing the message does not need to
  840. add another when redirecting.)
  841. The message is sent back out with the address from the redirect
  842. command as an envelope recipient. Implementations MAY combine
  843. separate redirects for a given message into a single submission with
  844. multiple envelope recipients. (This is not a Mail User Agent (MUA)-
  845. style forward, which creates a new message with a different sender
  846. and message ID, wrapping the old message in a new one.)
  847. The envelope sender address on the outgoing message is chosen by the
  848. sieve implementation. It MAY be copied from the message being
  849. processed. However, if the message being processed has an empty
  850. envelope sender address the outgoing message MUST also have an empty
  851. envelope sender address. This last requirement is imposed to prevent
  852. loops in the case where a message is redirected to an invalid address
  853. when then returns a delivery status notification that also ends up
  854. being redirected to the same invalid address.
  855. A simple script can be used for redirecting all mail:
  856. Example: redirect "bart@example.com";
  857. Implementations MUST take measures to implement loop control,
  858. possibly including adding headers to the message or counting Received
  859. headers as specified in section 6.2 of [SMTP]. If an implementation
  860. detects a loop, it causes an error.
  861. Implementations MUST provide means of limiting the number of
  862. redirects a Sieve script can perform. See section 10 for more
  863. details.
  864. Implementations MAY ignore a redirect action silently due to policy
  865. reasons. For example, an implementation MAY choose not to redirect
  866. to an address that is known to be undeliverable. Any ignored
  867. redirect MUST NOT cancel the implicit keep.
  868. 4.3. Action keep
  869. Usage: keep
  870. The "keep" action is whatever action is taken in lieu of all other
  871. actions, if no filtering happens at all; generally, this simply means
  872. to file the message into the user's main mailbox. This command
  873. Guenther & Showalter Standards Track [Page 24]
  874. RFC 5228 Sieve: An Email Filtering Language January 2008
  875. provides a way to execute this action without needing to know the
  876. name of the user's main mailbox, providing a way to call it without
  877. needing to understand the user's setup or the underlying mail system.
  878. For instance, in an implementation where the IMAP server is running
  879. scripts on behalf of the user at time of delivery, a keep command is
  880. equivalent to a fileinto "INBOX".
  881. Example: if size :under 1M { keep; } else { discard; }
  882. Note that the above script is identical to the one below.
  883. Example: if not size :under 1M { discard; }
  884. 4.4. Action discard
  885. Usage: discard
  886. Discard is used to silently throw away the message. It does so by
  887. simply canceling the implicit keep. If discard is used with other
  888. actions, the other actions still happen. Discard is compatible with
  889. all other actions. (For instance, fileinto+discard is equivalent to
  890. fileinto.)
  891. Discard MUST be silent; that is, it MUST NOT return a non-delivery
  892. notification of any kind ([DSN], [MDN], or otherwise).
  893. In the following script, any mail from "idiot@example.com" is thrown
  894. out.
  895. Example: if header :contains ["from"] ["idiot@example.com"] {
  896. discard;
  897. }
  898. While an important part of this language, "discard" has the potential
  899. to create serious problems for users: Students who leave themselves
  900. logged in to an unattended machine in a public computer lab may find
  901. their script changed to just "discard". In order to protect users in
  902. this situation (along with similar situations), implementations MAY
  903. keep messages destroyed by a script for an indefinite period, and MAY
  904. disallow scripts that throw out all mail.
  905. Guenther & Showalter Standards Track [Page 25]
  906. RFC 5228 Sieve: An Email Filtering Language January 2008
  907. 5. Test Commands
  908. Tests are used in conditionals to decide which part(s) of the
  909. conditional to execute.
  910. Implementations MUST support these tests: "address", "allof",
  911. "anyof", "exists", "false", "header", "not", "size", and "true".
  912. Implementations SHOULD support the "envelope" test.
  913. 5.1. Test address
  914. Usage: address [COMPARATOR] [ADDRESS-PART] [MATCH-TYPE]
  915. <header-list: string-list> <key-list: string-list>
  916. The "address" test matches Internet addresses in structured headers
  917. that contain addresses. It returns true if any header contains any
  918. key in the specified part of the address, as modified by the
  919. comparator and the match keyword. Whether there are other addresses
  920. present in the header doesn't affect this test; this test does not
  921. provide any way to determine whether an address is the only address
  922. in a header.
  923. Like envelope and header, this test returns true if any combination
  924. of the header-list and key-list arguments match and returns false
  925. otherwise.
  926. Internet email addresses [IMAIL] have the somewhat awkward
  927. characteristic that the local-part to the left of the at-sign is
  928. considered case sensitive, and the domain-part to the right of the
  929. at-sign is case insensitive. The "address" command does not deal
  930. with this itself, but provides the ADDRESS-PART argument for allowing
  931. users to deal with it.
  932. The address primitive never acts on the phrase part of an email
  933. address or on comments within that address. It also never acts on
  934. group names, although it does act on the addresses within the group
  935. construct.
  936. Implementations MUST restrict the address test to headers that
  937. contain addresses, but MUST include at least From, To, Cc, Bcc,
  938. Sender, Resent-From, and Resent-To, and it SHOULD include any other
  939. header that utilizes an "address-list" structured header body.
  940. Example: if address :is :all "from" "tim@example.com" {
  941. discard;
  942. }
  943. Guenther & Showalter Standards Track [Page 26]
  944. RFC 5228 Sieve: An Email Filtering Language January 2008
  945. 5.2. Test allof
  946. Usage: allof <tests: test-list>
  947. The "allof" test performs a logical AND on the tests supplied to it.
  948. Example: allof (false, false) => false
  949. allof (false, true) => false
  950. allof (true, true) => true
  951. The allof test takes as its argument a test-list.
  952. 5.3. Test anyof
  953. Usage: anyof <tests: test-list>
  954. The "anyof" test performs a logical OR on the tests supplied to it.
  955. Example: anyof (false, false) => false
  956. anyof (false, true) => true
  957. anyof (true, true) => true
  958. 5.4. Test envelope
  959. Usage: envelope [COMPARATOR] [ADDRESS-PART] [MATCH-TYPE]
  960. <envelope-part: string-list> <key-list: string-list>
  961. The "envelope" test is true if the specified part of the [SMTP] (or
  962. equivalent) envelope matches the specified key. This specification
  963. defines the interpretation of the (case insensitive) "from" and "to"
  964. envelope-parts. Additional envelope-parts may be defined by other
  965. extensions; implementations SHOULD consider unknown envelope parts an
  966. error.
  967. If one of the envelope-part strings is (case insensitive) "from",
  968. then matching occurs against the FROM address used in the SMTP MAIL
  969. command. The null reverse-path is matched against as the empty
  970. string, regardless of the ADDRESS-PART argument specified.
  971. If one of the envelope-part strings is (case insensitive) "to", then
  972. matching occurs against the TO address used in the SMTP RCPT command
  973. that resulted in this message getting delivered to this user. Note
  974. that only the most recent TO is available, and only the one relevant
  975. to this user.
  976. The envelope-part is a string list and may contain more than one
  977. parameter, in which case all of the strings specified in the key-list
  978. are matched against all parts given in the envelope-part list.
  979. Guenther & Showalter Standards Track [Page 27]
  980. RFC 5228 Sieve: An Email Filtering Language January 2008
  981. Like address and header, this test returns true if any combination of
  982. the envelope-part list and key-list arguments match and returns false
  983. otherwise.
  984. All tests against envelopes MUST drop source routes.
  985. If the SMTP transaction involved several RCPT commands, only the data
  986. from the RCPT command that caused delivery to this user is available
  987. in the "to" part of the envelope.
  988. If a protocol other than SMTP is used for message transport,
  989. implementations are expected to adapt this command appropriately.
  990. The envelope command is optional. Implementations SHOULD support it,
  991. but the necessary information may not be available in all cases. The
  992. capability string for use with the require command is "envelope".
  993. Example: require "envelope";
  994. if envelope :all :is "from" "tim@example.com" {
  995. discard;
  996. }
  997. 5.5. Test exists
  998. Usage: exists <header-names: string-list>
  999. The "exists" test is true if the headers listed in the header-names
  1000. argument exist within the message. All of the headers must exist or
  1001. the test is false.
  1002. The following example throws out mail that doesn't have a From header
  1003. and a Date header.
  1004. Example: if not exists ["From","Date"] {
  1005. discard;
  1006. }
  1007. 5.6. Test false
  1008. Usage: false
  1009. The "false" test always evaluates to false.
  1010. Guenther & Showalter Standards Track [Page 28]
  1011. RFC 5228 Sieve: An Email Filtering Language January 2008
  1012. 5.7. Test header
  1013. Usage: header [COMPARATOR] [MATCH-TYPE]
  1014. <header-names: string-list> <key-list: string-list>
  1015. The "header" test evaluates to true if the value of any of the named
  1016. headers, ignoring leading and trailing whitespace, matches any key.
  1017. The type of match is specified by the optional match argument, which
  1018. defaults to ":is" if not specified, as specified in section 2.6.
  1019. Like address and envelope, this test returns true if any combination
  1020. of the header-names list and key-list arguments match and returns
  1021. false otherwise.
  1022. If a header listed in the header-names argument exists, it contains
  1023. the empty key (""). However, if the named header is not present, it
  1024. does not match any key, including the empty key. So if a message
  1025. contained the header
  1026. X-Caffeine: C8H10N4O2
  1027. these tests on that header evaluate as follows:
  1028. header :is ["X-Caffeine"] [""] => false
  1029. header :contains ["X-Caffeine"] [""] => true
  1030. Testing whether a given header is either absent or doesn't contain
  1031. any non-whitespace characters can be done using a negated "header"
  1032. test:
  1033. not header :matches "Cc" "?*"
  1034. 5.8. Test not
  1035. Usage: not <test1: test>
  1036. The "not" test takes some other test as an argument, and yields the
  1037. opposite result. "not false" evaluates to "true" and "not true"
  1038. evaluates to "false".
  1039. 5.9. Test size
  1040. Usage: size <":over" / ":under"> <limit: number>
  1041. The "size" test deals with the size of a message. It takes either a
  1042. tagged argument of ":over" or ":under", followed by a number
  1043. representing the size of the message.
  1044. Guenther & Showalter Standards Track [Page 29]
  1045. RFC 5228 Sieve: An Email Filtering Language January 2008
  1046. If the argument is ":over", and the size of the message is greater
  1047. than the number provided, the test is true; otherwise, it is false.
  1048. If the argument is ":under", and the size of the message is less than
  1049. the number provided, the test is true; otherwise, it is false.
  1050. Exactly one of ":over" or ":under" must be specified, and anything
  1051. else is an error.
  1052. The size of a message is defined to be the number of octets in the
  1053. [IMAIL] representation of the message.
  1054. Note that for a message that is exactly 4,000 octets, the message is
  1055. neither ":over" nor ":under" 4000 octets.
  1056. 5.10. Test true
  1057. Usage: true
  1058. The "true" test always evaluates to true.
  1059. 6. Extensibility
  1060. New control commands, actions, and tests can be added to the
  1061. language. Sites must make these features known to their users; this
  1062. document does not define a way to discover the list of extensions
  1063. supported by the server.
  1064. Any extensions to this language MUST define a capability string that
  1065. uniquely identifies that extension. Capability string are case-
  1066. sensitive; for example, "foo" and "FOO" are different capabilities.
  1067. If a new version of an extension changes the functionality of a
  1068. previously defined extension, it MUST use a different name.
  1069. Extensions may register a set of related capabilities by registering
  1070. just a unique prefix for them. The "comparator-" prefix is an
  1071. example of this. The prefix MUST end with a "-" and MUST NOT overlap
  1072. any existing registrations.
  1073. In a situation where there is a script submission protocol and an
  1074. extension advertisement mechanism aware of the details of this
  1075. language, scripts submitted can be checked against the mail server to
  1076. prevent use of an extension that the server does not support.
  1077. Extensions MUST state how they interact with constraints defined in
  1078. section 2.10, e.g., whether they cancel the implicit keep, and which
  1079. actions they are compatible and incompatible with. Extensions MUST
  1080. NOT change the behavior of the "require" control command or alter the
  1081. interpretation of the argument to the "require" control.
  1082. Guenther & Showalter Standards Track [Page 30]
  1083. RFC 5228 Sieve: An Email Filtering Language January 2008
  1084. Extensions that can submit new email messages or otherwise generate
  1085. new protocol requests MUST consider loop suppression, at least to
  1086. document any security considerations.
  1087. 6.1. Capability String
  1088. Capability strings are typically short strings describing what
  1089. capabilities are supported by the server.
  1090. Capability strings beginning with "vnd." represent vendor-defined
  1091. extensions. Such extensions are not defined by Internet standards or
  1092. RFCs, but are still registered with IANA in order to prevent
  1093. conflicts. Extensions starting with "vnd." SHOULD be followed by the
  1094. name of the vendor and product, such as "vnd.acme.rocket-sled".
  1095. The following capability strings are defined by this document:
  1096. encoded-character The string "encoded-character" indicates that the
  1097. implementation supports the interpretation of
  1098. "${hex:...}" and "${unicode:...}" in strings.
  1099. envelope The string "envelope" indicates that the implementation
  1100. supports the "envelope" command.
  1101. fileinto The string "fileinto" indicates that the implementation
  1102. supports the "fileinto" command.
  1103. comparator- The string "comparator-elbonia" is provided if the
  1104. implementation supports the "elbonia" comparator.
  1105. Therefore, all implementations have at least the
  1106. "comparator-i;octet" and "comparator-i;ascii-casemap"
  1107. capabilities. However, these comparators may be used
  1108. without being declared with require.
  1109. 6.2. IANA Considerations
  1110. In order to provide a standard set of extensions, a registry is
  1111. maintained by IANA. This registry contains both vendor-controlled
  1112. capability names (beginning with "vnd.") and IETF-controlled
  1113. capability names. Vendor-controlled capability names may be
  1114. registered on a first-come, first-served basis, by applying to IANA
  1115. with the form in the following section. Registration of capability
  1116. prefixes that do not begin with "vnd." REQUIRES a standards track or
  1117. IESG-approved experimental RFC.
  1118. Extensions designed for interoperable use SHOULD use IETF-controlled
  1119. capability names.
  1120. Guenther & Showalter Standards Track [Page 31]
  1121. RFC 5228 Sieve: An Email Filtering Language January 2008
  1122. 6.2.1. Template for Capability Registrations
  1123. The following template is to be used for registering new Sieve
  1124. extensions with IANA.
  1125. To: iana@iana.org
  1126. Subject: Registration of new Sieve extension
  1127. Capability name: [the string for use in the 'require' statement]
  1128. Description: [a brief description of what the extension adds
  1129. or changes]
  1130. RFC number: [for extensions published as RFCs]
  1131. Contact address: [email and/or physical address to contact for
  1132. additional information]
  1133. 6.2.2. Handling of Existing Capability Registrations
  1134. In order to bring the existing capability registrations in line with
  1135. the new template, IANA has modified each as follows:
  1136. 1. The "capability name" and "capability arguments" fields have been
  1137. eliminated
  1138. 2. The "capability keyword" field have been renamed to "Capability
  1139. name"
  1140. 3. An empty "Description" field has been added
  1141. 4. The "Standards Track/IESG-approved experimental RFC number" field
  1142. has been renamed to "RFC number"
  1143. 5. The "Person and email address to contact for further information"
  1144. field should be renamed to "Contact address"
  1145. 6.2.3. Initial Capability Registrations
  1146. This RFC updates the following entries in the IANA registry for Sieve
  1147. extensions.
  1148. Capability name: encoded-character
  1149. Description: changes the interpretation of strings to allow
  1150. arbitrary octets and Unicode characters to be
  1151. represented using US-ASCII
  1152. RFC number: RFC 5228 (Sieve base spec)
  1153. Contact address: The Sieve discussion list <ietf-mta-filters@imc.org>
  1154. Capability name: fileinto
  1155. Description: adds the 'fileinto' action for delivering to a
  1156. mailbox other than the default
  1157. RFC number: RFC 5228 (Sieve base spec)
  1158. Contact address: The Sieve discussion list <ietf-mta-filters@imc.org>
  1159. Guenther & Showalter Standards Track [Page 32]
  1160. RFC 5228 Sieve: An Email Filtering Language January 2008
  1161. Capability name: envelope
  1162. Description: adds the 'envelope' test for testing the message
  1163. transport sender and recipient address
  1164. RFC number: RFC 5228 (Sieve base spec)
  1165. Contact address: The Sieve discussion list <ietf-mta-filters@imc.org>
  1166. Capability name: comparator-* (anything starting with "comparator-")
  1167. Description: adds the indicated comparator for use with the
  1168. :comparator argument
  1169. RFC number: RFC 5228 (Sieve base spec) and [COLLATION]
  1170. Contact address: The Sieve discussion list <ietf-mta-filters@imc.org>
  1171. 6.3. Capability Transport
  1172. A method of advertising which capabilities an implementation supports
  1173. is difficult due to the wide range of possible implementations. Such
  1174. a mechanism, however, should have the property that the
  1175. implementation can advertise the complete set of extensions that it
  1176. supports.
  1177. 7. Transmission
  1178. The [MIME] type for a Sieve script is "application/sieve".
  1179. The registration of this type for RFC 2048 requirements is updated as
  1180. follows:
  1181. Subject: Registration of MIME media type application/sieve
  1182. MIME media type name: application
  1183. MIME subtype name: sieve
  1184. Required parameters: none
  1185. Optional parameters: none
  1186. Encoding considerations: Most Sieve scripts will be textual,
  1187. written in UTF-8. When non-7bit characters are used,
  1188. quoted-printable is appropriate for transport systems
  1189. that require 7bit encoding.
  1190. Security considerations: Discussed in section 10 of this RFC.
  1191. Interoperability considerations: Discussed in section 2.10.5
  1192. of this RFC.
  1193. Published specification: this RFC.
  1194. Applications that use this media type: sieve-enabled mail
  1195. servers and clients
  1196. Additional information:
  1197. Magic number(s):
  1198. File extension(s): .siv .sieve
  1199. Macintosh File Type Code(s):
  1200. Guenther & Showalter Standards Track [Page 33]
  1201. RFC 5228 Sieve: An Email Filtering Language January 2008
  1202. Person & email address to contact for further information:
  1203. See the discussion list at ietf-mta-filters@imc.org.
  1204. Intended usage:
  1205. COMMON
  1206. Author/Change controller:
  1207. The SIEVE WG, delegated by the IESG.
  1208. 8. Parsing
  1209. The Sieve grammar is separated into tokens and a separate grammar as
  1210. most programming languages are. Additional rules are supplied here
  1211. for common arguments to various language facilities.
  1212. 8.1. Lexical Tokens
  1213. Sieve scripts are encoded in UTF-8. The following assumes a valid
  1214. UTF-8 encoding; special characters in Sieve scripts are all US-ASCII.
  1215. The following are tokens in Sieve:
  1216. - identifiers
  1217. - tags
  1218. - numbers
  1219. - quoted strings
  1220. - multi-line strings
  1221. - other separators
  1222. Identifiers, tags, and numbers are case-insensitive, while quoted
  1223. strings and multi-line strings are case-sensitive.
  1224. Blanks, horizontal tabs, CRLFs, and comments ("whitespace") are
  1225. ignored except as they separate tokens. Some whitespace is required
  1226. to separate otherwise adjacent tokens and in specific places in the
  1227. multi-line strings. CR and LF can only appear in CRLF pairs.
  1228. The other separators are single individual characters and are
  1229. mentioned explicitly in the grammar.
  1230. The lexical structure of sieve is defined in the following grammar
  1231. (as described in [ABNF]):
  1232. bracket-comment = "/*" *not-star 1*STAR
  1233. *(not-star-slash *not-star 1*STAR) "/"
  1234. ; No */ allowed inside a comment.
  1235. ; (No * is allowed unless it is the last
  1236. ; character, or unless it is followed by a
  1237. ; character that isn't a slash.)
  1238. Guenther & Showalter Standards Track [Page 34]
  1239. RFC 5228 Sieve: An Email Filtering Language January 2008
  1240. comment = bracket-comment / hash-comment
  1241. hash-comment = "#" *octet-not-crlf CRLF
  1242. identifier = (ALPHA / "_") *(ALPHA / DIGIT / "_")
  1243. multi-line = "text:" *(SP / HTAB) (hash-comment / CRLF)
  1244. *(multiline-literal / multiline-dotstart)
  1245. "." CRLF
  1246. multiline-literal = [ octet-not-period *octet-not-crlf ] CRLF
  1247. multiline-dotstart = "." 1*octet-not-crlf CRLF
  1248. ; A line containing only "." ends the
  1249. ; multi-line. Remove a leading '.' if
  1250. ; followed by another '.'.
  1251. not-star = CRLF / %x01-09 / %x0B-0C / %x0E-29 / %x2B-FF
  1252. ; either a CRLF pair, OR a single octet
  1253. ; other than NUL, CR, LF, or star
  1254. not-star-slash = CRLF / %x01-09 / %x0B-0C / %x0E-29 / %x2B-2E /
  1255. %x30-FF
  1256. ; either a CRLF pair, OR a single octet
  1257. ; other than NUL, CR, LF, star, or slash
  1258. number = 1*DIGIT [ QUANTIFIER ]
  1259. octet-not-crlf = %x01-09 / %x0B-0C / %x0E-FF
  1260. ; a single octet other than NUL, CR, or LF
  1261. octet-not-period = %x01-09 / %x0B-0C / %x0E-2D / %x2F-FF
  1262. ; a single octet other than NUL,
  1263. ; CR, LF, or period
  1264. octet-not-qspecial = %x01-09 / %x0B-0C / %x0E-21 / %x23-5B / %x5D-FF
  1265. ; a single octet other than NUL,
  1266. ; CR, LF, double-quote, or backslash
  1267. QUANTIFIER = "K" / "M" / "G"
  1268. quoted-other = "\" octet-not-qspecial
  1269. ; represents just the octet-no-qspecial
  1270. ; character. SHOULD NOT be used
  1271. quoted-safe = CRLF / octet-not-qspecial
  1272. ; either a CRLF pair, OR a single octet other
  1273. ; than NUL, CR, LF, double-quote, or backslash
  1274. Guenther & Showalter Standards Track [Page 35]
  1275. RFC 5228 Sieve: An Email Filtering Language January 2008
  1276. quoted-special = "\" (DQUOTE / "\")
  1277. ; represents just a double-quote or backslash
  1278. quoted-string = DQUOTE quoted-text DQUOTE
  1279. quoted-text = *(quoted-safe / quoted-special / quoted-other)
  1280. STAR = "*"
  1281. tag = ":" identifier
  1282. white-space = 1*(SP / CRLF / HTAB) / comment
  1283. 8.2. Grammar
  1284. The following is the grammar of Sieve after it has been lexically
  1285. interpreted. No whitespace or comments appear below. The start
  1286. symbol is "start".
  1287. argument = string-list / number / tag
  1288. arguments = *argument [ test / test-list ]
  1289. block = "{" commands "}"
  1290. command = identifier arguments (";" / block)
  1291. commands = *command
  1292. start = commands
  1293. string = quoted-string / multi-line
  1294. string-list = "[" string *("," string) "]" / string
  1295. ; if there is only a single string, the brackets
  1296. ; are optional
  1297. test = identifier arguments
  1298. test-list = "(" test *("," test) ")"
  1299. 8.3. Statement Elements
  1300. These elements are collected from the "Syntax" sections elsewhere in
  1301. this document, and are provided here in [ABNF] syntax so that they
  1302. can be modified by extensions.
  1303. ADDRESS-PART = ":localpart" / ":domain" / ":all"
  1304. Guenther & Showalter Standards Track [Page 36]
  1305. RFC 5228 Sieve: An Email Filtering Language January 2008
  1306. COMPARATOR = ":comparator" string
  1307. MATCH-TYPE = ":is" / ":contains" / ":matches"
  1308. 9. Extended Example
  1309. The following is an extended example of a Sieve script. Note that it
  1310. does not make use of the implicit keep.
  1311. #
  1312. # Example Sieve Filter
  1313. # Declare any optional features or extension used by the script
  1314. #
  1315. require ["fileinto"];
  1316. #
  1317. # Handle messages from known mailing lists
  1318. # Move messages from IETF filter discussion list to filter mailbox
  1319. #
  1320. if header :is "Sender" "owner-ietf-mta-filters@imc.org"
  1321. {
  1322. fileinto "filter"; # move to "filter" mailbox
  1323. }
  1324. #
  1325. # Keep all messages to or from people in my company
  1326. #
  1327. elsif address :DOMAIN :is ["From", "To"] "example.com"
  1328. {
  1329. keep; # keep in "In" mailbox
  1330. }
  1331. #
  1332. # Try and catch unsolicited email. If a message is not to me,
  1333. # or it contains a subject known to be spam, file it away.
  1334. #
  1335. elsif anyof (NOT address :all :contains
  1336. ["To", "Cc", "Bcc"] "me@example.com",
  1337. header :matches "subject"
  1338. ["*make*money*fast*", "*university*dipl*mas*"])
  1339. {
  1340. fileinto "spam"; # move to "spam" mailbox
  1341. }
  1342. else
  1343. {
  1344. # Move all other (non-company) mail to "personal"
  1345. # mailbox.
  1346. fileinto "personal";
  1347. }
  1348. Guenther & Showalter Standards Track [Page 37]
  1349. RFC 5228 Sieve: An Email Filtering Language January 2008
  1350. 10. Security Considerations
  1351. Users must get their mail. It is imperative that whatever
  1352. implementations use to store the user-defined filtering scripts
  1353. protect them from unauthorized modification, to preserve the
  1354. integrity of the mail system. An attacker who can modify a script
  1355. can cause mail to be discarded, rejected, or forwarded to an
  1356. unauthorized recipient. In addition, it's possible that Sieve
  1357. scripts might expose private information, such as mailbox names, or
  1358. email addresses of favored (or disfavored) correspondents. Because
  1359. of that, scripts SHOULD also be protected from unauthorized
  1360. retrieval.
  1361. Several commands, such as "discard", "redirect", and "fileinto",
  1362. allow for actions to be taken that are potentially very dangerous.
  1363. Use of the "redirect" command to generate notifications may easily
  1364. overwhelm the target address, especially if it was not designed to
  1365. handle large messages.
  1366. Allowing a single script to redirect to multiple destinations can be
  1367. used as a means of amplifying the number of messages in an attack.
  1368. Moreover, if loop detection is not properly implemented, it may be
  1369. possible to set up exponentially growing message loops. Accordingly,
  1370. Sieve implementations:
  1371. (1) MUST implement facilities to detect and break message loops. See
  1372. section 6.2 of [SMTP] for additional information on basic loop
  1373. detection strategies.
  1374. (2) MUST provide the means for administrators to limit the ability of
  1375. users to abuse redirect. In particular, it MUST be possible to
  1376. limit the number of redirects a script can perform.
  1377. Additionally, if no use cases exist for using redirect to
  1378. multiple destinations, this limit SHOULD be set to 1. Additional
  1379. limits, such as the ability to restrict redirect to local users,
  1380. MAY also be implemented.
  1381. (3) MUST provide facilities to log use of redirect in order to
  1382. facilitate tracking down abuse.
  1383. (4) MAY use script analysis to determine whether or not a given
  1384. script can be executed safely. While the Sieve language is
  1385. sufficiently complex that full analysis of all possible scripts
  1386. is computationally infeasible, the majority of real-world scripts
  1387. are amenable to analysis. For example, an implementation might
  1388. Guenther & Showalter Standards Track [Page 38]
  1389. RFC 5228 Sieve: An Email Filtering Language January 2008
  1390. allow scripts that it has determined are safe to run unhindered,
  1391. block scripts that are potentially problematic, and subject
  1392. unclassifiable scripts to additional auditing and logging.
  1393. Allowing redirects at all may not be appropriate in situations where
  1394. email accounts are freely available and/or not trackable to a human
  1395. who can be held accountable for creating message bombs or other
  1396. abuse.
  1397. As with any filter on a message stream, if the Sieve implementation
  1398. and the mail agents 'behind' Sieve in the message stream differ in
  1399. their interpretation of the messages, it may be possible for an
  1400. attacker to subvert the filter. Of particular note are differences
  1401. in the interpretation of malformed messages (e.g., missing or extra
  1402. syntax characters) or those that exhibit corner cases (e.g., NUL
  1403. octets encoded via [MIME3]).
  1404. 11. Acknowledgments
  1405. This document has been revised in part based on comments and
  1406. discussions that took place on and off the SIEVE mailing list.
  1407. Thanks to Sharon Chisholm, Cyrus Daboo, Ned Freed, Arnt Gulbrandsen,
  1408. Michael Haardt, Kjetil Torgrim Homme, Barry Leiba, Mark E. Mallett,
  1409. Alexey Melnikov, Eric Rescorla, Rob Siemborski, and Nigel Swinson for
  1410. reviews and suggestions.
  1411. 12. Normative References
  1412. [ABNF] Crocker, D., Ed., and P. Overell, "Augmented BNF for
  1413. Syntax Specifications: ABNF", RFC 4234, October 2005.
  1414. [COLLATION] Newman, C., Duerst, M., and A. Gulbrandsen, "Internet
  1415. Application Protocol Collation Registry", RFC 4790, March
  1416. 2007.
  1417. [IMAIL] Resnick, P., Ed., "Internet Message Format", RFC 2822,
  1418. April 2001.
  1419. [KEYWORDS] Bradner, S., "Key words for use in RFCs to Indicate
  1420. Requirement Levels", BCP 14, RFC 2119, March 1997.
  1421. [MIME] Freed, N. and N. Borenstein, "Multipurpose Internet Mail
  1422. Extensions (MIME) Part One: Format of Internet Message
  1423. Bodies", RFC 2045, November 1996.
  1424. [MIME3] Moore, K., "MIME (Multipurpose Internet Mail Extensions)
  1425. Part Three: Message Header Extensions for Non-ASCII
  1426. Text", RFC 2047, November 1996.
  1427. Guenther & Showalter Standards Track [Page 39]
  1428. RFC 5228 Sieve: An Email Filtering Language January 2008
  1429. [SMTP] Klensin, J., Ed., "Simple Mail Transfer Protocol", RFC
  1430. 2821, April 2001.
  1431. [UTF-8] Yergeau, F., "UTF-8, a transformation format of ISO
  1432. 10646", STD 63, RFC 3629, November 2003.
  1433. 13. Informative References
  1434. [BINARY-SI] "Standard IEC 60027-2: Letter symbols to be used in
  1435. electrical technology - Part 2: Telecommunications and
  1436. electronics", January 1999.
  1437. [DSN] Moore, K. and G. Vaudreuil, "An Extensible Message Format
  1438. for Delivery Status Notifications", RFC 3464, January
  1439. 2003.
  1440. [FLAMES] Borenstein, N, and C. Thyberg, "Power, Ease of Use, and
  1441. Cooperative Work in a Practical Multimedia Message
  1442. System", Int. J. of Man-Machine Studies, April, 1991.
  1443. Reprinted in Computer-Supported Cooperative Work and
  1444. Groupware, Saul Greenberg, editor, Harcourt Brace
  1445. Jovanovich, 1991. Reprinted in Readings in Groupware and
  1446. Computer-Supported Cooperative Work, Ronald Baecker,
  1447. editor, Morgan Kaufmann, 1993.
  1448. [IMAP] Crispin, M., "Internet Message Access Protocol - version
  1449. 4rev1", RFC 3501, March 2003.
  1450. [MDN] Hansen, T., Ed., and G. Vaudreuil, Ed., "Message
  1451. Disposition Notification", RFC 3798, May 2004.
  1452. [RFC3028] Showalter, T., "Sieve: A Mail Filtering Language", RFC
  1453. 3028, January 2001.
  1454. Guenther & Showalter Standards Track [Page 40]
  1455. RFC 5228 Sieve: An Email Filtering Language January 2008
  1456. 14. Changes from RFC 3028
  1457. This following list is a summary of the changes that have been made
  1458. in the Sieve language base specification from [RFC3028].
  1459. 1. Removed ban on tests having side-effects
  1460. 2. Removed reject extension (will be specified in a separate RFC)
  1461. 3. Clarified description of comparators to match [COLLATION], the
  1462. new base specification for them
  1463. 4. Require stripping of leading and trailing whitespace in "header"
  1464. test
  1465. 5. Clarified or tightened handling of many minor items, including:
  1466. - invalid [MIME3] encoding
  1467. - invalid addresses in headers
  1468. - invalid header field names in tests
  1469. - 'undefined' comparator result
  1470. - unknown envelope parts
  1471. - null return-path in "envelope" test
  1472. 6. Capability strings are case-sensitive
  1473. 7. Clarified that fileinto should reencode non-ASCII mailbox
  1474. names to match the mailstore's conventions
  1475. 8. Errors in the ABNF were corrected
  1476. 9. The references were updated and split into normative and
  1477. informative
  1478. 10. Added encoded-character capability and deprecated (but did not
  1479. remove) use of arbitrary binary octets in Sieve scripts.
  1480. 11. Updated IANA registration template, and added IANA
  1481. considerations to permit capability prefix registrations.
  1482. 12. Added .sieve as a valid extension for Sieve scripts.
  1483. Editors' Addresses
  1484. Philip Guenther
  1485. Sendmail, Inc.
  1486. 6425 Christie St. Ste 400
  1487. Emeryville, CA 94608
  1488. EMail: guenther@sendmail.com
  1489. Tim Showalter
  1490. EMail: tjs@psaux.com
  1491. Guenther & Showalter Standards Track [Page 41]
  1492. RFC 5228 Sieve: An Email Filtering Language January 2008
  1493. Full Copyright Statement
  1494. Copyright (C) The IETF Trust (2008).
  1495. This document is subject to the rights, licenses and restrictions
  1496. contained in BCP 78, and except as set forth therein, the authors
  1497. retain all their rights.
  1498. This document and the information contained herein are provided on an
  1499. "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
  1500. OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND
  1501. THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS
  1502. OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF
  1503. THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
  1504. WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  1505. Intellectual Property
  1506. The IETF takes no position regarding the validity or scope of any
  1507. Intellectual Property Rights or other rights that might be claimed to
  1508. pertain to the implementation or use of the technology described in
  1509. this document or the extent to which any license under such rights
  1510. might or might not be available; nor does it represent that it has
  1511. made any independent effort to identify any such rights. Information
  1512. on the procedures with respect to rights in RFC documents can be
  1513. found in BCP 78 and BCP 79.
  1514. Copies of IPR disclosures made to the IETF Secretariat and any
  1515. assurances of licenses to be made available, or the result of an
  1516. attempt made to obtain a general license or permission for the use of
  1517. such proprietary rights by implementers or users of this
  1518. specification can be obtained from the IETF on-line IPR repository at
  1519. http://www.ietf.org/ipr.
  1520. The IETF invites any interested party to bring to its attention any
  1521. copyrights, patents or patent applications, or other proprietary
  1522. rights that may cover technology that may be required to implement
  1523. this standard. Please address the information to the IETF at
  1524. ietf-ipr@ietf.org.
  1525. Guenther & Showalter Standards Track [Page 42]