RFC 5229
Sieve Email Filtering: Variables Extension
RFC 5229: Sieve Email Filtering: Variables Extension โจ
Network Working Group, Request for Comments: 5229 ๐
Okay bestie, let's get the paperwork out of the way first ๐ . This one was written by K. Homme from the University of Oslo and dated January 2008. It's a Standards Track document, so it's an actual protocol spec and not just a fun idea. It updates RFC 5228, which is the base Sieve filtering language, and the header doesn't list anything it obsoletes. ๐ฆ
Status of This Memo ๐ธ
This document specifies an Internet standards track protocol for the Internet community, and it's asking for discussion and suggestions for improvements ๐ซถ. For the official standardization state and status of this protocol, check the current edition of the "Internet Official Protocol Standards" (STD 1). Distribution of this memo is unlimited, so share it with everyone ๐.
Abstract โจ
Okay so in fancy mail filtering rule sets, it's super useful to hold on to state or config details across rules ๐ง . This document updates the Sieve filtering language (RFC 5228) with an extension that adds variables ๐. The extension changes how strings are interpreted, adds an action that stores data in variables, and adds a new test so you can examine the value of a string ๐ฅ.
1. Introduction ๐
This is an extension to the Sieve language that's defined by [SIEVE] ๐. It adds support for storing and referencing named data. The mechanisms in this document only apply to Sieve scripts that include a require clause for the "variables" extension, and the require clauses themselves aren't affected by any of this ๐.
For notation, we follow the conventions in [SIEVE] section 1.1, including the use of [KEYWORDS] and [ABNF]. The grammar builds on the grammar of [SIEVE] โจ. In this document, "character" means a character from the ISO 10646 coded character set [ISO10646], which might be made up of multiple octets coded in [UTF-8]. And "variable" is just a named reference to data that gets stored or read back using this extension ๐ฆ.
2. Capability Identifier ๐
The capability string for this extension is "variables" ๐
.
3. Interpretation of Strings ๐ฅ
This extension changes the semantics of quoted-string, multi-line-literal and multi-line-dotstuff from [SIEVE] so that the value of variables can be included in them ๐ง.
When a string gets evaluated, any substrings that match variable-ref get replaced by the value of variable-name ๐. Only one pass through the string is done, so no double-dipping ๐
. Variable names are case insensitive, which means "foo" and "FOO" refer to the same variable ๐ธ. Unknown variables get replaced by the empty string ๐.
variable-ref = "${" [namespace] variable-name "}"
namespace = identifier "." *sub-namespace
sub-namespace = variable-name "."
variable-name = num-variable / identifier
num-variable = 1*DIGIT
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"
"${BAD${Company}" => "${BADACME"
"${President, ${Company} Inc.}"
=> "${President, ACME Inc.}"
The expanded string is required to use the variable values that are current when control reaches the statement the string is part of ๐ฏ. Basically, the timing matters, bestie โฐ.
Strings where no variable substitutions happen are called constant strings ๐. Future extensions may specify that passing non-constant strings as arguments to its actions or tests is an error ๐.
Namespaces are for future extensions that make internal state available through variables ๐งโโ๏ธ. Those variables SHOULD be put in a namespace whose first component is the same as its capability string ๐. Such extensions SHOULD also state which, if any, of the variables in their namespace are modifiable with the "set" action ๐ซถ.
References to namespaces without a prior require statement for the relevant extension MUST cause an error ๐ซ. Not me trying to use a namespace I never required ๐.
Tests or actions in future extensions may need to access the unexpanded version of the string argument, and they might do the expansion after setting variables in their namespace. The design of the implementation should allow this โจ.
3.1. Quoting and Encoded Characters ๐
The semantics of quoting with backslash are not changed. Backslash quoting gets resolved before variable substitution happens ๐ฅ. Similarly, encoded character processing (see Section 2.4.2.4 of [SIEVE]) is performed before variable substitution, but after quoting ๐ .
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 you need to include a character sequence such as "${beep}" verbatim in a text literal, you can define a variable to dodge the expansion to the empty string ๐. Lowkey genius.
Example:
set "dollar" "$";
set "text" "regarding ${dollar}{beep}";
Example:
require ["encoded-character", "variables"];
set "name" "Ethelbert"
if header :contains "Subject" "dear${hex:20 24 7b 4e}ame}" {
# the test string is "dear Ethelbert"
}
3.2. Match Variables ๐ฆ
A "match variable" has a name made up only of decimal digits, and it has no namespace component ๐ข.
The decimal value of the match variable name indexes the list of matching strings from the most recently evaluated successful match of type ":matches" ๐. The list is empty if no match has been successful yet ๐ธ.
Note: Extra leading zeroes are allowed and ignored. ๐ง
The list has one string for each wildcard ("?" and "*") in the match pattern ๐. Each string holds the substring from the source value that the matching wildcard expands to, and that substring might be the empty string ๐ซง. The wildcards match as little as possible, which is called non-greedy matching ๐ค.
The first string in the list has index 1 โ๏ธ. If the index is out of range, the empty string gets substituted. Index 0 contains the matched part of the source value ๐.
The interpreter MUST short-circuit tests, which means it must not run more tests than it needs to find the result โก. Evaluation order MUST be left to right โก๏ธ. If a test has two or more list arguments, the implementation is free to choose which one to iterate over first ๐ฒ.
An extension describing a new match type (for example, [REGEX]) MAY specify that match variables are set as a side effect when that match type is used in a script that has enabled the "variables" extension ๐.
Example:
require ["fileinto", "variables"];
if header :matches "List-ID" "*<*@*" {
fileinto "INBOX.lists.${2}"; stop;
}
# Imagine the header
# Subject: [acme-users] [fwd] version 1.0 is out
if header :matches "Subject" "[*] *" {
# ${1} will hold "acme-users",
# ${2} will hold "[fwd] version 1.0 is out"
fileinfo "INBOX.lists.${1}"; stop;
}
# Imagine the header
# To: coyote@ACME.Example.COM
if address :matches ["To", "Cc"] ["coyote@**.com",
"wile@**.com"] {
# ${0} is the matching address
# ${1} is always the empty string
# ${2} is part of the domain name ("ACME.Example")
fileinto "INBOX.business.${2}"; stop;
} else {
# Control wouldn't reach this block if any match was
# successful, so no match variables are set at this
# point.
}
if anyof (true, address :domain :matches "To" "*.com") {
# The second test is never evaluated, so there are
# still no match variables set.
stop;
}
4. Action set ๐
Usage:
set [MODIFIER] <name: string> <value: string>
The "set" action stores the specified value in the variable identified by name ๐. The name MUST be a constant string and conform to the syntax of variable-name ๐ฏ. Match variables cannot be set ๐ซ. A namespace cannot be used unless an extension explicitly allows its use in "set" ๐ง. An invalid name MUST be detected as a syntax error ๐.
Modifiers are applied to a value before it gets stored in the variable. See the next section for details ๐ธ.
Variables are only visible to the currently running script ๐. Future extensions may provide different scoping rules for variables ๐ฎ.
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 meep.
.
;
"set" does not affect the implicit keep, and it's compatible with all actions defined in [SIEVE] ๐ซถ.
4.1. Modifiers ๐ฆ
Usage:
":lower" / ":upper" / ":lowerfirst" / ":upperfirst" /
":quotewildcard" / ":length"
Modifier names are case insensitive. Unknown modifiers MUST yield a syntax error ๐ โโ๏ธ. You can specify more than one modifier, and when you do, they get applied according to this precedence list, with the largest value first ๐:
+--------------------------------+
| Precedence Modifier |
+--------------------------------+
| 40 :lower |
| :upper |
+--------------------------------+
| 30 :lowerfirst |
| :upperfirst |
+--------------------------------+
| 20 :quotewildcard |
+--------------------------------+
| 10 :length |
+--------------------------------+
It is an error to use two or more modifiers of the same precedence in a single "set" action ๐จ.
Examples:
# The value assigned to the variable is printed after the arrow
set "a" "juMBlEd lETteRS"; => "juMBlEd lETteRS"
set :length "b" "${a}"; => "15"
set :lower "b" "${a}"; => "jumbled letters"
set :upperfirst "b" "${a}"; => "JuMBlEd lETteRS"
set :upperfirst :lower "b" "${a}"; => "Jumbled letters"
set :quotewildcard "b" "Rock*"; => "Rock\*"
4.1.1. Modifier ":length" ๐
The value is the decimal number of characters in the expansion, converted to a string ๐ข.
4.1.2. Modifier ":quotewildcard" ๐ก๏ธ
This modifier adds the quoting needed to make sure the expanded text only matches a literal occurrence when it's used as a parameter to :matches ๐ฏ. Every character with special meaning ("*", "?", and "") gets prefixed with "" in the expansion ๐ .
4.1.3. Case Modifiers ๐ค
These modifiers change the letters of the text from upper to lower case, or the other way around. Characters other than "A"-"Z" and "a"-"z" from US-ASCII are left unchanged ๐.
4.1.3.1. Modifier ":upper" โฌ๏ธ
All lower case letters are converted to their upper case counterparts ๐ฅ.
4.1.3.2. Modifier ":lower" โฌ๏ธ
All upper case letters are converted to their lower case counterparts ๐ธ.
4.1.3.3. Modifier ":upperfirst" ๐
The first character of the string is converted to upper case if it's a letter and is set in lower case. The rest of the string is left unchanged ๐.
4.1.3.4. Modifier ":lowerfirst" ๐ง
The first character of the string is converted to lower case if it's a letter and is set in upper case. The rest of the string is left unchanged ๐ซถ.
5. Test string โจ
okay bestie, the string test is literally so good ๐ it checks whether any of the source strings matches any key. If you don't say which kind of match you want, it defaults to ":is" ๐
Usage: string [MATCH-TYPE] [COMPARATOR]
<source: string-list> <key-list: string-list>
Now the big rule for this one ๐ source and key-list both come from the script, NOT the message, and whitespace stripping MUST NOT be done unless the script explicitly asks for it through some future mechanism. no cap, that's a strict vibe ๐
Example, because you know I love showing you:
Example:
set "state" "${state} pending";
if string :matches " ${state} " "* pending *" {
# the above test always succeeds
}
Obsessed with that one tbh ๐ญ the ${state} gets swapped in first, so the pattern matches no matter what.
The "relational" extension [RELATIONAL] adds a match type called ":count" ๐ง For a single string, the count is 0 if it's the empty string, and 1 otherwise. For a string list, the count is the sum of the counts of the member strings. It's giving math class, but make it cute ๐
6. Implementation Limits ๐ฆ
okay this section is about the limits every implementation has to handle, and I need you to take them seriously ๐ซถ
An implementation of this document MUST support at least 128 distinct variables. The supported length of variable names MUST be at least 32 characters. Each variable MUST be able to hold at least 4000 characters. If you try to set a variable to a value bigger than the implementation can handle, it SHOULD be reported as an error at compile-time if that's possible. If the attempt gets discovered at run-time instead, the value SHOULD be truncated, and it MUST NOT be treated as an error. ๐ณ that run-time thing is a little plot twist, ngl
Match variables ${1} through ${9} MUST be supported. References to higher indices than the implementation supports MUST be treated as a syntax error, which SHOULD be discovered at compile-time. Bestie, catch these early ๐ฅ
7. Security Considerations ๐
this section is serious, so I'm going to be serious too ๐ฅบ
When match variables are used, and the author of the script isn't careful, strings can contain arbitrary values controlled by the sender of the mail. Yikes ๐ฌ the sender can literally write whatever they want into those strings.
โ ๏ธ Since values stored by set that exceed implementation limits are silently truncated, it's not appropriate to store large structures with security implications in variables. Don't do it, periodt.
The introduction of variables makes advanced decision making easier to write, but since no looping construct is provided, all Sieve scripts will terminate in an orderly manner. So no infinite loops, which is honestly iconic ๐
Sieve filtering should not be relied on as a security measure against hostile mail messages. Sieve is designed to do simple, mostly static tests, and it is not suitable for use as a spam or virus checker, where the perpetrator has a motivation to vary the format of the mail in order to avoid filtering rules. See also [SPAMTEST]. Not me trusting Sieve to stop hackers ๐ it's a filtering tool, not a bodyguard.
8. IANA Considerations ๐ธ
the IANA part is basically a template for registering the variables extension. Here's how it's written:
To: iana@iana.org
Subject: Registration of new Sieve extension
Capability name: variables
Description: Adds support for variables to the Sieve filtering
language.
RFC number: RFC 5229
Contact address: The Sieve discussion list <ietf-mta-filters@imc.org>
9. Acknowledgments ๐ซถ
big thank-you to Cyrus Daboo, Jutta Degener, Ned Freed, Lawrence Greenfield, Jeffrey Hutzelman, Mark E. Mallett, Alexey Melnikov, Peder Stray, and Nigel Swinson for giving valuable feedback. You all ate ๐โจ
10. References ๐
10.1. Normative References
- [ABNF] Crocker, D., Ed., and Overell, P., "Augmented BNF for Syntax Specifications: ABNF", RFC 4234, October 2005.
- [KEYWORDS] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.
- [RELATIONAL] Segmuller, W. and B. Leiba, "Sieve Email Filtering: Relational Extension", RFC 5231, January 2008.
- [SIEVE] Guenther, P., Ed., and T. Showalter, Ed., "Sieve: An Email Filtering Language", RFC 5228, January 2008.
- [UTF-8] Yergeau, F., "UTF-8, a transformation format of Unicode and ISO 10646", RFC 3629, November 2003.
10.2. Informative References
- [ISO10646] ISO/IEC, "Information Technology - Universal Multiple-Octet Coded Character Set (UCS) - Part 1: Architecture and Basic Multilingual Plane", May 1993, with amendments.
- [REGEX] Murchison, K., "Sieve Email Filtering -- Regular Expression Extension", Work in Progress, February 2006.
- [SPAMTEST] Daboo, C., "Sieve Email Filtering: Spamtest and Virustest Extensions", RFC 5235, January 2008.
Author's Address ๐
Kjetil T. Homme
University of Oslo
PO Box 1080
0316 Oslo, Norway
Phone: +47 9366 0091
EMail: kjetilho@ifi.uio.no
Full Copyright Statement ๐
Copyright (C) The IETF Trust (2008).
This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights.
This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM 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. ๐
Intellectual Property ๐ง
The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document or the extent to which any license under such rights might or might not be available; nor does it represent that it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79.
Copies of IPR disclosures made to the IETF Secretariat and any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr.
The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at ietf-ipr@ietf.org. ๐ฆ
๐ฆ where this page comes from
- ietf: rfc5229 2008-01
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms