Network Working Group K. T. Homme Document: draft-homme-sieve-variables-00.txt University of Oslo Expires June 21, 2003 21 Dec 2002 Sieve -- Variables Extension Status of this Memo This document is an Internet-Draft and is subject to all provisions of Section 10 of RFC2026. Internet-Drafts are working documents of the Internet Engineering Task Force (IETF), its areas, and its working groups. Note that other groups may also distribute working documents as Internet- Drafts. Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." The list of current Internet-Drafts can be accessed at http://www.ietf.org/ietf/1id-abstracts.txt To view the list Internet-Draft Shadow Directories, see http://www.ietf.org/shadow.html. Distribution of this memo is unlimited. Abstract In advanced filtering rule sets, it is useful to keep state or configuration details across rules. This extension adds an action to store data in variables, changes the interpolation of double quoted strings, and supplies a new test so that the value of a string can be examined. 0 Meta-information on this draft This information is intended to facilitate discussion. It will be removed when this document leaves the Internet-Draft stage. 0.1 Discussion This draft is intended to be an extension to the Sieve mail filtering language, available from the RFC repository as Homme [Page 1] Internet Draft Sieve -- Variables Extension 21 Dec 2002 . This draft and the Sieve language itself are being discussed on the MTA Filters mailing list at . Subscription requests can be sent to (send an email message with the word "subscribe" in the body). More information on the mailing list along with a WWW archive of back messages is available at . 0.2 Noted Changes 0.3 Open Issues a) Does it make sense to reserve all upper case variable names for the future? Sieve extension are perhaps static and unchanging by nature. b) Should we include more predefined variables to access the time? (hour, minutes, timezone, weekday, week number (US, EU og ISO?), name of month, name of weekday, ...) Could use ${Time_X} => %X as per strftime(3c). c) This extension is particularily useful if fileinto is extended to create new folders on demand. Example: fileinto :makefolder "archive.${Year}-${Month}"; It is not clear if this feature should be included here or left for a separate extension. 1. Introduction This is an extension to the Sieve language defined by [SIEVE]. It adds support for storing and referencing data in string variables. Conventions for notations are as in [SIEVE] section 1.1, including use of [KEYWORDS]. 2. Capability Identifier The capability string associated with the extension defined in this document is "variables". 3. Interpretation of strings This extension changes the syntax of quoted-string, multi-line- literal and multi-line-dotstuff found in [SIEVE] to enable the Homme [Page 2] Internet Draft Sieve -- Variables Extension 21 Dec 2002 inclusion of the value of variables. The syntax follows [ABNF]. quoted-string = DQUOTE *(CHAR / variable-ref) DQUOTE multi-line-literal = [ (variable-ref / CHAR-NOT-DOT) *(variable-ref / CHAR-NOT-CRLF) ] CRLF multi-line-dotstuff = "." 1*(variable-ref / CHAR-NOT-CRLF) CRLF variable-ref = "${" variable-name "}" variable-name = reserved-variable / user-variable reserved-variable = num-variable / uc-variable num-variable = 1*DIGIT uc-variable = UPPER *(ALPHA / DIGIT / "_") user-variable = LOWER *(ALPHA / DIGIT / "_") LOWER = %x61-7A ; a-z UPPER = %x41-5A ; A-Z When the string is evaluated, variable-ref shall be replaced by the value of variable-name. Unknown variables are replaced by the empty string. As per the grammar, illegal variable names leaves the would-be variable-ref verbatim, since it is interpreted as a 1*CHAR instead. Examples: "&%${}!" => unchanged, as the empty string is an illegal identifier. "${doh!}" => unchanged, as "!" is illegal in identifiers. "${Argggh}" => the empty string, since "Argggh" is an unknown reserved variable. Strings SHOULD be evaluated every time control reaches the statement it is a part of, to make sure the expanded variable values are up- to-date. 3.1 Interaction with quoting The semantics of quoting using backslash are not changed. Examples: "${fo\o}" => ${foo} => the expansion of variable foo. "${fo\\o}" => ${fo\o} => illegal identifier => left verbatim. "\${foo}" => ${foo} => the expansion of variable foo. "\\${foo}" => \${foo} => a backslash character followed by the expansion of variable foo. 3.2 Reserved variables 3.2.1 Numeric variables Homme [Page 3] Internet Draft Sieve -- Variables Extension 21 Dec 2002 Unless the extension "regex" is in use, all numeric variable name MUST evaluate to the empty string. The decimal value of the numeric variable name will index the list of matching strings from the each of the group operators in the latest regular expression match. The first pair of grouping parentheses has index 1. If the index is out of range, the empty string will be substituted. Index 0 returns the number of matching groups. Example: require [ "fileinto", "regex", "variables", "vacation" ]; if header :regex "List-ID" "<(.*)@" { fileinto "lists.${1}"; stop; } if header :regex "From" "^ set greeting "Dear ${1},"; } if header :regex "Subject" "(.*)" { set subject " on ${1}"; } vacation text: ${greeting} Thank you for your mail${subject}. I'm away from office for a few days, but I will get back to you as soon as possible. . ; 3.2.2 Dollar The value of ${Dollar} is always "$". This means the literal value of "$" can be escaped by entering it as "${Dollar}". Example: "make ${Dollar}${Dollar}${Dollar} fast" => "make $$$ fast" Note: it is not required to escape "$$$". 3.2.3 Miscellaneous A few variables give access to the time: ${Year} => the current year, "0000" .. "9999" ${Month} => the current month, "01" .. "12" Homme [Page 4] Internet Draft Sieve -- Variables Extension 21 Dec 2002 ${Day} => the current day, "01" .. "31" These variables SHOULD reference the time when execution of the Sieve script started to ensure consistent results even when run at midnight. The local timezone SHOULD be used. Other variable names starting with an uppercase letter or underscore are reserved for future extensions. 4. Action set Syntax: set The "set" action stores the specified value in the variable. Assignment to a reserved variable name or an illegal identifier MUST cause a syntax error. All variables have global scope. Example: set honorific "Mr"; set first_name "Wile"; set last_name "Coyote"; set vacation text: I'm out, please leave a message after the meep. . ; "set" does not affect the implicit keep. 5. Test string Syntax: string [MATCH-TYPE] [COMPARATOR] The "string" test evaluates to true if any of the strings matches any key. The type of match defaults to ":is". 6. Security Considerations When combined with the regex extension, strings can contain arbitrary values controlled by the sender of the e-mail if the author of the script isn't careful. The introduction of variables makes advanced decision making easier to write, but since no looping construct is provided, all Sieve scripts will terminate orderly. Homme [Page 5] Internet Draft Sieve -- Variables Extension 21 Dec 2002 7. Acknowledgments Thanks to Peder Stray for inspiration. 8. Author's Address Kjetil T. Homme Frydens g 5B 0564 Oslo, Norway Phone: +47 9366 0091 E-mail: kjetilho(_at_)ifi(_dot_)uio(_dot_)no Appendix A. References [ABNF] D. Crocker, Ed., "Augmented BNF for Syntax Specifications: ABNF", Internet Mail Consortium, RFC 2234, November 1997 [KEYWORDS] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", Harvard University, RFC 2119, March 1997. [SIEVE] Showalter, T., "Sieve: A Mail Filtering Language", Mirapoint, RFC 3028, January 2001. Appendix B. Full Copyright Statement Copyright (C) The Internet Society 2002. All Rights Reserved. This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this paragraph are included on all such copies and derivative works. However, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations, except as needed for the purpose of develop- ing Internet standards in which case the procedures for copyrights defined in the Internet Standards process must be followed, or as required to translate it into languages other than English. The limited permissions granted above are perpetual and will not be revoked by the Internet Society or its successors or assigns. This document and the information contained herein is provided on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING Homme [Page 6] Internet Draft Sieve -- Variables Extension 21 Dec 2002 BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Homme [Page 7]