Network Working Group K. T. Homme Document: draft-homme-sieve-variables-00.txt University of Oslo Expires September 21, 2003 21 Mar 2003 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 20 Mar 2003 . 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 a) "setdate" now has an optional timezone argument, and the default timezone is UTC. b) the first two revisions of this document went into a bitbucket at IETF. the numbering has to revert to -00 to accomodate their database. 0.3 Open Issues a) Should we include more predefined variables to access the time? (timezone, weekday, week number (US, EU and/or ISO?), name of month, name of weekday, ...) Could use strftime(3c) as a list of what to offer, but the names should be in English. b) This extension is particularily useful if fileinto is extended to create new folders on demand. Example: setdate "+0200" fileinto :makefolder "archive.${year}-${month}"; This will be proposed in a separate extension. c) Should the modifier syntax be prefix or postfix? ${var.lower} may be more natural than ${lower:var}, since the order of evaluation runs the same way as the syntax, rather than in the opposite direction. d) The modifiers for changing to upper or lower case are dependent on language, e.g. in Turkish the upper case of "i" is capital dotted I and the lower case of "I" is "i" without the dot. There is no way of specifying what locale to use in the modifiers toupper et al. A user can't rely on this being handled perfectly, anyway, so it may be acceptable to leave the choice of locale to the server administrator. 1. Introduction Homme [Page 2] Internet Draft Sieve -- Variables Extension 20 Mar 2003 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 semantics of quoted-string, multi-line- literal and multi-line-dotstuff found in [SIEVE] to enable the inclusion of the value of variables. The syntax follows [ABNF]. variable-ref = "${" *variable-modifier variable-name "}" variable-modifier = 1*ALPHA ":" variable-name = num-variable / user-variable num-variable = 1*DIGIT user-variable = ALPHA *(ALPHA / DIGIT / "_") When the string is evaluated, substrings matching variable-ref shall be replaced by the value of variable-name. Variable names are case insensitive. Unknown variables are replaced by the empty string. As per the grammar, illegal variable names leaves the would-be variable- ref verbatim, since it doesn't match the variable-ref syntax. Examples: "&%${}!" => unchanged, as the empty string is an illegal identifier "${doh!}" => unchanged, as "!" is illegal in identifiers The variable company holds the value "ACME". No other variables are set. "${full}" => the empty string "${company}" => "ACME" "${President, ${Company} Inc.}" => "${President, ACME Inc.}" 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 Quoting Homme [Page 3] Internet Draft Sieve -- Variables Extension 20 Mar 2003 The semantics of quoting using backslash are not changed. Backslash quoting is resolved before doing variable substitution. 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. If it is required to include a character sequence such as "${beep}" verbatim in a text literal, the user can define a variable to circumvent expansion to the empty string. Example: set dollar "$" set text "regarding ${dollar}{beep}" 3.2 Numeric variables Unless the extension "regex" is in use, all variables whose names are all digits 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 Homme [Page 4] Internet Draft Sieve -- Variables Extension 20 Mar 2003 you as soon as possible. . ; 3.3 Modifiers Modifiers change the expansion of the variable. More than one can be specified, in which case they are applied from right to left. Modifier names are case insensitive. Unknown modifiers MUST yield a syntax error. Examples: set string "juMBlEd lETteRS" "${length:string}" => "15" "${lower:string}" => "jumbled letters" "${upperfirst:string}" => "JuMBlEd lETteRS" "${upperfirst:lower:string}" => "Jumbled letters" 3.3.1 Modifier "length:" The expansion is replaced by the number of letters in the expansion. 3.3.2 Case modifiers These modifiers change the letters of the text from upper to lower case or vice versa. The implementation MUST support US-ASCII, but is not required to handle the entire Unicode repertoire. 3.3.2.1 Modifier "upper:" All lower case letters are converted to their upper case counterpart. 3.3.2.2 Modifier "lower:" All upper case letters are converted to their lower case counterpart. 3.3.2.3 Modifier "upperfirst:" The first character of the expansion is converted to upper case if it is a letter and set in lower case. The rest of the expansion is left unchanged. 3.3.2.4 Modifier "lowerfirst:" The first character of the expansion is converted to lower case if it is a letter and set in upper case. The rest of the expansion is left unchanged. Homme [Page 5] Internet Draft Sieve -- Variables Extension 20 Mar 2003 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. Variable names are case insensitive. Example: set honorific "Mr"; set first_name "Wile"; set last_name "Coyote"; set vacation text: Dear ${HONORIFIC} ${last_name}, I'm out, please leave a message after the beep. . ; "set" does not affect the implicit keep. 5. Action setdate Syntax: setdate [time-zone] time-zone = ( "+" / "-" ) 4DIGIT The action setdate initialises a few variables: ${year} => the current year, "0000" .. "9999" ${month} => the current month, "01" .. "12" ${day} => the current day, "01" .. "31" ${hour} => the current hour, "00" .. "23" ${minute} => the current hour, "00" .. "59" ${second} => the current second, "00" .. "59" These variables SHOULD reference the time when execution of the Sieve script reaches the statement. The default time zone is UTC. The time-zone should be interpreted the same way as "zone" in [IMAIL]. 6. Test string Syntax: string [MATCH-TYPE] [COMPARATOR] Homme [Page 6] Internet Draft Sieve -- Variables Extension 20 Mar 2003 The "string" test evaluates to true if any of the strings matches any key. The type of match defaults to ":is". 7. 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. 8. Acknowledgments Thanks to Jutta Degener, Peder Stray and Nigel Swinson for valuable feedback. 8. Author's Address Kjetil T. Homme Frydens g 5B 0564 Oslo, Norway Phone: +47 9366 0091 E-mail: kjetilho@ifi.uio.no Appendix A. References [ABNF] D. Crocker, Ed., "Augmented BNF for Syntax Specifications: ABNF", Internet Mail Consortium, RFC 2234, November 1997 [IMAIL] P. Resnick, Ed., "Internet Message Format", QUALCOMM Incorporated, April 2001. [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 Homme [Page 7] Internet Draft Sieve -- Variables Extension 20 Mar 2003 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 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 8]