rfc-5703

Sieve Email Filtering: MIME Part Tests, Iteration, Extraction, Replacement, and Enclosure

T. Hansen, C. Daboo
date2009-10 streamIETF areaapp wgsieve statusPROPOSED STANDARD pages18 canonicalhttps://www.rfc-editor.org/rfc/rfc5703 doi10.17487/RFC5703 errataview
This document defines extensions to the Sieve email filtering language to permit analysis and manipulation of the MIME body parts of an email message. [STANDARDS-TRACK]

Extracted elements (26)

design-rationale §6

After 'enclose' is executed, subsequent actions and tests operate on the newly created wrapper message rather than the original. Therefore, any 'replace' or similar actions should be executed before 'enclose' to affect the original message content.

email

design-rationale §5

When a 'foreverypart' loop replaces a multipart MIME part via 'replace', structural changes take effect immediately: the currently executing iterator does not descend into the now-removed children, and subsequent iterators use the new structure. This avoids undefined behavior from iterating over deleted parts.

email

interoperability-note §4.1

The ':anychild' tagged argument may only appear when ':mime' is also present; its presence without ':mime' is an error. Without ':mime' and ':anychild', the extended 'header', 'address', and 'exists' tests behave identically to their RFC 5228 definitions.

email

normative-requirement §5 MUST

If ':mime' is specified in 'replace' along with either ':subject' or ':from', those parameters MUST be ignored. This SHOULD be flagged as a compilation error.

email

normative-requirement §4.1 SHOULD

Implementations SHOULD support desegmentation, decoding, and charset translation of parameter values encoded per RFC 2231 as part of the ':mime' header test. Implementations MAY also decode RFC 2047-encoded words in parameter values.

email

normative-requirement §5 MUST

Implementations supporting the 'editheader' extension MUST ensure that Original-Subject or Original-From headers added by 'replace' cannot be modified or removed via 'editheader'.

email

normative-requirement §7 MUST

Servers MUST support transcoding of any textual body part into UTF-8 for use with 'extracttext', including decoding transfer encodings and transcoding from the indicated character set. Unrecognized or invalid encoding results in an empty string.

email

normative-requirement §3 MUST

Sieve implementations MAY limit the number of nested 'foreverypart' loops, but MUST support at least one nested loop inside another loop.

email

normative-requirement §7 SHOULD

Using 'extracttext' outside a 'foreverypart' loop sets the variable to empty string and SHOULD be flagged as a compilation error.

email

normative-requirement §5 MUST

When 'replace' is used without ':mime', the replacement is treated as a text/plain part in UTF-8. When ':mime' is specified, the replacement string is a full MIME entity including MIME headers and content.

email

normative-requirement §5 MUST

When 'replace' uses ':from', implementations SHOULD check syntax and generate an error for syntactically invalid values. Implementations MUST preserve the previous From header as Original-From if the From header is changed.

email

normative-requirement §5 MUST

When replacing the entire message with a ':subject' parameter, implementations MUST convert non-ASCII characters to RFC 2047-encoded words, MUST preserve the previous Subject as Original-Subject, and MUST preserve all other header fields except those relating to the replaced MIME structure.

email

protocol-element §4.1

MIME header options for the ':mime' tagged argument include ':type' (MIME type or Content-Disposition value), ':subtype' (MIME subtype), ':contenttype' (combined type/subtype), and ':param' (named MIME parameters). These are used with the extended 'header' test.

email

protocol-element §4.2

The 'address' test is extended with ':mime' and ':anychild' tagged arguments, causing it to parse MIME header lines as address headers. Without ':mime'/':anychild', it operates only on top-level header fields as in RFC 5228.

email

protocol-element §3

The 'break' command terminates the closest enclosing 'foreverypart' loop, or if a ':name' parameter is given, terminates the nearest enclosing loop with that matching name. It is an error to use a named break with no enclosing loop of that name.

email

protocol-element §6

The 'enclose' action wraps the entire message as a message/rfc822 attachment inside a new multipart/mixed message with a text/plain preamble. The ':subject' argument sets the new subject; ':headers' copies specified headers from the original message.

email

protocol-element §4.3

The 'exists' test is extended with ':mime' and ':anychild' tagged arguments to check for the existence of MIME headers in MIME parts. Semantics of ':anychild' interaction with 'foreverypart' mirrors the extended 'header' test.

email

protocol-element §7

The 'extracttext' action stores the transcoded text content of the current MIME body part into a Sieve variable. Optional ':first N' limits extraction to the first N characters. It must be used within a 'foreverypart' loop; outside a loop, it sets the variable to empty string.

email

protocol-element §3

The 'foreverypart' action is a loop iterator that walks through every MIME part of a message depth-first, including nested parts, applying a command block to each. It can be named with ':name' and terminated early using the 'break' command.

email

protocol-element §4.1

The 'header' test is extended with ':mime' and ':anychild' tagged arguments. ':mime' enables parsing of MIME header lines; ':anychild' (only valid with ':mime') causes the test to examine all nested MIME body parts rather than just the current part.

email

protocol-element §5

The 'replace' action replaces a MIME part with supplied text. When inside 'foreverypart', it replaces the current MIME part; when outside, it replaces the entire message. Optional ':subject' and ':from' parameters apply only when replacing the entire message.

email

registry §12

Five new Sieve extension capability strings are registered with IANA: 'foreverypart' (loop iteration), 'mime' (MIME-aware tests), 'replace' (MIME part replacement), 'enclose' (message enclosure), and 'extracttext' (text extraction into variables).

email, registry

registry §12

The Original-Subject and Original-From header fields are registered in the IANA Permanent Message Header Fields registry, created when 'replace' preserves prior Subject or From headers during whole-message replacement.

email, registry

security-consideration §11

The 'enclose' action creates an entirely new message, so site policies applicable to message submission should be enforced. Using 'replace' or 'enclose' may interfere with digital signatures (DKIM, S/MIME, PGP, OpenPGP) that cover the message content.

email, security

security-consideration §11 MUST

The system MUST be sized and restricted so that even malicious use of MIME part matching does not deny service to other users. It is not possible to examine the MIME structure of decrypted content in a multipart/encrypted MIME part.

email, security

security-consideration §11 MUST

When 'enclose' is used on a message containing a multipart/signed MIME part, the implementation MUST copy the original message octet-for-octet to maintain the validity of the digital signature.

email, security