1
2
3
4
5
6
7Internet Engineering Task Force (IETF) N. Freed
8Request for Comments: 5784 S. Vedam
9Category: Standards Track Sun Microsystems
10ISSN: 2070-1721 March 2010
11
12
13 Sieve Email Filtering: Sieves and Display Directives in XML
14
15Abstract
16
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.
21
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.
28
29Status of This Memo
30
31 This is an Internet Standards Track document.
32
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.
38
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.
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58Freed & Vedam Standards Track [Page 1]
59
60RFC 5784 An XML Representation for Sieve March 2010
61
62
63Copyright Notice
64
65 Copyright (c) 2010 IETF Trust and the persons identified as the
66 document authors. All rights reserved.
67
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.
77
78Table of Contents
79
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114Freed & Vedam Standards Track [Page 2]
115
116RFC 5784 An XML Representation for Sieve March 2010
117
118
1191. Introduction
120
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.
127
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.
135
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
140 storage facilities.
141
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
150 format.
151
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
155 will interoperate.
156
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.
166
167
168
169
170Freed & Vedam Standards Track [Page 3]
171
172RFC 5784 An XML Representation for Sieve March 2010
173
174
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.
185
1862. Conventions Used in This Document
187
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].
191
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.
196
1973. Grammatical Structure of Sieve
198
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.
203
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.
210
211 Some example Sieve controls are:
212
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
216
217 Some examples of Sieve actions are:
218
219discard; <-- Action with no arguments, test, or command block
220fileinto "folder"; <-- Action with an argument
221
222
223
224
225
226Freed & Vedam Standards Track [Page 4]
227
228RFC 5784 An XML Representation for Sieve March 2010
229
230
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.
236
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.
240
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:
243
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
247
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.
253
254 Here is an example showing the use of both a test-list and a string
255 list:
256
257 if anyof (not exists ["From", "Date"],
258 header :contains "from" "fool@example.edu") {
259 discard;
260 }
261
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.
270
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.
275
276
277
278
279
280
281
282Freed & Vedam Standards Track [Page 5]
283
284RFC 5784 An XML Representation for Sieve March 2010
285
286
2874. XML Representation of Sieve
288
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.
297
298 The example Sieve controls shown in the previous section would be
299 represented as these XML fragments:
300
301 <control name="stop"/>
302
303 <control name="require"><str>fileinto</str></control>
304
305 <control name="if">
306 <test name="true"/><control name="stop"/>
307 </control>
308
309 The example Sieve actions shown above would appear in XML as:
310
311 <action name="discard"/>
312 <action name="fileinto"><str>folder</str></action>
313
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:
320
321 1. if [RFC5228],
322
323 2. stop [RFC5228],
324
325 3. require [RFC5228],
326
327 4. foreverypart [RFC5703], and
328
329 5. break [RFC5703].
330
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
334
335
336
337
338Freed & Vedam Standards Track [Page 6]
339
340RFC 5784 An XML Representation for Sieve March 2010
341
342
343 unlikely to cause other issues since knowledge of a control's
344 language semantics is almost always required to take advantage of it.
345
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
349 types of tests:
350
351 <test name="true"/>
352
353 <test name="envelope"/>
354 <str>to</str><str>me@example.com</str>
355 </test>
356
357 <test name="header"/>
358 <tag>is</tag><str>from</str><str>you@example.com</str>
359 </test>
360
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.
371
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
378 XML.
379
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:
384
385
386
387
388
389
390
391
392
393
394Freed & Vedam Standards Track [Page 7]
395
396RFC 5784 An XML Representation for Sieve March 2010
397
398
399 <control name="if">
400 <test name="anyof">
401 <test name="not">
402 <test name="exists">
403 <list><str>From</str><str>Date</str></list>
404 </test>
405 </test>
406 <test name="header">
407 <tag>contains</tag>
408 <str>from</str>
409 <str>fool@example.edu</str>
410 </test>
411 </test>
412 <action name="discard"/>
413 </control>
414
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
419 comment nodes.
420
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:
425
426 <control name="if">
427 <preamble>
428 <comment>Check to see if message should be discarded</comment>
429 </preamble>
430 <test name="anyof">
431 <test name="not">
432 <test name="exists">
433 <list><str>From</str><str>Date</str></list>
434 </test>
435 </test>
436 <test name="header">
437 <tag>contains</tag>
438 <str>from</str>
439 <str>fool@example.edu</str>
440 </test>
441 </test>
442 <action name="discard"/>
443 <postamble>
444 <comment>End of discard check</comment>
445 </postamble>
446 </control>
447
448
449
450Freed & Vedam Standards Track [Page 8]
451
452RFC 5784 An XML Representation for Sieve March 2010
453
454
4554.1. XML Display Directives
456
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
460 for end users.
461
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.
469
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
475 controls.
476
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.
480
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
487 semantics.
488
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.
495
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
500 format.
501
502
503
504
505
506Freed & Vedam Standards Track [Page 9]
507
508RFC 5784 An XML Representation for Sieve March 2010
509
510
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.
517
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
522 editors.
523
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.
530
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.
535
5364.2. Structured Comments
537
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:
542
543 1. XML content in other namespaces is placed in Sieve bracketed
544 comments beginning with the string "/* [/" and ending with the
545 string "/] */".
546
547 2. The content of displaydata elements is placed in Sieve bracketed
548 comments beginning with the string "/* [|" and ending with the
549 string "|] */".
550
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
555 "*] */".
556
557 Processors MUST preserve the additional information allowed in the
558 XML format and SHOULD use the structured comment format shown above.
559
560
561
562Freed & Vedam Standards Track [Page 10]
563
564RFC 5784 An XML Representation for Sieve March 2010
565
566
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.
573
5744.3. Validation
575
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.
580
581 Note that example Relax NG and XML Schema are given in the appendices
582 below.
583
5845. Security Considerations
585
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.
589
590 The use of XML carries its own security risks. Section 7 of RFC 3470
591 [RFC3470] discusses these risks.
592
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
596 format.
597
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.
604
6056. IANA Considerations
606
607 This section registers a new XML namespace per the procedures in RFC
608 3688 [RFC3688].
609
610
611
612
613
614
615
616
617
618Freed & Vedam Standards Track [Page 11]
619
620RFC 5784 An XML Representation for Sieve March 2010
621
622
623 URI: urn:ietf:params:xml:ns:sieve
624
625 Registrant Contact: IETF Sieve working group
626 <ietf-mta-filters@imc.org>
627
628 XML:
629
630 BEGIN
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">
635 <head>
636 <meta http-equiv="content-type"
637 content="text/html;charset=iso-8859-1"/>
638 <title>Sieve Namespace</title>
639 </head>
640 <body>
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">
644 RFC 5784</a>.
645 </p>
646 </body>
647 </html>
648 END
649
6507. References
651
6527.1. Normative References
653
654 [OASISRNC] Clark, J., "RELAX NG Compact Syntax", OASIS Committee
655 Specification rnc, November 2002.
656
657 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
658 Requirement Levels", BCP 14, RFC 2119, March 1997.
659
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.
663
664 [RFC3688] Mealling, M., "The IETF XML Registry", BCP 81, RFC 3688,
665 January 2004.
666
667 [RFC5228] Guenther, P. and T. Showalter, "Sieve: An Email Filtering
668 Language", RFC 5228, January 2008.
669
670
671
672
673
674Freed & Vedam Standards Track [Page 12]
675
676RFC 5784 An XML Representation for Sieve March 2010
677
678
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/>.
683
6847.2. Informative References
685
686 [RFC5183] Freed, N., "Sieve Email Filtering: Environment
687 Extension", RFC 5183, May 2008.
688
689 [RFC5229] Homme, K., "Sieve Email Filtering: Variables Extension",
690 RFC 5229, January 2008.
691
692 [RFC5230] Showalter, T. and N. Freed, "Sieve Email Filtering:
693 Vacation Extension", RFC 5230, January 2008.
694
695 [RFC5231] Segmuller, W. and B. Leiba, "Sieve Email Filtering:
696 Relational Extension", RFC 5231, January 2008.
697
698 [RFC5232] Melnikov, A., "Sieve Email Filtering: Imap4flags
699 Extension", RFC 5232, January 2008.
700
701 [RFC5233] Murchison, K., "Sieve Email Filtering: Subaddress
702 Extension", RFC 5233, January 2008.
703
704 [RFC5235] Daboo, C., "Sieve Email Filtering: Spamtest and Virustest
705 Extensions", RFC 5235, January 2008.
706
707 [RFC5293] Degener, J. and P. Guenther, "Sieve Email Filtering:
708 Editheader Extension", RFC 5293, August 2008.
709
710 [RFC5703] Hansen, T. and C. Daboo, "Sieve Email Filtering: MIME
711 Part Tests, Iteration, Extraction, Replacement, and
712 Enclosure", RFC 5703, October 2009.
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730Freed & Vedam Standards Track [Page 13]
731
732RFC 5784 An XML Representation for Sieve March 2010
733
734
735Appendix A. Extended Example
736
737 The example Sieve script given in Section 9 of [RFC5228] would be
738 represented in XML as the following code component:
739
740 <sieve xmlns="urn:ietf:params:xml:ns:sieve">
741 <comment>
742 Example Sieve Filter
743 Declare any optional features or extensions used by the script
744 </comment>
745
746 <control name="require">
747 <str>fileinto</str>
748 </control>
749 <comment>
750 Handle messages from known mailing lists.
751 Move messages from IETF filter discussion list to filter mailbox.
752 </comment>
753 <control name="if">
754 <test name="header">
755 <tag>is</tag>
756 <str>Sender</str>
757 <str>owner-ietf-mta-filters@imc.org</str>
758 </test>
759 <action name="fileinto">
760 <str>filter</str>
761 </action>
762 <postamble>
763 <comment>move to "filter" mailbox</comment>
764 </postamble>
765 </control>
766
767 <comment>
768 Keep all messages to or from people in my company.
769 </comment>
770 <control name="elsif">
771 <test name="address">
772 <tag>domain</tag>
773 <tag>is</tag>
774 <list>
775 <str>From</str>
776 <str>To</str>
777 </list>
778 <str>example.com</str>
779 </test>
780 <action name="keep"/>
781 </control>
782
783
784
785
786Freed & Vedam Standards Track [Page 14]
787
788RFC 5784 An XML Representation for Sieve March 2010
789
790
791 <comment>
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.
794 </comment>
795 <control name="elsif">
796 <test name="anyof">
797 <test name="not">
798 <test name="address">
799 <tag>all</tag>
800 <tag>contains</tag>
801 <list>
802 <str>To</str>
803 <str>Cc</str>
804 <str>Bcc</str>
805 </list>
806 <str>me@example.com</str>
807 </test>
808 </test>
809 <test name="header">
810 <tag>matches</tag>
811 <str>subject</str>
812 <list>
813 <str>*make*money*fast*</str>
814 <str>*university*dipl*mas*</str>
815 </list>
816 </test>
817 </test>
818 <action name="fileinto">
819 <str>spam</str>
820 </action>
821 </control>
822 <control name="else">
823 <preamble>
824 <comment>
825 Move all other (non-company) mail to "personal"
826 mailbox.
827 </comment>
828 </preamble>
829 <action name="fileinto">
830 <str>personal</str>
831 </action>
832 </control>
833
834 </sieve>
835
836
837
838
839
840
841
842Freed & Vedam Standards Track [Page 15]
843
844RFC 5784 An XML Representation for Sieve March 2010
845
846
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:
849
850 <sieve xmlns="urn:ietf:params:xml:ns:sieve">
851
852 <control name="require">
853 <str>fileinto</str>
854 </control>
855
856 <displayblock name="File filter list mail" order="1"
857 group="FILE_TO_FOLDER" enable="true">
858 <control name="if">
859 <test name="header">
860 <tag>is</tag>
861 <str>Sender</str>
862 <str>owner-ietf-mta-filters@imc.org</str>
863 </test>
864 <action name="fileinto">
865 <str>filter</str>
866 </action>
867 </control>
868 </displayblock>
869
870 <displayblock name="Keep all company mail" order="2"
871 group="KEEP_MESSAGE" enable="true">
872 <control name="elsif">
873 <test name="address">
874 <tag>domain</tag>
875 <tag>is</tag>
876 <list>
877 <str>From</str>
878 <str>To</str>
879 </list>
880 <str>example.com</str>
881 </test>
882 <action name="keep"/>
883 </control>
884 </displayblock>
885
886 <displayblock name="File suspected spam" order="3"
887 group="FILE_TO_FOLDER" enable="true">
888 <control name="elsif">
889 <test name="anyof">
890 <test name="not">
891 <test name="address">
892 <tag>all</tag>
893 <tag>contains</tag>
894 <list>
895
896
897
898Freed & Vedam Standards Track [Page 16]
899
900RFC 5784 An XML Representation for Sieve March 2010
901
902
903 <str>To</str>
904 <str>Cc</str>
905 <str>Bcc</str>
906 </list>
907 <str>me@example.com</str>
908 </test>
909 </test>
910 <test name="header">
911 <tag>matches</tag>
912 <str>subject</str>
913 <list>
914 <str>*make*money*fast*</str>
915 <str>*university*dipl*mas*</str>
916 </list>
917 </test>
918 </test>
919 <action name="fileinto">
920 <str>spam</str>
921 </action>
922 </control>
923 </displayblock>
924
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">
929 <str>personal</str>
930 </action>
931 </control>
932 </displayblock>
933
934 </sieve>
935
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.
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954Freed & Vedam Standards Track [Page 17]
955
956RFC 5784 An XML Representation for Sieve March 2010
957
958
959 The representation of this script in regular Sieve syntax uses
960 structured comments:
961
962 require "fileinto";
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"
966 {
967 fileinto "filter";
968 }
969 /* *] */
970 /* [* name="Keep all company mail" order="2"
971 group="KEEP_MESSAGE" enable="true" */
972 elsif address :domain :is [ "From", "To" ] "example.com"
973 {
974 keep;
975 }
976 /* *] */
977 /* [* name="File suspected spam" order="3"
978 group="FILE_TO_FOLDER" enable="true" */
979 elsif anyof ( not ( address :all :contains [ "To", "Cc", "Bcc" ]
980 "me@example.com" ),
981 header :matches "subject" [ "*make*money*fast*",
982 "*university*dipl*mas*" ] )
983 {
984 fileinto "spam";
985 }
986 /* *] */
987 /* [* name="File noncompany mail as personal" order="4"
988 group="FILE_TO_FOLDER" enable="true" */
989 else
990 {
991 fileinto "personal";
992 }
993 /* *] */
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010Freed & Vedam Standards Track [Page 18]
1011
1012RFC 5784 An XML Representation for Sieve March 2010
1013
1014
1015 A separate namespace can be used to embed text or structured
1016 information:
1017
1018 <sieve xmlns="urn:ietf:params:xml:ns:sieve"
1019 xmlns:nls="http://example.com/nls">
1020
1021 <nls:interpretation>
1022 If the email header "Sender" is owner-ietf-mta-filters@imc.org,
1023 then file it into the "filter" folder.
1024
1025 Otherwise, if the address in the "From" or "To" has a domain
1026 that is "example.com", then keep it.
1027
1028 Otherwise, messages meeting with any of these conditions:
1029
1030 (1) None of the addresses in "To", "Cc", or "Bcc" contain
1031 the domain "example.com".
1032
1033 (2) The "Subject" field matches the pattern *make*money*fast*
1034 or *university*dipl*mas*, then file it into the "spam"
1035 folder.
1036
1037 If all else fails, then file the message in the "personal"
1038 folder.
1039 </nls:interpretation>
1040
1041 ... the actual Sieve script ...
1042
1043 </sieve>
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066Freed & Vedam Standards Track [Page 19]
1067
1068RFC 5784 An XML Representation for Sieve March 2010
1069
1070
1071 Alternately, displaydata elements can be used to accomplish the same
1072 thing:
1073
1074 <sieve xmlns="urn:ietf:params:xml:ns:sieve">
1075
1076 <displaydata>
1077 <nls-interpretation>
1078 If the email header "Sender" is owner-ietf-mta-filters@imc.org,
1079 then file it into the "filter" folder.
1080
1081 Otherwise, if the address in the "From" or "To" has a domain
1082 that is "example.com", then keep it.
1083
1084 Otherwise, messages meeting with any of these conditions:
1085
1086 (1) None of the addresses in "To","Cc", or "Bcc" contain
1087 the domain "example.com".
1088
1089 (2) The "Subject" field matches the pattern *make*money*fast*
1090 or *university*dipl*mas*, then file it into the "spam"
1091 folder.
1092
1093 If all else fails, then file the message in the "personal"
1094 folder.
1095 </nls-interpretation>
1096 </displaydata>
1097
1098 ... the actual Sieve script ...
1099
1100 </sieve>
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122Freed & Vedam Standards Track [Page 20]
1123
1124RFC 5784 An XML Representation for Sieve March 2010
1125
1126
1127 Again, structured comments are used to represent this in regular
1128 Sieve syntax:
1129
1130 /* [|
1131 <nls-interpretation>
1132 If the email header "Sender" is owner-ietf-mta-filters@imc.org,
1133 then file it into the "filter" folder.
1134
1135 Otherwise, if the address in the "From" or "To" has a domain
1136 that is "example.com", then keep it.
1137
1138 Otherwise, messages meeting with any of these conditions:
1139
1140 (1) None of the addresses in "To","Cc", or "Bcc" contain
1141 the domain "example.com".
1142
1143 (2) The "Subject" field matches the pattern *make*money*fast*
1144 or *university*dipl*mas*, then file it into the "spam"
1145 folder.
1146
1147 If all else fails, then file the message in the "personal"
1148 folder.
1149 </nls-interpretation>
1150 |] */
1151
1152 ... the actual Sieve script ...
1153
1154Appendix B. XML Schema for Sieves in XML
1155
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.
1164
1165 <?xml version="1.0" encoding="UTF-8"?>
1166
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">
1170
1171 <xsd:element name="sieve">
1172 <xsd:complexType>
1173 <xsd:sequence>
1174 <xsd:choice maxOccurs="unbounded" minOccurs="0">
1175
1176
1177
1178Freed & Vedam Standards Track [Page 21]
1179
1180RFC 5784 An XML Representation for Sieve March 2010
1181
1182
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"/>
1189 </xsd:choice>
1190 </xsd:sequence>
1191 </xsd:complexType>
1192 </xsd:element>
1193
1194 <xsd:element name="comment" type="xsd:string"/>
1195
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"/>
1201 </xsd:choice>
1202 </xsd:complexType>
1203
1204 <xsd:element name="preamble" type="ambles"/>
1205 <xsd:element name="postamble" type="ambles"/>
1206
1207 <xsd:complexType name="command">
1208 <xsd:sequence>
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"/>
1215 </xsd:choice>
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"/>
1221 </xsd:choice>
1222 <xsd:element ref="postamble" minOccurs="0" maxOccurs="1"/>
1223 </xsd:sequence>
1224 <xsd:attribute use="required" name="name" type="identifier"/>
1225 </xsd:complexType>
1226
1227 <xsd:element name="control" type="command"/>
1228 <xsd:element name="action" type="command"/>
1229
1230 <xsd:element name="test">
1231
1232
1233
1234Freed & Vedam Standards Track [Page 22]
1235
1236RFC 5784 An XML Representation for Sieve March 2010
1237
1238
1239 <xsd:complexType>
1240 <xsd:sequence>
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"/>
1249 </xsd:choice>
1250 <xsd:element ref="test" minOccurs="0"
1251 maxOccurs="unbounded"/>
1252 </xsd:sequence>
1253 <xsd:attribute use="required" name="name" type="identifier"/>
1254 </xsd:complexType>
1255 </xsd:element>
1256
1257 <xsd:element name="list">
1258 <xsd:complexType>
1259 <xsd:sequence>
1260 <xsd:element ref="str" minOccurs="1"
1261 maxOccurs="unbounded"/>
1262 </xsd:sequence>
1263 </xsd:complexType>
1264 </xsd:element>
1265
1266 <xsd:element name="tag" type="identifier"/>
1267
1268 <xsd:element name="str" type="xsd:string"/>
1269
1270 <xsd:element name="num" type="xsd:nonNegativeInteger"/>
1271
1272 <xsd:simpleType name="identifier">
1273 <xsd:restriction base="xsd:token">
1274 <xsd:pattern value="[A-Za-z_][A-Za-z0-9_]*"/>
1275 </xsd:restriction>
1276 </xsd:simpleType>
1277
1278 <xsd:element name="displayblock">
1279 <xsd:complexType>
1280 <xsd:sequence>
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"/>
1287
1288
1289
1290Freed & Vedam Standards Track [Page 23]
1291
1292RFC 5784 An XML Representation for Sieve March 2010
1293
1294
1295 <xsd:any namespace="##other" processContents="lax"/>
1296 </xsd:choice>
1297 </xsd:sequence>
1298 <xsd:anyAttribute processContents="skip"/>
1299 </xsd:complexType>
1300 </xsd:element>
1301
1302 <xsd:element name="displaydata">
1303 <xsd:complexType>
1304 <xsd:sequence minOccurs="0" maxOccurs="unbounded">
1305 <xsd:any processContents="skip"/>
1306 </xsd:sequence>
1307 </xsd:complexType>
1308 </xsd:element>
1309
1310 </xsd:schema>
1311
1312Appendix C. Relax NG Schema for Sieves in XML
1313
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.
1322
1323 namespace sieve = "urn:ietf:params:xml:ns:sieve"
1324
1325 start = element sieve:sieve { ( control | action | displayblock |
1326 displaydata | comment | ext )* }
1327
1328 comment = element sieve:comment { xsd:string }
1329
1330 ambles =
1331 (
1332 ( displaydata | comment | ext )*
1333 ),
1334 empty
1335
1336 preamble = element sieve:preamble { ambles }
1337 postamble = element sieve:postamble { ambles }
1338
1339 command =
1340 (
1341 attribute name {
1342 xsd:token {
1343
1344
1345
1346Freed & Vedam Standards Track [Page 24]
1347
1348RFC 5784 An XML Representation for Sieve March 2010
1349
1350
1351 pattern = "[A-Za-z_][A-Za-z0-9_]*" } },
1352 preamble?,
1353 ( str | num | \list | tag )*,
1354 test?,
1355 ( control | action | displayblock)*,
1356 postamble?
1357 ),
1358 empty
1359
1360 control = element sieve:control { command }
1361 action = element sieve:action { command }
1362
1363 test =
1364 element sieve:test
1365 {
1366 attribute name {
1367 xsd:token {
1368 pattern = "[A-Za-z_][A-Za-z0-9_]*" } },
1369 ( str | num | \list | tag | comment | ext )*,
1370 test*
1371 }
1372
1373 \list = element sieve:list { str+ }
1374
1375 tag = element sieve:tag {
1376 xsd:token {
1377 pattern = "[A-Za-z_][A-Za-z0-9_]*" } }
1378
1379 str = element sieve:str { xsd:string }
1380
1381 num = element sieve:num { xsd:nonNegativeInteger }
1382
1383 any = ( element * { any } | attribute * { text } | text )*
1384
1385 ext = element * - sieve:* { any }*
1386
1387 displayblock =
1388 element sieve:displayblock
1389 {
1390 ( control | action | displayblock |
1391 displaydata | comment | ext )*,
1392 attribute * { text }*
1393 }
1394
1395 displaydata = element sieve:displaydata { any* }
1396
1397
1398
1399
1400
1401
1402Freed & Vedam Standards Track [Page 25]
1403
1404RFC 5784 An XML Representation for Sieve March 2010
1405
1406
1407Appendix D. Stylesheet for Conversion from XML
1408
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.
1414
1415 <?xml version="1.0" encoding="UTF-8"?>
1416
1417 <!-- Convert Sieve in XML to standard Sieve syntax -->
1418
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">
1422
1423 <xsl:output method="text" encoding="UTF-8"
1424 media-type="application/sieve"/>
1425
1426 <!-- Only preserve whitespace in str elements -->
1427 <xsl:strip-space elements="*"/>
1428 <xsl:preserve-space elements="sieve:str"/>
1429
1430 <!-- Match top level sieve node,
1431 start processing in sieve mode -->
1432
1433 <xsl:template match="sieve:sieve">
1434 <xsl:apply-templates select="*" mode="sieve">
1435 <xsl:with-param name="prefix" select="''"/>
1436 </xsl:apply-templates>
1437 </xsl:template>
1438
1439 <!-- Routine to properly literalize quotes in Sieve strings -->
1440
1441 <xsl:template name="quote-string">
1442 <xsl:param name="str"/>
1443 <xsl:choose>
1444 <xsl:when test="not($str)"/>
1445 <xsl:when test="contains($str, '&quot;')">
1446 <xsl:call-template name="quote-string">
1447 <xsl:with-param name="str"
1448 select="substring-before($str, '&quot;')"/>
1449 </xsl:call-template>
1450 <xsl:text>\&quot;</xsl:text>
1451 <xsl:call-template name="quote-string">
1452 <xsl:with-param name="str"
1453 select="substring-after($str, '&quot;')"/>
1454 </xsl:call-template>
1455
1456
1457
1458Freed & Vedam Standards Track [Page 26]
1459
1460RFC 5784 An XML Representation for Sieve March 2010
1461
1462
1463 </xsl:when>
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>
1474 </xsl:when>
1475 <xsl:otherwise>
1476 <xsl:value-of select="$str"/>
1477 </xsl:otherwise>
1478 </xsl:choose>
1479 </xsl:template>
1480
1481 <!-- Sieve mode processing templates -->
1482
1483 <xsl:template match="sieve:control|sieve:action" mode="sieve">
1484 <xsl:param name="prefix"/>
1485 <xsl:text xml:space="preserve">
1486 </xsl:text>
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="*">
1492 <xsl:choose>
1493 <xsl:when test="self::sieve:str|self::sieve:num|
1494 self::sieve:list|self::sieve:tag|
1495 self::sieve:test">
1496 <xsl:apply-templates select="." mode="sieve"/>
1497 </xsl:when>
1498 <xsl:when test="generate-id(.) = $blockbegin">
1499 <xsl:text xml:space="preserve">
1500 </xsl:text>
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>
1507 </xsl:when>
1508 <xsl:otherwise>
1509 <xsl:apply-templates select="." mode="sieve">
1510 <xsl:with-param name="prefix"
1511
1512
1513
1514Freed & Vedam Standards Track [Page 27]
1515
1516RFC 5784 An XML Representation for Sieve March 2010
1517
1518
1519 select="concat($prefix, ' ')"/>
1520 </xsl:apply-templates>
1521 </xsl:otherwise>
1522 </xsl:choose>
1523 </xsl:for-each>
1524 <xsl:choose>
1525 <xsl:when test="count(sieve:control|sieve:action) &gt; 0">
1526 <xsl:text xml:space="preserve">
1527 </xsl:text>
1528 <xsl:value-of select="$prefix"/>
1529 <xsl:text>}</xsl:text>
1530 </xsl:when>
1531 <xsl:otherwise>
1532 <xsl:text>;</xsl:text>
1533 </xsl:otherwise>
1534 </xsl:choose>
1535 </xsl:template>
1536
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>
1542 </xsl:template>
1543
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)]"
1548 mode="sieve"/>
1549 <xsl:if test="count(descendant::sieve:test) &gt; 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) &gt; 0">
1554 <xsl:text>,</xsl:text>
1555 </xsl:if>
1556 </xsl:for-each>
1557 <xsl:text> )</xsl:text>
1558 </xsl:if>
1559 </xsl:template>
1560
1561 <xsl:template match="sieve:str" mode="sieve">
1562 <xsl:text> &quot;</xsl:text>
1563 <xsl:call-template name="quote-string">
1564 <xsl:with-param name="str" select="text()"/>
1565 </xsl:call-template>
1566 <xsl:text>&quot;</xsl:text>
1567
1568
1569
1570Freed & Vedam Standards Track [Page 28]
1571
1572RFC 5784 An XML Representation for Sieve March 2010
1573
1574
1575 </xsl:template>
1576
1577 <xsl:template match="sieve:num" mode="sieve">
1578 <xsl:text xml:space="preserve"> </xsl:text>
1579 <!-- Use numeric suffixes when possible -->
1580 <xsl:choose>
1581 <xsl:when test="(number(text()) mod 1073741824) = 0">
1582 <xsl:value-of select="number(text()) div 1073741824"/>
1583 <xsl:text>G</xsl:text>
1584 </xsl:when>
1585 <xsl:when test="(number(text()) mod 1048576) = 0">
1586 <xsl:value-of select="number(text()) div 1048576"/>
1587 <xsl:text>M</xsl:text>
1588 </xsl:when>
1589 <xsl:when test="(number(text()) mod 1024) = 0">
1590 <xsl:value-of select="number(text()) div 1024"/>
1591 <xsl:text>K</xsl:text>
1592 </xsl:when>
1593 <xsl:otherwise>
1594 <xsl:value-of select="text()"/>
1595 </xsl:otherwise>
1596 </xsl:choose>
1597 </xsl:template>
1598
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) &gt; 0">
1604 <xsl:text>,</xsl:text>
1605 </xsl:if>
1606 </xsl:for-each>
1607 <xsl:text> ]</xsl:text>
1608 </xsl:template>
1609
1610 <xsl:template match="sieve:tag" mode="sieve">
1611 <xsl:text> :</xsl:text>
1612 <xsl:value-of select="text()"/>
1613 </xsl:template>
1614
1615 <xsl:template match="sieve:comment" mode="sieve">
1616 <xsl:param name="prefix"/>
1617 <xsl:text xml:space="preserve">
1618 </xsl:text>
1619 <xsl:value-of select="$prefix"/>
1620 <xsl:text>/*</xsl:text>
1621 <xsl:value-of select="."/>
1622 <xsl:value-of select="$prefix"/>
1623
1624
1625
1626Freed & Vedam Standards Track [Page 29]
1627
1628RFC 5784 An XML Representation for Sieve March 2010
1629
1630
1631 <xsl:text>*/</xsl:text>
1632 </xsl:template>
1633
1634 <!-- Convert display information into structured comments -->
1635
1636 <xsl:template match="sieve:displayblock" mode="sieve">
1637 <xsl:param name="prefix"/>
1638 <xsl:text xml:space="preserve">
1639 </xsl:text>
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">
1648 </xsl:text>
1649 <xsl:value-of select="$prefix"/>
1650 <xsl:text>/* *] */</xsl:text>
1651 </xsl:template>
1652
1653 <xsl:template match="sieve:displaydata" mode="sieve">
1654 <xsl:param name="prefix"/>
1655 <xsl:text xml:space="preserve">
1656 </xsl:text>
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">
1664 </xsl:text>
1665 <xsl:value-of select="$prefix"/>
1666 <xsl:text> |] */</xsl:text>
1667 </xsl:template>
1668
1669 <!-- Copy unrecnognized nodes and their descendants -->
1670
1671 <xsl:template match="*" mode="sieve">
1672 <xsl:param name="prefix"/>
1673 <xsl:text xml:space="preserve">
1674 </xsl:text>
1675 <xsl:value-of select="$prefix"/>
1676 <xsl:text>/* [/</xsl:text>
1677 <xsl:apply-templates select="." mode="copy">
1678 <xsl:with-param name="prefix"
1679
1680
1681
1682Freed & Vedam Standards Track [Page 30]
1683
1684RFC 5784 An XML Representation for Sieve March 2010
1685
1686
1687 select="concat($prefix, ' ')"/>
1688 </xsl:apply-templates>
1689 <xsl:text xml:space="preserve">
1690 </xsl:text>
1691 <xsl:value-of select="$prefix"/>
1692 <xsl:text> /] */</xsl:text>
1693 </xsl:template>
1694
1695 <!-- Copy mode processing templates -->
1696
1697 <xsl:template match="*[not(node())]" mode="copy">
1698 <xsl:param name="prefix"/>
1699 <xsl:text xml:space="preserve">
1700 </xsl:text>
1701 <xsl:value-of select="$prefix"/>
1702 <xsl:text>&lt;</xsl:text>
1703 <xsl:value-of select="name()"/>
1704 <xsl:apply-templates select="@*" mode="copy"/>
1705 <xsl:text>/&gt;</xsl:text>
1706 </xsl:template>
1707
1708 <xsl:template match="*[node()]" mode="copy">
1709 <xsl:param name="prefix"/>
1710 <xsl:text xml:space="preserve">
1711 </xsl:text>
1712 <xsl:value-of select="$prefix"/>
1713 <xsl:text>&lt;</xsl:text>
1714 <xsl:value-of select="name()"/>
1715 <xsl:apply-templates select="@*" mode="copy"/>
1716 <xsl:text>&gt;</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">
1723 </xsl:text>
1724 <xsl:value-of select="$prefix"/>
1725 </xsl:if>
1726 <xsl:text>&lt;/</xsl:text>
1727 <xsl:value-of select="name()"/>
1728 <xsl:text>&gt;</xsl:text>
1729 </xsl:template>
1730
1731 <xsl:template match="@*" mode="copy">
1732 <xsl:text> </xsl:text>
1733 <xsl:value-of select="name()"/>
1734 <xsl:text>="</xsl:text>
1735
1736
1737
1738Freed & Vedam Standards Track [Page 31]
1739
1740RFC 5784 An XML Representation for Sieve March 2010
1741
1742
1743 <xsl:value-of select="."/>
1744 <xsl:text>"</xsl:text>
1745 </xsl:template>
1746
1747 </xsl:stylesheet>
1748
1749Appendix E. Acknowledgements
1750
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.
1755
1756Authors' Addresses
1757
1758 Ned Freed
1759 Sun Microsystems
1760 800 Royal Oaks
1761 Monrovia, CA 91016-6347
1762 USA
1763
1764 Phone: +1 909 457 4293
1765 EMail: ned.freed@mrochek.com
1766
1767
1768 Srinivas Saisatish Vedam
1769 Sun Microsystems
1770
1771 Phone: +91 80669 27577
1772 EMail: Srinivas.Sv@Sun.COM
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794Freed & Vedam Standards Track [Page 32]
1795
1796