7Network Working Group N. Freed
8Request for Comments: 5260 Sun Microsystems
9Category: Standards Track July 2008
12 Sieve Email Filtering: Date and Index Extensions
16 This document specifies an Internet standards track protocol for the
17 Internet community, and requests discussion and suggestions for
18 improvements. Please refer to the current edition of the "Internet
19 Official Protocol Standards" (STD 1) for the standardization state
20 and status of this protocol. Distribution of this memo is unlimited.
24 This document describes the "date" and "index" extensions to the
25 Sieve email filtering language. The "date" extension gives Sieve the
26 ability to test date and time values in various ways. The "index"
27 extension provides a means to limit header and address tests to
28 specific instances of header fields when header fields are repeated.
32 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 2
33 2. Conventions Used in This Document . . . . . . . . . . . . . . 2
34 3. Capability Identifiers . . . . . . . . . . . . . . . . . . . . 3
35 4. Date Test . . . . . . . . . . . . . . . . . . . . . . . . . . 3
36 4.1. Zone and Originalzone Arguments . . . . . . . . . . . . . 4
37 4.2. Date-part Argument . . . . . . . . . . . . . . . . . . . . 4
38 4.3. Comparator Interactions with Date-part Arguments . . . . . 5
39 4.4. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 6
40 5. Currentdate Test . . . . . . . . . . . . . . . . . . . . . . . 6
41 5.1. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 6
42 6. Index Extension . . . . . . . . . . . . . . . . . . . . . . . 7
43 6.1. Example . . . . . . . . . . . . . . . . . . . . . . . . . 8
44 7. Security Considerations . . . . . . . . . . . . . . . . . . . 8
45 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9
46 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 9
47 9.1. Normative References . . . . . . . . . . . . . . . . . . . 9
48 9.2. Informative References . . . . . . . . . . . . . . . . . . 10
49 Appendix A. Julian Date Conversions . . . . . . . . . . . . . . . 11
50 Appendix B. Acknowledgements . . . . . . . . . . . . . . . . . . 12
58Freed Standards Track [Page 1]
60RFC 5260 Sieve Date and Index Extensions July 2008
65 Sieve [RFC5228] is a language for filtering email messages at or
66 around the time of final delivery. It is designed to be
67 implementable on either a mail client or mail server. It is meant to
68 be extensible, simple, and independent of access protocol, mail
69 architecture, and operating system. It is suitable for running on a
70 mail server where users may not be allowed to execute arbitrary
71 programs, such as on black box Internet Message Access Protocol
72 [RFC3501] servers, as it does not have user-controlled loops or the
73 ability to run external programs.
75 The "date" extension provides a new date test to extract and match
76 date/time information from structured header fields. The date test
77 is similar in concept to the address test specified in [RFC5228],
78 which performs similar operations on addresses in header fields.
80 The "date" extension also provides a currentdate test that operates
81 on the date and time when the Sieve script is executed.
83 Some header fields containing date/time information, e.g., Received:,
84 naturally occur more than once in a single header. In such cases it
85 is useful to be able to restrict the date test to some subset of the
86 fields that are present. For example, it may be useful to apply a
87 date test to the last (earliest) Received: field. Additionally, it
88 may also be useful to apply similar restrictions to either the header
89 or address tests specified in [RFC5228].
91 For this reason, this specification also defines an "index"
92 extension. This extension adds two additional tagged arguments
93 :index and :last to the header, address, and date tests. If present,
94 these arguments specify which occurrence of the named header field is
972. Conventions Used in This Document
99 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
100 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
101 document are to be interpreted as described in RFC 2119 [RFC2119].
103 The terms used to describe the various components of the Sieve
104 language are taken from Section 1.1 of [RFC5228]. Section 2 of the
105 same document describes basic Sieve language syntax and semantics.
106 The date-time syntactic element defined using ABNF notation [RFC5234]
107 in [RFC3339] is also used here.
114Freed Standards Track [Page 2]
116RFC 5260 Sieve Date and Index Extensions July 2008
1193. Capability Identifiers
121 The capability strings associated with the two extensions defined in
122 this document are "date" and "index".
126 Usage: date [<":zone" <time-zone: string>> / ":originalzone"]
127 [COMPARATOR] [MATCH-TYPE] <header-name: string>
128 <date-part: string> <key-list: string-list>
130 The date test matches date/time information derived from headers
131 containing [RFC2822] date-time values. The date/time information is
132 extracted from the header, shifted to the specified time zone, and
133 the value of the given date-part is determined. The test returns
134 true if the resulting string matches any of the strings specified in
135 the key-list, as controlled by the comparator and match keywords.
136 The date test returns false unconditionally if the specified header
137 field does not exist, the field exists but does not contain a
138 syntactically valid date-time specification, the date-time isn't
139 valid according to the rules of the calendar system (e.g., January
140 32nd, February 29 in a non-leap year), or the resulting string fails
141 to match any key-list value.
143 The type of match defaults to ":is" and the default comparator is
146 Unlike the header and address tests, the date test can only be
147 applied to a single header field at a time. If multiple header
148 fields with the same name are present, only the first field that is
149 found is used. (Note, however, that this behavior can be modified
150 with the "index" extension defined below.) These restrictions
151 simplify the test and keep the meaning clear.
153 The "relational" extension [RFC5231] adds a match type called
154 ":count". The count of a date test is 1 if the specified field
155 exists and contains a valid date; 0, otherwise.
157 Implementations MUST support extraction of RFC 2822 date-time
158 information that either makes up the entire header field (e.g., as it
159 does in a standard Date: header field) or appears at the end of a
160 header field following a semicolon (e.g., as it does in a standard
161 Received: header field). Implementations MAY support extraction of
162 date and time information in RFC2822 or other formats that appears in
163 other positions in header field content. In the case of a field
164 containing more than one date or time value, the last one that
165 appears SHOULD be used.
170Freed Standards Track [Page 3]
172RFC 5260 Sieve Date and Index Extensions July 2008
1754.1. Zone and Originalzone Arguments
177 The :originalzone argument specifies that the time zone offset
178 originally in the extracted date-time value should be retained. The
179 :zone argument specifies a specific time zone offset that the date-
180 time value is to be shifted to prior to testing. It is an error to
181 specify both :zone and :originalzone.
183 The value of time-zone MUST be an offset relative to UTC with the
186 time-zone = ( "+" / "-" ) 4DIGIT
188 The "+" or "-" indicates whether the time-of-day is ahead of (i.e.,
189 east of) or behind (i.e., west of) UTC. The first two digits
190 indicate the number of hours difference from Universal Time, and the
191 last two digits indicate the number of minutes difference from
192 Universal Time. Note that this agrees with the RFC 2822 format for
193 time zone offsets, not the ISO 8601 format.
195 If both the :zone and :originalzone arguments are omitted, the local
196 time zone MUST be used.
1984.2. Date-part Argument
200 The date-part argument specifies a particular part of the resulting
201 date/time value to match against the key-list. Possible case-
202 insensitive values are:
204 "year" => the year, "0000" .. "9999".
205 "month" => the month, "01" .. "12".
206 "day" => the day, "01" .. "31".
207 "date" => the date in "yyyy-mm-dd" format.
208 "julian" => the Modified Julian Day, that is, the date
209 expressed as an integer number of days since
210 00:00 UTC on November 17, 1858 (using the Gregorian
211 calendar). This corresponds to the regular
212 Julian Day minus 2400000.5. Sample routines to
213 convert to and from modified Julian dates are
215 "hour" => the hour, "00" .. "23".
216 "minute" => the minute, "00" .. "59".
217 "second" => the second, "00" .. "60".
218 "time" => the time in "hh:mm:ss" format.
219 "iso8601" => the date and time in restricted ISO 8601 format.
220 "std11" => the date and time in a format appropriate
221 for use in a Date: header field [RFC2822].
226Freed Standards Track [Page 4]
228RFC 5260 Sieve Date and Index Extensions July 2008
231 "zone" => the time zone in use. If the user specified a
232 time zone with ":zone", "zone" will
233 contain that value. If :originalzone is specified
234 this value will be the original zone specified
235 in the date-time value. If neither argument is
236 specified the value will be the server's default
237 time zone in offset format "+hhmm" or "-hhmm". An
238 offset of 0 (Zulu) always has a positive sign.
239 "weekday" => the day of the week expressed as an integer between
240 "0" and "6". "0" is Sunday, "1" is Monday, etc.
242 The restricted ISO 8601 format is specified by the date-time ABNF
243 production given in [RFC3339], Section 5.6, with the added
244 restrictions that the letters "T" and "Z" MUST be in upper case, and
245 a time zone offset of zero MUST be represented by "Z" and not
2484.3. Comparator Interactions with Date-part Arguments
250 Not all comparators are suitable with all date-part arguments. In
251 general, the date-parts can be compared and tested for equality with
252 either "i;ascii-casemap" (the default) or "i;octet", but there are
255 julian This is an integer, and may or may not have leading zeros.
256 As such, "i;ascii-numeric" is almost certainly the best
257 comparator to use with it.
259 std11 This is provided as a means to obtain date/time values in a
260 format appropriate for inclusion in email header fields. The
261 wide range of possible syntaxes for a std11 date/time --
262 which implementations of this extension are free to use when
263 composing a std11 string -- makes this format a poor choice
264 for comparisons. Nevertheless, if a comparison must be
265 performed, this is case-insensitive, and therefore "i;ascii-
266 casemap" needs to be used.
268 "year", "month", "day", "hour", "minute", "second" and "weekday" all
269 use fixed-width string representations of integers, and can therefore
270 be compared with "i;octet", "i;ascii-casemap", and "i;ascii-numeric"
271 with equivalent results.
273 "date" and "time" also use fixed-width string representations of
274 integers, and can therefore be compared with "i;octet" and "i;ascii-
275 casemap"; however, "i;ascii-numeric" can't be used with it, as
276 "i;ascii-numeric" doesn't allow for non-digit characters.
282Freed Standards Track [Page 5]
284RFC 5260 Sieve Date and Index Extensions July 2008
289 The Date: field can be checked to test when the sender claims to have
290 created the message and act accordingly:
292 require ["date", "relational", "fileinto"];
293 if allof(header :is "from" "boss@example.com",
294 date :value "ge" :originalzone "date" "hour" "09",
295 date :value "lt" :originalzone "date" "hour" "17")
296 { fileinto "urgent"; }
298 Testing the initial Received: field can provide an indication of when
299 a message was actually received by the local system:
301 require ["date", "relational", "fileinto"];
302 if anyof(date :is "received" "weekday" "0",
303 date :is "received" "weekday" "6")
304 { fileinto "weekend"; }
308 Usage: currentdate [":zone" <time-zone: string>]
309 [COMPARATOR] [MATCH-TYPE]
311 <key-list: string-list>
313 The currentdate test is similar to the date test, except that it
314 operates on the current date/time rather than a value extracted from
315 the message header. In particular, the ":zone" and date-part
316 arguments are the same as those in the date test.
318 All currentdate tests in a single Sieve script MUST refer to the same
319 point in time during execution of the script.
321 The :count value of a currentdate test is always 1.
325 The simplest use of currentdate is to have an action that only
326 operates at certain times. For example, a user might want to have
327 messages redirected to their pager after business hours and on
338Freed Standards Track [Page 6]
340RFC 5260 Sieve Date and Index Extensions July 2008
343 require ["date", "relational"];
344 if anyof(currentdate :is "weekday" "0",
345 currentdate :is "weekday" "6",
346 currentdate :value "lt" "hour" "09",
347 currentdate :value "ge" "hour" "17")
348 { redirect "pager@example.com"; }
350 Currentdate can be used to set up vacation [RFC5230] responses in
351 advance and to stop response generation automatically:
353 require ["date", "relational", "vacation"];
354 if allof(currentdate :value "ge" "date" "2007-06-30",
355 currentdate :value "le" "date" "2007-07-07")
356 { vacation :days 7 "I'm away during the first week in July."; }
358 Currentdate may also be used in conjunction with the variables
359 extension to pass time-dependent arguments to other tests and
360 actions. The following Sieve places messages in a folder named
361 according to the current month and year:
363 require ["date", "variables", "fileinto"];
364 if currentdate :matches "month" "*" { set "month" "${1}"; }
365 if currentdate :matches "year" "*" { set "year" "${1}"; }
366 fileinto "${month}-${year}";
368 Finally, currentdate can be used in conjunction with the editheader
369 extension to insert a header-field containing date/time information:
371 require ["variables", "date", "editheader"];
372 if currentdate :matches "std11" "*"
373 {addheader "Processing-date" "${0}";}
377 The "index" extension, if specified, adds optional :index and :last
378 arguments to the header, address, and date tests as follows:
380 Syntax: date [":index" <fieldno: number> [":last"]]
381 [<":zone" <time-zone: string>> / ":originalzone"]
382 [COMPARATOR] [MATCH-TYPE] <header-name: string>
383 <date-part: string> <key-list: string-list>
386 Syntax: header [":index" <fieldno: number> [":last"]]
387 [COMPARATOR] [MATCH-TYPE]
388 <header-names: string-list> <key-list: string-list>
394Freed Standards Track [Page 7]
396RFC 5260 Sieve Date and Index Extensions July 2008
399 Syntax: address [":index" <fieldno: number> [":last"]]
400 [ADDRESS-PART] [COMPARATOR] [MATCH-TYPE]
401 <header-list: string-list> <key-list: string-list>
403 If :index <fieldno> is specified, the attempts to match a value are
404 limited to the header field fieldno (beginning at 1, the first named
405 header field). If :last is also specified, the count is backwards; 1
406 denotes the last named header field, 2 the second to last, and so on.
407 Specifying :last without :index is an error.
409 :index only counts separate header fields, not multiple occurrences
410 within a single field. In particular, :index cannot be used to test
411 a specific address in an address list contained within a single
414 Both header and address allow the specification of more than one
415 header field name. If more than one header field name is specified,
416 all the named header fields are counted in the order specified by the
421 Mail delivery may involve multiple hops, resulting in the Received:
422 field containing information about when a message first entered the
423 local administrative domain being the second or subsequent field in
424 the message. As long as the field offset is consistent, it can be
427 # Implement the Internet-Draft cutoff date check assuming the
428 # second Received: field specifies when the message first
429 # entered the local email infrastructure.
430 require ["date", "relational", "index"];
431 if date :value "gt" :index 2 :zone "-0500" "received"
432 "iso8601" "2007-02-26T09:00:00-05:00",
433 { redirect "aftercutoff@example.org"; }
4357. Security Considerations
437 The facilities defined here, like the facilities in the base Sieve
438 specification, operate on message header information that can easily
439 be forged. Note, however, that some fields are inherently more
440 reliable than others. For example, the Date: field is typically
441 inserted by the message sender and can be altered at any point. By
442 contrast, the uppermost Received: field is typically inserted by the
443 local mail system and is therefore difficult for the sender or an
444 intermediary to falsify.
450Freed Standards Track [Page 8]
452RFC 5260 Sieve Date and Index Extensions July 2008
455 Use of the currentdate test makes script behavior inherently less
456 predictable and harder to analyze. This may have consequences for
457 systems that use script analysis to try and spot problematic scripts.
459 All of the security considerations given in the base Sieve
460 specification also apply to these extensions.
4628. IANA Considerations
464 The following templates specify the IANA registrations of the two
465 Sieve extensions specified in this document:
468 Subject: Registration of new Sieve extensions
470 Capability name: date
471 Description: The "date" extension gives Sieve the ability
472 to test date and time values.
474 Contact address: Sieve discussion list <ietf-mta-filters@imc.org>
476 Capability name: index
477 Description: The "index" extension provides a means to
478 limit header and address tests to specific
479 instances when more than one field of a
480 given type is present.
482 Contact address: Sieve discussion list <ietf-mta-filters@imc.org>
4869.1. Normative References
488 [CALGO199] Tantzen, R., "Algorithm 199: Conversions Between Calendar
489 Date and Julian Day Number", Collected Algorithms from
492 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
493 Requirement Levels", BCP 14, RFC 2119, March 1997.
495 [RFC2822] Resnick, P., "Internet Message Format", RFC 2822,
498 [RFC3339] Klyne, G., Ed. and C. Newman, "Date and Time on the
499 Internet: Timestamps", RFC 3339, July 2002.
501 [RFC5228] Guenther, P. and T. Showalter, "Sieve: An Email Filtering
502 Language", RFC 5228, January 2008.
506Freed Standards Track [Page 9]
508RFC 5260 Sieve Date and Index Extensions July 2008
511 [RFC5231] Segmuller, W. and B. Leiba, "Sieve Email Filtering:
512 Relational Extension", RFC 5231, January 2008.
514 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax
515 Specifications: ABNF", STD 68, RFC 5234, January 2008.
5179.2. Informative References
519 [RFC3501] Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION
520 4rev1", RFC 3501, March 2003.
522 [RFC5230] Showalter, T. and N. Freed, "Sieve Email Filtering:
523 Vacation Extension", RFC 5230, January 2008.
562Freed Standards Track [Page 10]
564RFC 5260 Sieve Date and Index Extensions July 2008
567Appendix A. Julian Date Conversions
569 The following C routines show how to translate day/month/year
570 information to and from modified Julian dates. These routines are
571 straightforward translations of the Algol routines specified in CACM
572 Algorithm 199 [CALGO199].
574 Given the day, month, and year, jday returns the modified Julian
577 int jday(int year, int month, int day)
590 return (c * 146097 / 4 + ya * 1461 / 4 + (month * 153 + 2) / 5 +
618Freed Standards Track [Page 11]
620RFC 5260 Sieve Date and Index Extensions July 2008
623 Given j, the modified Julian date, jdate returns the day, month, and
626 void jdate(int j, int *year, int *month, int *day)
631 y = (j * 4 - 1) / 146097;
632 j = j * 4 - y * 146097 - 1;
634 j = (d * 4 + 3) / 1461;
635 d = d * 4 - j * 1461 + 3;
637 m = (d * 5 - 3) / 153;
638 d = d * 5 - m * 153 - 3;
650Appendix B. Acknowledgements
652 Dave Cridland contributed the text describing the proper comparators
653 to use with different date-parts. Cyrus Daboo, Frank Ellerman,
654 Alexey Melnikov, Chris Newman, Dilyan Palauzov, and Aaron Stone
655 provided helpful suggestions and corrections.
662 Monrovia, CA 91016-6347
665 Phone: +1 909 457 4293
666 EMail: ned.freed@mrochek.com
674Freed Standards Track [Page 12]
676RFC 5260 Sieve Date and Index Extensions July 2008
679Full Copyright Statement
681 Copyright (C) The IETF Trust (2008).
683 This document is subject to the rights, licenses and restrictions
684 contained in BCP 78, and except as set forth therein, the authors
685 retain all their rights.
687 This document and the information contained herein are provided on an
688 "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
689 OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND
690 THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS
691 OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF
692 THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
693 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
697 The IETF takes no position regarding the validity or scope of any
698 Intellectual Property Rights or other rights that might be claimed to
699 pertain to the implementation or use of the technology described in
700 this document or the extent to which any license under such rights
701 might or might not be available; nor does it represent that it has
702 made any independent effort to identify any such rights. Information
703 on the procedures with respect to rights in RFC documents can be
704 found in BCP 78 and BCP 79.
706 Copies of IPR disclosures made to the IETF Secretariat and any
707 assurances of licenses to be made available, or the result of an
708 attempt made to obtain a general license or permission for the use of
709 such proprietary rights by implementers or users of this
710 specification can be obtained from the IETF on-line IPR repository at
711 http://www.ietf.org/ipr.
713 The IETF invites any interested party to bring to its attention any
714 copyrights, patents or patent applications, or other proprietary
715 rights that may cover technology that may be required to implement
716 this standard. Please address the information to the IETF at
730Freed Standards Track [Page 13]