7Internet Engineering Task Force (IETF) N. Freed
8Request for Comments: 5784 S. Vedam
9Category: Standards Track Sun Microsystems
10ISSN: 2070-1721 March 2010
13 Sieve Email Filtering: Sieves and Display Directives in XML
17 This document describes a way to represent Sieve email filtering
18 language scripts in XML. Representing Sieves in XML is intended not
19 as an alternate storage format for Sieve but rather as a means to
20 facilitate manipulation of scripts using XML tools.
22 The XML representation also defines additional elements that have no
23 counterparts in the regular Sieve language. These elements are
24 intended for use by graphical user interfaces and provide facilities
25 for labeling or grouping sections of a script so they can be
26 displayed more conveniently. These elements are represented as
27 specially structured comments in regular Sieve format.
31 This is an Internet Standards Track document.
33 This document is a product of the Internet Engineering Task Force
34 (IETF). It represents the consensus of the IETF community. It has
35 received public review and has been approved for publication by the
36 Internet Engineering Steering Group (IESG). Further information on
37 Internet Standards is available in Section 2 of RFC 5741.
39 Information about the current status of this document, any errata,
40 and how to provide feedback on it may be obtained at
41 http://www.rfc-editor.org/info/rfc5784.
58Freed & Vedam Standards Track [Page 1]
60RFC 5784 An XML Representation for Sieve March 2010
65 Copyright (c) 2010 IETF Trust and the persons identified as the
66 document authors. All rights reserved.
68 This document is subject to BCP 78 and the IETF Trust's Legal
69 Provisions Relating to IETF Documents
70 (http://trustee.ietf.org/license-info) in effect on the date of
71 publication of this document. Please review these documents
72 carefully, as they describe your rights and restrictions with respect
73 to this document. Code Components extracted from this document must
74 include Simplified BSD License text as described in Section 4.e of
75 the Trust Legal Provisions and are provided without warranty as
76 described in the Simplified BSD License.
80 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3
81 2. Conventions Used in This Document . . . . . . . . . . . . . . 4
82 3. Grammatical Structure of Sieve . . . . . . . . . . . . . . . . 4
83 4. XML Representation of Sieve . . . . . . . . . . . . . . . . . 6
84 4.1. XML Display Directives . . . . . . . . . . . . . . . . . . 9
85 4.2. Structured Comments . . . . . . . . . . . . . . . . . . . 10
86 4.3. Validation . . . . . . . . . . . . . . . . . . . . . . . . 11
87 5. Security Considerations . . . . . . . . . . . . . . . . . . . 11
88 6. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 11
89 7. References . . . . . . . . . . . . . . . . . . . . . . . . . . 12
90 7.1. Normative References . . . . . . . . . . . . . . . . . . . 12
91 7.2. Informative References . . . . . . . . . . . . . . . . . . 13
92 Appendix A. Extended Example . . . . . . . . . . . . . . . . . . 14
93 Appendix B. XML Schema for Sieves in XML . . . . . . . . . . . . 21
94 Appendix C. Relax NG Schema for Sieves in XML . . . . . . . . . . 24
95 Appendix D. Stylesheet for Conversion from XML . . . . . . . . . 26
96 Appendix E. Acknowledgements . . . . . . . . . . . . . . . . . . 32
114Freed & Vedam Standards Track [Page 2]
116RFC 5784 An XML Representation for Sieve March 2010
121 Sieve [RFC5228] is a language for filtering email messages at or
122 around the time of final delivery. It is designed to be
123 implementable on either a mail client or mail server. It is meant to
124 be extensible, simple, and independent of access protocol, mail
125 architecture, and operating system, and it is intended to be
126 manipulated by a variety of different user interfaces.
128 Some user interface environments have extensive existing facilities
129 for manipulating material represented in XML [XML]. While adding
130 support for alternate data syntaxes may be possible in most if not
131 all of these environments, it may not be particularly convenient to
132 do so. The obvious way to deal with this issue is to map Sieves into
133 XML, possibly on a separate back-end system, manipulate the XML, and
134 convert it back to normal Sieve format.
136 The fact that conversion into and out of XML may be done as a
137 separate operation on a different system argues strongly for defining
138 a common XML representation for Sieve. This way, different front-end
139 user interfaces can be used with different back-end mapping and
142 Another issue with the creation and manipulation of Sieve scripts by
143 user interfaces is that the language is strictly focused on
144 describing email filtering operations. The language contains no
145 mechanisms for indicating how a given script should be presented in a
146 user interface. Such information can be represented in XML very
147 easily, so it makes sense to define a framework to do this as part of
148 the XML format. A structured comment convention is then used to
149 retain this information when the script is converted to normal Sieve
152 It should be noted, however, that the ability for different front
153 ends to use the same mapping and storage facilities does not mean
154 that the additional XML information produced by different front ends
157 Various Sieve extensions have already been defined, e.g., [RFC5183],
158 [RFC5229], [RFC5230], [RFC5231], [RFC5232], [RFC5233], [RFC5235],
159 [RFC5293], and more are planned. The set of extensions available
160 varies from one implementation to the next and may even change as a
161 result of configuration choices. It is therefore essential that the
162 XML representation of Sieve be able to accommodate Sieve extensions
163 without requiring schema changes. It is also desirable that Sieve
164 extensions not require changes to the code that converts to and from
165 the XML representation.
170Freed & Vedam Standards Track [Page 3]
172RFC 5784 An XML Representation for Sieve March 2010
175 This specification defines an XML representation for Sieve scripts
176 and explains how the conversion process to and from XML works. The
177 XML representation is capable of accommodating any future Sieve
178 extension as long as the underlying Sieve grammar remains unchanged.
179 Furthermore, code that converts from XML to the normal Sieve format
180 requires no changes to accommodate extensions, while code used to
181 convert from normal Sieve format to XML only requires changes when
182 new control commands are added -- a rare event. An XML Schema, Relax
183 NG Schema, and a sample stylesheet to convert from XML format are
184 also provided in the appendices.
1862. Conventions Used in This Document
188 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
189 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
190 document are to be interpreted as described in RFC 2119 [RFC2119].
192 The term "processor" is used throughout this document to refer to
193 agents that convert Sieve to and from the XML representation. The
194 term "editor" refers to agents that operate on, possibly creating or
195 modifying, Sieves in XML format.
1973. Grammatical Structure of Sieve
199 The Sieve language is designed to be highly extensible without making
200 any changes to the basic language syntax. Accordingly, the syntax of
201 Sieve, defined in Section 8 of [RFC5228], is entirely structural in
202 nature and employs no reserved words of any sort.
204 Structurally, a Sieve script consists of a series of commands. Each
205 command, in turn, consists of an identifier, zero or more arguments,
206 an optional test or test-list, and finally an optional block
207 containing another series of commands. Commands are further broken
208 down into controls and actions, although this distinction cannot be
209 determined from the grammar.
211 Some example Sieve controls are:
213 stop; <-- No arguments, test, or command block
214 require "fileinto"; <-- Control with a single argument
215 if true {stop;} <-- Control with test and command block
217 Some examples of Sieve actions are:
219discard; <-- Action with no arguments, test, or command block
220fileinto "folder"; <-- Action with an argument
226Freed & Vedam Standards Track [Page 4]
228RFC 5784 An XML Representation for Sieve March 2010
231 At the time of this writing, there are no controls defined that
232 accept both arguments and a test. Similarly, there are currently no
233 defined actions that allow either a test or a command block.
234 Nevertheless, the Sieve grammar allows such constructs to be defined
235 by some future extension.
237 A test consists of an identifier followed by zero or more arguments,
238 then another test or test-list. Unlike commands, tests cannot be
239 followed by a command block.
241 Here are some examples of Sieve tests. Note that such tests have to
242 appear as part of a command in order to be syntactically valid:
244 true <-- Test with no argument or subordinate test
245 envelope "to" "me@example.com" <-- Test with several arguments
246 header :is "from" "you@example.com" <-- Test with tagged argument
248 Command or test arguments can be either string lists, whole numbers,
249 or tags. (Tags are simply identifiers preceded by a colon.) Note
250 that although the Sieve grammar treats single strings as a degenerate
251 case of a string list, some tests or actions have arguments that can
252 only be individual strings, not lists.
254 Here is an example showing the use of both a test-list and a string
257 if anyof (not exists ["From", "Date"],
258 header :contains "from" "fool@example.edu") {
262 Extensions can add new controls, actions, tests, or arguments to
263 existing controls or actions. Extensions have also changed how
264 string content is interpreted, although this is not relevant to this
265 specification. However, it is especially important to note that so
266 far, only one of the many defined Sieve extensions -- the
267 foreverypart extension [RFC5703] -- has added new controls to the
268 language. It seems safe to assume that, due to their nature, future
269 addition of controls will be relatively rare.
271 Finally, comments are allowed between lexical elements in a Sieve
272 script. One important use case for comments is encoding meta-data
273 about the script, a facility that is lacking in the Sieve language.
274 Therefore, comments need to be preserved in the XML representation.
282Freed & Vedam Standards Track [Page 5]
284RFC 5784 An XML Representation for Sieve March 2010
2874. XML Representation of Sieve
289 Sieve controls and actions are represented in XML as "control" or
290 "action" elements, respectively. The command's identifier appears as
291 a name attribute on the element itself. This is the only attribute
292 allowed on controls and actions -- arguments, tests, test-lists, and
293 nested command blocks are all represented as nested elements. While
294 naming the element after the control or action itself may seem like a
295 better choice, doing so would result in extensions requiring frequent
296 corresponding schema changes.
298 The example Sieve controls shown in the previous section would be
299 represented as these XML fragments:
301 <control name="stop"/>
303 <control name="require"><str>fileinto</str></control>
306 <test name="true"/><control name="stop"/>
309 The example Sieve actions shown above would appear in XML as:
311 <action name="discard"/>
312 <action name="fileinto"><str>folder</str></action>
314 The separation of controls from actions in the XML representation
315 means that conversion from normal Sieve format to XML has to be able
316 to distinguish between controls and actions. This is easily done by
317 maintaining a list of all known controls since experience indicates
318 new controls are rarely added. At the time of this writing, the list
319 of defined controls consists of:
325 3. require [RFC5228],
327 4. foreverypart [RFC5703], and
331 It should be noted that with this approach unknown controls will
332 simply be treated as actions and can be passed back and forth between
333 the two representations. The treatment of a control as an action is
338Freed & Vedam Standards Track [Page 6]
340RFC 5784 An XML Representation for Sieve March 2010
343 unlikely to cause other issues since knowledge of a control's
344 language semantics is almost always required to take advantage of it.
346 Tests are represented in the same basic way as controls and actions,
347 that is, as a "test" element with a name attribute giving the test
348 identifier. For example, the following XML fragments show various
353 <test name="envelope"/>
354 <str>to</str><str>me@example.com</str>
357 <test name="header"/>
358 <tag>is</tag><str>from</str><str>you@example.com</str>
361 String, number, and tag arguments are represented as "str", "num",
362 and "tag" elements, respectively. The actual string, number, or tag
363 identifier appears as text inside the element. None of these
364 elements have any defined attributes. Several examples of arguments
365 have already appeared in the preceding control, action, and test
366 examples. Any whitespace in the str body content MUST be preserved
367 by the processor. Also, note that since strings and tags are
368 represented as element text, any quotes or other syntactic elements
369 required in the regular Sieve representation are dropped rather than
370 being carried over into the XML.
372 String list arguments are represented as a "list" element, which in
373 turn contains one or more str elements. Note that this allows the
374 distinction between a single string and a string list containing a
375 single string to be preserved. This is not essential since a list
376 containing a single string could simply be mapped to a string, but it
377 seems prudent to maintain the distinction when mapping to and from
380 Nested command blocks appear as a series of control or action
381 elements inside of an outer control or action element. No block
382 element is needed since an inner command block can only appear once
383 and only after any arguments, tests, or test-lists. For example:
394Freed & Vedam Standards Track [Page 7]
396RFC 5784 An XML Representation for Sieve March 2010
403 <list><str>From</str><str>Date</str></list>
409 <str>fool@example.edu</str>
412 <action name="discard"/>
415 Sieve comments are mapped to a special "comment" element in XML.
416 Both hash and bracketed comments are mapped to the same construct so
417 the distinction between the two is lost in XML. XML comments are not
418 used because some XML tools do not make it convenient to access
421 Comments are allowed between commands and inside "test" elements.
422 But comments aren't allowed directly inside commands -- due to
423 limitations of XML Schema, special enclosing "preamble" and
424 "postamble" elements are needed:
428 <comment>Check to see if message should be discarded</comment>
433 <list><str>From</str><str>Date</str></list>
439 <str>fool@example.edu</str>
442 <action name="discard"/>
444 <comment>End of discard check</comment>
450Freed & Vedam Standards Track [Page 8]
452RFC 5784 An XML Representation for Sieve March 2010
4554.1. XML Display Directives
457 Sometimes graphical user interfaces are a convenient way to provide
458 Sieve management functions to users. These interfaces typically
459 summarize/annotate/group/display Sieve script(s) in an intuitive way
462 To do this effectively, the graphical user interface may require
463 additional information about the Sieve script itself. That
464 information or "meta-data" might include, but is not limited to, a
465 Sieve name (identifying the current Sieve), whether the Sieve is
466 enabled or disabled, and the order in which the parts of the Sieve
467 are presented to the user. The graphical user interface may also
468 choose to provide mechanisms to allow the user to modify the script.
470 It is often useful for a graphical user interface to group related
471 Sieve script elements and provide an interface that displays these
472 groups separately so they can be managed as a single object. Some
473 examples include Sieve statements that together provide vacation
474 responders, blacklists/whitelists, and other types of filtering
477 Some advanced graphical user interfaces may even provide a natural
478 language representation of a Sieve script and/or an advanced
479 interface to present Sieve statements directly to the user.
481 A graphical user interface may also choose to support only a subset
482 of action commands in the Sieve language (and its extensions), and so
483 a mechanism to indicate the extent of support and characterize the
484 relationships between those supported action commands and the test
485 (with its arguments) is immensely useful and probably required for
486 clients that may not have complete knowledge of Sieve grammar and
489 The Sieve language contains no mechanisms for indicating how a given
490 script should be presented in a user interface. The language also
491 does not contain any specific mechanisms to represent other sorts of
492 meta-data about the script. Providing support for such meta-data as
493 part of a Sieve script is currently totally implementation specific
494 and is usually done by imposing some type of structure on comments.
496 However, such information can be represented in XML very easily, so
497 it makes sense to define a framework to do this as part of the XML
498 format. Implementations MAY choose to use structured comments to
499 retain this information when the script is converted to normal Sieve
506Freed & Vedam Standards Track [Page 9]
508RFC 5784 An XML Representation for Sieve March 2010
511 The sample schemata for the XML representation of Sieve allows XML in
512 foreign namespaces to be inserted in the same places "comment"
513 elements can appear in Sieve scripts. This is the preferred means of
514 including additional information. Alternately, the schema defines
515 two display directives -- displayblock and displaydata -- as
516 containers for meta-data needed by graphical user interfaces.
518 Editors MAY use displayblock, displaydata, and foreign namespaces to
519 associate meta-data. Some editors find it inconvenient to preserve
520 this additional data during an editing session. Editors MAY preserve
521 this data during an editing session for compatibility with other
524 The displayblock element can be used to enclose any number of Sieve
525 statements at any level. It is semantically meaningless to the Sieve
526 script itself. It allows an arbitrary set of attributes.
527 Implementations MAY use this to provide many simple, display-related
528 meta-data for the Sieve such as Sieve identifier, group identifier,
529 order of processing, etc.
531 The displaydata element supports any number of arbitrary child
532 elements. Implementations MAY use this to represent complex data
533 about that Sieve such as a natural language representation of Sieve
534 or a way to provide the Sieve script directly.
5364.2. Structured Comments
538 Since the XML representation is not intended as a storage format,
539 there needs to be a way to preserve the additional information that
540 can be included in the XML representation in the normal Sieve syntax.
541 This is done through the use of three structured comment conventions:
543 1. XML content in other namespaces is placed in Sieve bracketed
544 comments beginning with the string "/* [/" and ending with the
547 2. The content of displaydata elements is placed in Sieve bracketed
548 comments beginning with the string "/* [|" and ending with the
551 3. The beginning of a displayblock element is mapped to a bracketed
552 Sieve comment beginning with the string "/* [*", which then lists
553 any displayblock attribute names and values in XML format. The
554 end of a displayblock element is mapped to a comment of the form
557 Processors MUST preserve the additional information allowed in the
558 XML format and SHOULD use the structured comment format shown above.
562Freed & Vedam Standards Track [Page 10]
564RFC 5784 An XML Representation for Sieve March 2010
567 Note: If "*/" is found in the XML content, when mapped into a
568 comment, it would prematurely terminate that comment. Escaping this
569 sequence would often be inconvenient for processors. Editors SHALL
570 NOT include "*/" within displayblock, displaydata, or foreign markup.
571 Processors MAY regard documents containing "*/" in foreign markup,
572 displayblock, or displaydata as invalid.
576 A processor MAY validate documents against a schema, and it MAY
577 reject any that do not conform. For any document that a processor
578 does not reject as invalid, any markup that the processor cannot
579 understand by reference to this specification MAY be discarded.
581 Note that example Relax NG and XML Schema are given in the appendices
5845. Security Considerations
586 Any syntactically valid Sieve script can be represented in XML.
587 Accordingly, all security considerations applicable to Sieve and any
588 extensions used also apply to the XML representation.
590 The use of XML carries its own security risks. Section 7 of RFC 3470
591 [RFC3470] discusses these risks.
593 It is axiomatic that a Sieve editor must be trusted to do what the
594 user specifies. If XML formats are used, this trust necessarily must
595 extend to the components involved in converting to and from XML
598 Arbitrary data can be included using other namespaces or placed in
599 the extensible displayblock and displaydata constructs defined in
600 this specification, possibly including entire scripts and other
601 executable content in languages other than Sieve. Such material will
602 necessarily have its own security considerations, which are beyond
603 the scope of this document.
6056. IANA Considerations
607 This section registers a new XML namespace per the procedures in RFC
618Freed & Vedam Standards Track [Page 11]
620RFC 5784 An XML Representation for Sieve March 2010
623 URI: urn:ietf:params:xml:ns:sieve
625 Registrant Contact: IETF Sieve working group
626 <ietf-mta-filters@imc.org>
631 <?xml version="1.0"?>
632 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
633 "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
634 <html xmlns="http://www.w3.org/1999/xhtml">
636 <meta http-equiv="content-type"
637 content="text/html;charset=iso-8859-1"/>
638 <title>Sieve Namespace</title>
641 <h1>Namespace for Sieve Language objects expressed in XML</h1>
642 <h2>urn:ietf:params:xml:ns:sieve</h2>
643 <p>See <a href="http://www.rfc-editor.org/rfc/rfc5784.txt">
6527.1. Normative References
654 [OASISRNC] Clark, J., "RELAX NG Compact Syntax", OASIS Committee
655 Specification rnc, November 2002.
657 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
658 Requirement Levels", BCP 14, RFC 2119, March 1997.
660 [RFC3470] Hollenbeck, S., Rose, M., and L. Masinter, "Guidelines
661 for the Use of Extensible Markup Language (XML)
662 within IETF Protocols", BCP 70, RFC 3470, January 2003.
664 [RFC3688] Mealling, M., "The IETF XML Registry", BCP 81, RFC 3688,
667 [RFC5228] Guenther, P. and T. Showalter, "Sieve: An Email Filtering
668 Language", RFC 5228, January 2008.
674Freed & Vedam Standards Track [Page 12]
676RFC 5784 An XML Representation for Sieve March 2010
679 [XML] Bray, T., Paoli, J., Sperberg-McQueen, C., Maler, E., and
680 F. Yergeau, "Extensible Markup Language (XML) 1.0 (Fifth
681 Edition)", W3C REC-xml-20081126, November 2008,
682 <http://www.w3.org/TR/2008/REC-xml-20081126/>.
6847.2. Informative References
686 [RFC5183] Freed, N., "Sieve Email Filtering: Environment
687 Extension", RFC 5183, May 2008.
689 [RFC5229] Homme, K., "Sieve Email Filtering: Variables Extension",
690 RFC 5229, January 2008.
692 [RFC5230] Showalter, T. and N. Freed, "Sieve Email Filtering:
693 Vacation Extension", RFC 5230, January 2008.
695 [RFC5231] Segmuller, W. and B. Leiba, "Sieve Email Filtering:
696 Relational Extension", RFC 5231, January 2008.
698 [RFC5232] Melnikov, A., "Sieve Email Filtering: Imap4flags
699 Extension", RFC 5232, January 2008.
701 [RFC5233] Murchison, K., "Sieve Email Filtering: Subaddress
702 Extension", RFC 5233, January 2008.
704 [RFC5235] Daboo, C., "Sieve Email Filtering: Spamtest and Virustest
705 Extensions", RFC 5235, January 2008.
707 [RFC5293] Degener, J. and P. Guenther, "Sieve Email Filtering:
708 Editheader Extension", RFC 5293, August 2008.
710 [RFC5703] Hansen, T. and C. Daboo, "Sieve Email Filtering: MIME
711 Part Tests, Iteration, Extraction, Replacement, and
712 Enclosure", RFC 5703, October 2009.
730Freed & Vedam Standards Track [Page 13]
732RFC 5784 An XML Representation for Sieve March 2010
735Appendix A. Extended Example
737 The example Sieve script given in Section 9 of [RFC5228] would be
738 represented in XML as the following code component:
740 <sieve xmlns="urn:ietf:params:xml:ns:sieve">
743 Declare any optional features or extensions used by the script
746 <control name="require">
750 Handle messages from known mailing lists.
751 Move messages from IETF filter discussion list to filter mailbox.
757 <str>owner-ietf-mta-filters@imc.org</str>
759 <action name="fileinto">
763 <comment>move to "filter" mailbox</comment>
768 Keep all messages to or from people in my company.
770 <control name="elsif">
771 <test name="address">
778 <str>example.com</str>
780 <action name="keep"/>
786Freed & Vedam Standards Track [Page 14]
788RFC 5784 An XML Representation for Sieve March 2010
792 Try and catch unsolicited email. If a message is not to me,
793 or it contains a subject known to be spam, file it away.
795 <control name="elsif">
798 <test name="address">
806 <str>me@example.com</str>
813 <str>*make*money*fast*</str>
814 <str>*university*dipl*mas*</str>
818 <action name="fileinto">
822 <control name="else">
825 Move all other (non-company) mail to "personal"
829 <action name="fileinto">
842Freed & Vedam Standards Track [Page 15]
844RFC 5784 An XML Representation for Sieve March 2010
847 The same script could be annotated with graphical display hints in a
848 variety of ways. Three possible code components that do this are:
850 <sieve xmlns="urn:ietf:params:xml:ns:sieve">
852 <control name="require">
856 <displayblock name="File filter list mail" order="1"
857 group="FILE_TO_FOLDER" enable="true">
862 <str>owner-ietf-mta-filters@imc.org</str>
864 <action name="fileinto">
870 <displayblock name="Keep all company mail" order="2"
871 group="KEEP_MESSAGE" enable="true">
872 <control name="elsif">
873 <test name="address">
880 <str>example.com</str>
882 <action name="keep"/>
886 <displayblock name="File suspected spam" order="3"
887 group="FILE_TO_FOLDER" enable="true">
888 <control name="elsif">
891 <test name="address">
898Freed & Vedam Standards Track [Page 16]
900RFC 5784 An XML Representation for Sieve March 2010
907 <str>me@example.com</str>
914 <str>*make*money*fast*</str>
915 <str>*university*dipl*mas*</str>
919 <action name="fileinto">
925 <displayblock name="File noncompany mail as personal" order="4"
926 group="FILE_TO_FOLDER" enable="true">
927 <control name="else">
928 <action name="fileinto">
936 Note that since displayblock elements are semantically null as far as
937 the script itself is concerned, they can be used to group structures
938 like elsif and else that are tied to statements in other groups.
954Freed & Vedam Standards Track [Page 17]
956RFC 5784 An XML Representation for Sieve March 2010
959 The representation of this script in regular Sieve syntax uses
963 /* [* name="File filter list mail" order="1"
964 group="FILE_TO_FOLDER" enable="true" */
965 if header :is "Sender" "owner-ietf-mta-filters@imc.org"
970 /* [* name="Keep all company mail" order="2"
971 group="KEEP_MESSAGE" enable="true" */
972 elsif address :domain :is [ "From", "To" ] "example.com"
977 /* [* name="File suspected spam" order="3"
978 group="FILE_TO_FOLDER" enable="true" */
979 elsif anyof ( not ( address :all :contains [ "To", "Cc", "Bcc" ]
981 header :matches "subject" [ "*make*money*fast*",
982 "*university*dipl*mas*" ] )
987 /* [* name="File noncompany mail as personal" order="4"
988 group="FILE_TO_FOLDER" enable="true" */
1010Freed & Vedam Standards Track [Page 18]
1012RFC 5784 An XML Representation for Sieve March 2010
1015 A separate namespace can be used to embed text or structured
1018 <sieve xmlns="urn:ietf:params:xml:ns:sieve"
1019 xmlns:nls="http://example.com/nls">
1021 <nls:interpretation>
1022 If the email header "Sender" is owner-ietf-mta-filters@imc.org,
1023 then file it into the "filter" folder.
1025 Otherwise, if the address in the "From" or "To" has a domain
1026 that is "example.com", then keep it.
1028 Otherwise, messages meeting with any of these conditions:
1030 (1) None of the addresses in "To", "Cc", or "Bcc" contain
1031 the domain "example.com".
1033 (2) The "Subject" field matches the pattern *make*money*fast*
1034 or *university*dipl*mas*, then file it into the "spam"
1037 If all else fails, then file the message in the "personal"
1039 </nls:interpretation>
1041 ... the actual Sieve script ...
1066Freed & Vedam Standards Track [Page 19]
1068RFC 5784 An XML Representation for Sieve March 2010
1071 Alternately, displaydata elements can be used to accomplish the same
1074 <sieve xmlns="urn:ietf:params:xml:ns:sieve">
1077 <nls-interpretation>
1078 If the email header "Sender" is owner-ietf-mta-filters@imc.org,
1079 then file it into the "filter" folder.
1081 Otherwise, if the address in the "From" or "To" has a domain
1082 that is "example.com", then keep it.
1084 Otherwise, messages meeting with any of these conditions:
1086 (1) None of the addresses in "To","Cc", or "Bcc" contain
1087 the domain "example.com".
1089 (2) The "Subject" field matches the pattern *make*money*fast*
1090 or *university*dipl*mas*, then file it into the "spam"
1093 If all else fails, then file the message in the "personal"
1095 </nls-interpretation>
1098 ... the actual Sieve script ...
1122Freed & Vedam Standards Track [Page 20]
1124RFC 5784 An XML Representation for Sieve March 2010
1127 Again, structured comments are used to represent this in regular
1131 <nls-interpretation>
1132 If the email header "Sender" is owner-ietf-mta-filters@imc.org,
1133 then file it into the "filter" folder.
1135 Otherwise, if the address in the "From" or "To" has a domain
1136 that is "example.com", then keep it.
1138 Otherwise, messages meeting with any of these conditions:
1140 (1) None of the addresses in "To","Cc", or "Bcc" contain
1141 the domain "example.com".
1143 (2) The "Subject" field matches the pattern *make*money*fast*
1144 or *university*dipl*mas*, then file it into the "spam"
1147 If all else fails, then file the message in the "personal"
1149 </nls-interpretation>
1152 ... the actual Sieve script ...
1154Appendix B. XML Schema for Sieves in XML
1156 This appendix is informative. The following code component is an XML
1157 Schema for the XML representation of Sieve scripts. Most of the
1158 elements employing a complex content model allow use of elements in
1159 other namespaces, subject to lax XML Schema validation rules.
1160 Additionally, displaydata elements can be used to encapsulate
1161 arbitrary XML content. Finally, displayblock elements can be used as
1162 a general-purpose grouping mechanism -- arbitrary attributes are
1163 allowed on displayblock elements.
1165 <?xml version="1.0" encoding="UTF-8"?>
1167 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1168 xmlns="urn:ietf:params:xml:ns:sieve"
1169 targetNamespace="urn:ietf:params:xml:ns:sieve">
1171 <xsd:element name="sieve">
1174 <xsd:choice maxOccurs="unbounded" minOccurs="0">
1178Freed & Vedam Standards Track [Page 21]
1180RFC 5784 An XML Representation for Sieve March 2010
1183 <xsd:element ref="control"/>
1184 <xsd:element ref="action"/>
1185 <xsd:element ref="displayblock"/>
1186 <xsd:element ref="displaydata"/>
1187 <xsd:element ref="comment"/>
1188 <xsd:any namespace="##other" processContents="lax"/>
1194 <xsd:element name="comment" type="xsd:string"/>
1196 <xsd:complexType name="ambles">
1197 <xsd:choice minOccurs="0" maxOccurs="unbounded">
1198 <xsd:element ref="displaydata"/>
1199 <xsd:element ref="comment"/>
1200 <xsd:any namespace="##other" processContents="lax"/>
1204 <xsd:element name="preamble" type="ambles"/>
1205 <xsd:element name="postamble" type="ambles"/>
1207 <xsd:complexType name="command">
1209 <xsd:element ref="preamble" minOccurs="0" maxOccurs="1"/>
1210 <xsd:choice minOccurs="0" maxOccurs="unbounded">
1211 <xsd:element ref="str"/>
1212 <xsd:element ref="num"/>
1213 <xsd:element ref="list"/>
1214 <xsd:element ref="tag"/>
1216 <xsd:element ref="test" minOccurs="0" maxOccurs="1"/>
1217 <xsd:choice minOccurs="0" maxOccurs="unbounded">
1218 <xsd:element ref="control"/>
1219 <xsd:element ref="action"/>
1220 <xsd:element ref="displayblock"/>
1222 <xsd:element ref="postamble" minOccurs="0" maxOccurs="1"/>
1224 <xsd:attribute use="required" name="name" type="identifier"/>
1227 <xsd:element name="control" type="command"/>
1228 <xsd:element name="action" type="command"/>
1230 <xsd:element name="test">
1234Freed & Vedam Standards Track [Page 22]
1236RFC 5784 An XML Representation for Sieve March 2010
1241 <xsd:choice minOccurs="0" maxOccurs="unbounded">
1242 <xsd:element ref="str"/>
1243 <xsd:element ref="num"/>
1244 <xsd:element ref="list"/>
1245 <xsd:element ref="tag"/>
1246 <xsd:element ref="displaydata"/>
1247 <xsd:element ref="comment"/>
1248 <xsd:any namespace="##other" processContents="lax"/>
1250 <xsd:element ref="test" minOccurs="0"
1251 maxOccurs="unbounded"/>
1253 <xsd:attribute use="required" name="name" type="identifier"/>
1257 <xsd:element name="list">
1260 <xsd:element ref="str" minOccurs="1"
1261 maxOccurs="unbounded"/>
1266 <xsd:element name="tag" type="identifier"/>
1268 <xsd:element name="str" type="xsd:string"/>
1270 <xsd:element name="num" type="xsd:nonNegativeInteger"/>
1272 <xsd:simpleType name="identifier">
1273 <xsd:restriction base="xsd:token">
1274 <xsd:pattern value="[A-Za-z_][A-Za-z0-9_]*"/>
1278 <xsd:element name="displayblock">
1281 <xsd:choice minOccurs="0" maxOccurs="unbounded">
1282 <xsd:element ref="control"/>
1283 <xsd:element ref="action"/>
1284 <xsd:element ref="displayblock"/>
1285 <xsd:element ref="displaydata"/>
1286 <xsd:element ref="comment"/>
1290Freed & Vedam Standards Track [Page 23]
1292RFC 5784 An XML Representation for Sieve March 2010
1295 <xsd:any namespace="##other" processContents="lax"/>
1298 <xsd:anyAttribute processContents="skip"/>
1302 <xsd:element name="displaydata">
1304 <xsd:sequence minOccurs="0" maxOccurs="unbounded">
1305 <xsd:any processContents="skip"/>
1312Appendix C. Relax NG Schema for Sieves in XML
1314 This appendix is informative. The following code component defines a
1315 Relax NG Schema using compact notation OASISRNC [OASISRNC] for the
1316 XML representation of Sieve scripts. Most of the elements employing
1317 a complex content model allow unrestricted use of elements in other
1318 namespaces. Additionally, displaydata elements can be used to
1319 encapsulate arbitrary XML content. Finally, displayblock elements
1320 can be used as a general-purpose grouping mechanism -- arbitrary
1321 attributes are allowed on displayblock elements.
1323 namespace sieve = "urn:ietf:params:xml:ns:sieve"
1325 start = element sieve:sieve { ( control | action | displayblock |
1326 displaydata | comment | ext )* }
1328 comment = element sieve:comment { xsd:string }
1332 ( displaydata | comment | ext )*
1336 preamble = element sieve:preamble { ambles }
1337 postamble = element sieve:postamble { ambles }
1346Freed & Vedam Standards Track [Page 24]
1348RFC 5784 An XML Representation for Sieve March 2010
1351 pattern = "[A-Za-z_][A-Za-z0-9_]*" } },
1353 ( str | num | \list | tag )*,
1355 ( control | action | displayblock)*,
1360 control = element sieve:control { command }
1361 action = element sieve:action { command }
1368 pattern = "[A-Za-z_][A-Za-z0-9_]*" } },
1369 ( str | num | \list | tag | comment | ext )*,
1373 \list = element sieve:list { str+ }
1375 tag = element sieve:tag {
1377 pattern = "[A-Za-z_][A-Za-z0-9_]*" } }
1379 str = element sieve:str { xsd:string }
1381 num = element sieve:num { xsd:nonNegativeInteger }
1383 any = ( element * { any } | attribute * { text } | text )*
1385 ext = element * - sieve:* { any }*
1388 element sieve:displayblock
1390 ( control | action | displayblock |
1391 displaydata | comment | ext )*,
1392 attribute * { text }*
1395 displaydata = element sieve:displaydata { any* }
1402Freed & Vedam Standards Track [Page 25]
1404RFC 5784 An XML Representation for Sieve March 2010
1407Appendix D. Stylesheet for Conversion from XML
1409 This appendix is informative. The following code component is a
1410 stylesheet that can be used to convert the Sieve in XML
1411 representation to regular Sieve format. Content in other namespaces,
1412 displaydata, and displayblock elements are converted to structured
1413 comments as appropriate.
1415 <?xml version="1.0" encoding="UTF-8"?>
1417 <!-- Convert Sieve in XML to standard Sieve syntax -->
1419 <xsl:stylesheet version="1.0"
1420 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1421 xmlns:sieve="urn:ietf:params:xml:ns:sieve">
1423 <xsl:output method="text" encoding="UTF-8"
1424 media-type="application/sieve"/>
1426 <!-- Only preserve whitespace in str elements -->
1427 <xsl:strip-space elements="*"/>
1428 <xsl:preserve-space elements="sieve:str"/>
1430 <!-- Match top level sieve node,
1431 start processing in sieve mode -->
1433 <xsl:template match="sieve:sieve">
1434 <xsl:apply-templates select="*" mode="sieve">
1435 <xsl:with-param name="prefix" select="''"/>
1436 </xsl:apply-templates>
1439 <!-- Routine to properly literalize quotes in Sieve strings -->
1441 <xsl:template name="quote-string">
1442 <xsl:param name="str"/>
1444 <xsl:when test="not($str)"/>
1445 <xsl:when test="contains($str, '"')">
1446 <xsl:call-template name="quote-string">
1447 <xsl:with-param name="str"
1448 select="substring-before($str, '"')"/>
1449 </xsl:call-template>
1450 <xsl:text>\"</xsl:text>
1451 <xsl:call-template name="quote-string">
1452 <xsl:with-param name="str"
1453 select="substring-after($str, '"')"/>
1454 </xsl:call-template>
1458Freed & Vedam Standards Track [Page 26]
1460RFC 5784 An XML Representation for Sieve March 2010
1464 <xsl:when test="contains($str, '\')">
1465 <xsl:call-template name="quote-string">
1466 <xsl:with-param name="str"
1467 select="substring-before($str, '\')"/>
1468 </xsl:call-template>
1469 <xsl:text>\\</xsl:text>
1470 <xsl:call-template name="quote-string">
1471 <xsl:with-param name="str"
1472 select="substring-after($str, '\')"/>
1473 </xsl:call-template>
1476 <xsl:value-of select="$str"/>
1481 <!-- Sieve mode processing templates -->
1483 <xsl:template match="sieve:control|sieve:action" mode="sieve">
1484 <xsl:param name="prefix"/>
1485 <xsl:text xml:space="preserve">
1487 <xsl:value-of select="$prefix"/>
1488 <xsl:value-of select="@name"/>
1489 <xsl:variable name="blockbegin"
1490 select="generate-id(sieve:control|sieve:action)"/>
1491 <xsl:for-each select="*">
1493 <xsl:when test="self::sieve:str|self::sieve:num|
1494 self::sieve:list|self::sieve:tag|
1496 <xsl:apply-templates select="." mode="sieve"/>
1498 <xsl:when test="generate-id(.) = $blockbegin">
1499 <xsl:text xml:space="preserve">
1501 <xsl:value-of select="$prefix"/>
1502 <xsl:text>{</xsl:text>
1503 <xsl:apply-templates select="." mode="sieve">
1504 <xsl:with-param name="prefix"
1505 select="concat($prefix, ' ')"/>
1506 </xsl:apply-templates>
1509 <xsl:apply-templates select="." mode="sieve">
1510 <xsl:with-param name="prefix"
1514Freed & Vedam Standards Track [Page 27]
1516RFC 5784 An XML Representation for Sieve March 2010
1519 select="concat($prefix, ' ')"/>
1520 </xsl:apply-templates>
1525 <xsl:when test="count(sieve:control|sieve:action) > 0">
1526 <xsl:text xml:space="preserve">
1528 <xsl:value-of select="$prefix"/>
1529 <xsl:text>}</xsl:text>
1532 <xsl:text>;</xsl:text>
1537 <xsl:template match="sieve:preamble|sieve:postamble" mode="sieve">
1538 <xsl:param name="prefix"/>
1539 <xsl:apply-templates mode="sieve">
1540 <xsl:with-param name="prefix" select="$prefix"/>
1541 </xsl:apply-templates>
1544 <xsl:template match="sieve:test" mode="sieve">
1545 <xsl:text xml:space="preserve"> </xsl:text>
1546 <xsl:value-of select="@name"/>
1547 <xsl:apply-templates select="*[not(self::sieve:test)]"
1549 <xsl:if test="count(descendant::sieve:test) > 0">
1550 <xsl:text> (</xsl:text>
1551 <xsl:for-each select="sieve:test">
1552 <xsl:apply-templates select="." mode="sieve"/>
1553 <xsl:if test="count(following-sibling::sieve:test) > 0">
1554 <xsl:text>,</xsl:text>
1557 <xsl:text> )</xsl:text>
1561 <xsl:template match="sieve:str" mode="sieve">
1562 <xsl:text> "</xsl:text>
1563 <xsl:call-template name="quote-string">
1564 <xsl:with-param name="str" select="text()"/>
1565 </xsl:call-template>
1566 <xsl:text>"</xsl:text>
1570Freed & Vedam Standards Track [Page 28]
1572RFC 5784 An XML Representation for Sieve March 2010
1577 <xsl:template match="sieve:num" mode="sieve">
1578 <xsl:text xml:space="preserve"> </xsl:text>
1579 <!-- Use numeric suffixes when possible -->
1581 <xsl:when test="(number(text()) mod 1073741824) = 0">
1582 <xsl:value-of select="number(text()) div 1073741824"/>
1583 <xsl:text>G</xsl:text>
1585 <xsl:when test="(number(text()) mod 1048576) = 0">
1586 <xsl:value-of select="number(text()) div 1048576"/>
1587 <xsl:text>M</xsl:text>
1589 <xsl:when test="(number(text()) mod 1024) = 0">
1590 <xsl:value-of select="number(text()) div 1024"/>
1591 <xsl:text>K</xsl:text>
1594 <xsl:value-of select="text()"/>
1599 <xsl:template match="sieve:list" mode="sieve">
1600 <xsl:text> [</xsl:text>
1601 <xsl:for-each select="sieve:str">
1602 <xsl:apply-templates select="." mode="sieve"/>
1603 <xsl:if test="count(following-sibling::sieve:str) > 0">
1604 <xsl:text>,</xsl:text>
1607 <xsl:text> ]</xsl:text>
1610 <xsl:template match="sieve:tag" mode="sieve">
1611 <xsl:text> :</xsl:text>
1612 <xsl:value-of select="text()"/>
1615 <xsl:template match="sieve:comment" mode="sieve">
1616 <xsl:param name="prefix"/>
1617 <xsl:text xml:space="preserve">
1619 <xsl:value-of select="$prefix"/>
1620 <xsl:text>/*</xsl:text>
1621 <xsl:value-of select="."/>
1622 <xsl:value-of select="$prefix"/>
1626Freed & Vedam Standards Track [Page 29]
1628RFC 5784 An XML Representation for Sieve March 2010
1631 <xsl:text>*/</xsl:text>
1634 <!-- Convert display information into structured comments -->
1636 <xsl:template match="sieve:displayblock" mode="sieve">
1637 <xsl:param name="prefix"/>
1638 <xsl:text xml:space="preserve">
1640 <xsl:value-of select="$prefix"/>
1641 <xsl:text>/* [*</xsl:text>
1642 <xsl:apply-templates select="@*" mode="copy"/>
1643 <xsl:text> */</xsl:text>
1644 <xsl:apply-templates select="*" mode="sieve">
1645 <xsl:with-param name="prefix" select="$prefix"/>
1646 </xsl:apply-templates>
1647 <xsl:text xml:space="preserve">
1649 <xsl:value-of select="$prefix"/>
1650 <xsl:text>/* *] */</xsl:text>
1653 <xsl:template match="sieve:displaydata" mode="sieve">
1654 <xsl:param name="prefix"/>
1655 <xsl:text xml:space="preserve">
1657 <xsl:value-of select="$prefix"/>
1658 <xsl:text>/* [|</xsl:text>
1659 <xsl:apply-templates mode="copy">
1660 <xsl:with-param name="prefix"
1661 select="concat($prefix, ' ')"/>
1662 </xsl:apply-templates>
1663 <xsl:text xml:space="preserve">
1665 <xsl:value-of select="$prefix"/>
1666 <xsl:text> |] */</xsl:text>
1669 <!-- Copy unrecnognized nodes and their descendants -->
1671 <xsl:template match="*" mode="sieve">
1672 <xsl:param name="prefix"/>
1673 <xsl:text xml:space="preserve">
1675 <xsl:value-of select="$prefix"/>
1676 <xsl:text>/* [/</xsl:text>
1677 <xsl:apply-templates select="." mode="copy">
1678 <xsl:with-param name="prefix"
1682Freed & Vedam Standards Track [Page 30]
1684RFC 5784 An XML Representation for Sieve March 2010
1687 select="concat($prefix, ' ')"/>
1688 </xsl:apply-templates>
1689 <xsl:text xml:space="preserve">
1691 <xsl:value-of select="$prefix"/>
1692 <xsl:text> /] */</xsl:text>
1695 <!-- Copy mode processing templates -->
1697 <xsl:template match="*[not(node())]" mode="copy">
1698 <xsl:param name="prefix"/>
1699 <xsl:text xml:space="preserve">
1701 <xsl:value-of select="$prefix"/>
1702 <xsl:text><</xsl:text>
1703 <xsl:value-of select="name()"/>
1704 <xsl:apply-templates select="@*" mode="copy"/>
1705 <xsl:text>/></xsl:text>
1708 <xsl:template match="*[node()]" mode="copy">
1709 <xsl:param name="prefix"/>
1710 <xsl:text xml:space="preserve">
1712 <xsl:value-of select="$prefix"/>
1713 <xsl:text><</xsl:text>
1714 <xsl:value-of select="name()"/>
1715 <xsl:apply-templates select="@*" mode="copy"/>
1716 <xsl:text>></xsl:text>
1717 <xsl:apply-templates mode="copy">
1718 <xsl:with-param name="prefix"
1719 select="concat($prefix, ' ')"/>
1720 </xsl:apply-templates>
1721 <xsl:if test="*[last()][not(text())]">
1722 <xsl:text xml:space="preserve">
1724 <xsl:value-of select="$prefix"/>
1726 <xsl:text></</xsl:text>
1727 <xsl:value-of select="name()"/>
1728 <xsl:text>></xsl:text>
1731 <xsl:template match="@*" mode="copy">
1732 <xsl:text> </xsl:text>
1733 <xsl:value-of select="name()"/>
1734 <xsl:text>="</xsl:text>
1738Freed & Vedam Standards Track [Page 31]
1740RFC 5784 An XML Representation for Sieve March 2010
1743 <xsl:value-of select="."/>
1744 <xsl:text>"</xsl:text>
1749Appendix E. Acknowledgements
1751 The stylesheet copy mode code is loosely based on a sample code
1752 posted to the xsl-list list by Americo Albuquerque. Jari Arkko,
1753 Robert Burrell Donkin, Andrew McKeon, Alexey Melnikov, and Aaron
1754 Stone provided useful comments on the document.
1761 Monrovia, CA 91016-6347
1764 Phone: +1 909 457 4293
1765 EMail: ned.freed@mrochek.com
1768 Srinivas Saisatish Vedam
1771 Phone: +91 80669 27577
1772 EMail: Srinivas.Sv@Sun.COM
1794Freed & Vedam Standards Track [Page 32]