<?xml version="1.0" encoding="utf-8"?>
<!-- name="GENERATOR" content="github.com/mmarkdown/mmark Mmark Markdown Processor - mmark.miek.nl" -->
<rfc version="3" ipr="trust200902" docName="draft-happel-sieve-filter-rule-metadata-00" submissionType="IETF" category="info" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" indexInclude="true" consensus="true">

<front>
<title>Sieve Filter Rule Metadata</title><seriesInfo value="draft-happel-sieve-filter-rule-metadata-00" stream="IETF" status="informational" name="Internet-Draft"></seriesInfo>
<author initials="H.-J." surname="Happel" fullname="Hans-Joerg Happel"><organization>audriga GmbH</organization><address><postal><street></street>
</postal><email>happel@audriga.com</email>
<uri>https://www.audriga.com</uri>
</address></author><date/>
<area>ART</area>
<workgroup>Network Working Group</workgroup>

<abstract>
<t>This document describes current practices in managing Sieve scripts and proposes a standardized way for storing filter rule metadata in Sieve comments.</t>
</abstract>

</front>

<middle>

<section anchor="introduction"><name>Introduction</name>
<t>Sieve is a formal language for email filtering specified in (RFC5228). Filters are stored in so called &quot;scripts&quot;, which are text files containing Sieve filtering expressions.</t>
<t>Users can edit Sieve scripts directly, in case they have access to the script files, or by using the ManageSieve protocol (RFC5804), if it is made available by their email service.</t>
<t>While experienced users may follow this approach, (RFC5228, section 1) anticipates that &quot;GUI-based editors will be the preferred way of editing filters for a large number of users.&quot;</t>
<t>This likely describes current practice, given that typical end users rarely have direct access to their Sieve scripts, and given that most email services do not offer ManageSieve access. Furthermore, even for a popular email client such as Thunderbird, only very rough Script editors seem to exist <xref target="TBSieve"></xref>.</t>

<section anchor="gui-based-email-filter-editors"><name>GUI-based email filter editors</name>
<t>Many Webmail and Groupware software features GUI-based email filter editors, which use Sieve as the underlying script language. When creating filters, the editor will create or update the user's Sieve script. When opening the editor, the script will be parsed and presented in a constrained set of UI widgets (such as dropdown-lists or input fields).</t>
<t>The vast majority (if not all) GUI-based editors follow a similar interaction paradigm, which is designed along the Sieve language design concepts. A user first needs to define a &quot;test&quot; (RFC5228, section 2.5), which defines filtering criteria (e.g., based on sender or size of a message). The second major component is the definition of one or more &quot;actions&quot; (RFC5228, section 4), such as to move an email matching the filtering criteria into a certain mailbox.</t>
<t>The design of existing editors affords users to <em>modularize</em> their email filters, so that multiple test/action style &quot;fiter rules&quot; are created. The &quot;else&quot; and &quot;elseif&quot; keywords, which are common in free-form Sieve scripts (RFC5228, section 9), are typically not used in those modularized filter rules.</t>
<t>Modularized filter rules often contain a &quot;stop;&quot; commend as their final action by default, which makes them widely independent of each other. GUI-based email filter editors typically allow users to label and to (re-)order filter rules.</t>
</section>

<section anchor="indirect-creation-of-email-filters"><name>Indirect creation of email filters</name>
<t>Besides a dedicated GUI-based editor for email filters, many Webmail and Groupware software include additional ways to modify the Sieve script of a user. There are <em>contextual</em> interfaces, which create rules in the background or which launch a prefilled filter rule creation dialog.</t>
<t>Examples are:</t>

<ul spacing="compact">
<li>Creating a filter rule based on a sender's email address (&quot;Move all emails from &quot;John Doe&quot; to ...&quot;)</li>
<li>Adding a sender to a block- or allowlist</li>
</ul>
<t>The latter case is also an example for special purpose filters as described in the following.</t>
</section>

<section anchor="special-purpose-email-filters"><name>Special purpose email filters</name>
<t>Email filters are often used as a technology for realizing other features, such as blocklists, vacation messages [RFC5230], or email forwarding. In most of these cases, there will be a <em>dedicated user interface</em> specific to the feature. This user interface will still write to the user's Sieve script, but the corresponding email filter will either not be editable or hidden in the regular email filter editor.</t>
<t>This special handling in the filter editor (i.e., the recognition of a special purpose filter rule) is typically based on metadata which is captured in Sieve comments (see also <xref target="examples"></xref>).</t>
</section>

<section anchor="other-kinds-of-sieve-scripts"><name>Other kinds of Sieve scripts</name>
<t>Besides capturing rules based on user input, Sieve scripts are sometimes also used in other ways. E.g., some SPAM filtering systems use machine-generated Sieve scripts for their operations. Such scripts are typically hidden from end users and hence cannot be edited. They are out of the scope of this draft.</t>
</section>

<section anchor="conventions-used-in-this-document"><name>Conventions Used in This Document</name>
</section>
</section>

<section anchor="modular-sieve-scripts-in-practice"><name>Modular Sieve scripts in practice</name>

<section anchor="rule-comments"><name>Rule comments</name>
<t>In order to manage modularized Sieve scripts, GUI-based script editors need to capture the following information.</t>

<ul spacing="compact">
<li>The <em>type</em> of a rule, distinguishing user-defined rules from certain special-purpose rules. Examples for the latter are: VACTION, SPAM, ALLOWED/BLOCKED SENDER, AUTOFORWARD.</li>
<li>The user-defined name of a rules, as shown in the rule management UI. Some systems will use predefined rule names instead of rule types.</li>
</ul>
<t>In addition to this, some systems store further information:</t>

<ul spacing="compact">
<li>Rule Id: an id for internal reference and/or ordering of rules in processing and list presentation.</li>
<li>Rule position: a numberic value to maintain the ordering of filter rules in a separate field.</li>
<li>Rule description: additional notes complementing the rule label</li>
</ul>
<t>Since none of this information is natively supported by the Sieve rule language, systems fall back to Sieve comments for storing. Various vendor-specific practices have emerged, as seen in <xref target="examples"></xref>.</t>
</section>

<section anchor="deactivation-of-filtering-rules"><name>Deactivation of filtering rules</name>
<t>Another aspect of informal standardization has been the deacativation of certain Sieve code. Based on the RFC, Sieve offers two means of deactivation:</t>

<ul spacing="compact">
<li>Commenting out Sieve code</li>
<li>Keeping one active and multiple deativated scripts (as per ManageSieve (RFC5804, section 1.4))</li>
</ul>
<t>While some vendors using type (b) scripts rely on commenting out for disabling individual modular rules, others came up with more formalized approaches such as wrapping disabled rules using a simple &quot;if (false)&quot; clause.</t>

<section anchor="example-commenting-out"><name>Example: Commenting out</name>
<t>The following filtering rule is take from an OpenXChange-generated Sieve script:</t>

<artwork>Flag: |UniqueId:15|Rulename: testRuleCreate
if true 
{
    discard ;
}
</artwork>
<t>Once &quot;deactivated&quot; in the user interface, this filtering rule will be represented in the Sieve script as follows:</t>

<artwork>## Flag: |UniqueId:15|Rulename: testRuleCreate
#&lt;!--&gt;if true 
#&lt;!--&gt;{
#&lt;!--&gt;    discard ;
#&lt;!--&gt;}
</artwork>
</section>

<section anchor="example-wrapping"><name>Example: Wrapping</name>
<t>The following filtering rule is take from an CriticalPath-generated Sieve script:</t>

<artwork>if allof (true, header :contains &quot;X-Priority&quot; &quot;5&quot;)
{
	discard;
}
</artwork>
<t>Once &quot;deactivated&quot; in the user interface, this filtering rule will be represented in the Sieve script as follows:</t>

<artwork>if allof (false, header :contains &quot;X-Priority&quot; &quot;5&quot;)
{
	discard;
}
</artwork>
</section>
</section>

<section anchor="issues"><name>Issues</name>
<t>While the described informal workarounds helped vendors to cope within the boundaries of the Sieve language, we see a number of issues with this status quo:</t>

<ul spacing="compact">
<li>Interoperability: Vendor-specific workarounds tend to work only with the vendors own user interfaces. Any attempt to edit the resulting Sieve scripts can essentially cause trouble displaying these scripts respectively their contained rules within the vendors UI. Furthermore, editing special-purpose rules might even lead to more severe side effects. The lack of interoperability might be considered a barrier for the implementation of useful Sieve clients, which in turn hinders more widespread adoption of Sieve.</li>
<li>Portability: similar to the way Sieve clients should be able to interoperate with the Sieve usage of servers, Sieve scripts should be portable between different Sieve server vendors. Otherwise, users will not be able to transfer their data between different providers.</li>
</ul>
</section>
</section>

<section anchor="proposed-conventions"><name>Proposed conventions</name>
<t>The purpose of this section is to propose a normative reference for filtering rule comments and deactivation.</t>

<section anchor="script-comments"><name>Script comments</name>
<t>(TBD)</t>
</section>

<section anchor="rule-comments-1"><name>Rule comments</name>
<t>(TBD)</t>
</section>

<section anchor="deactivation-of-filtering-rules-1"><name>Deactivation of filtering rules</name>
<t>For the purpose of deactivating rules, the &quot;wrapping&quot; approach described in the previous section should be applied.</t>
<t>(TBD)</t>
</section>
</section>

<section anchor="examples"><name>Examples</name>
<t>In this section, we will document Sieve script patterns used by the software of different vendors.</t>
<t>&quot;(...)&quot; stands for omitted code in example scripts.</t>

<section anchor="criticalpath"><name>CriticalPath</name>

<artwork># cp_filter_name: Test filter
# cp_filter_description: 
</artwork>
</section>

<section anchor="horde-ingo"><name>Horde (Ingo)</name>

<artwork># Sieve Filter
# Generated by Ingo (http://www.horde.org/apps/ingo/) (09/03/2021, 05:37:41 PM)

require [&quot;vacation&quot;, &quot;regex&quot;, &quot;fileinto&quot;, &quot;imapflags&quot;, &quot;body&quot;, &quot;reject&quot;, &quot;notify&quot;];

# Whitelisted Addresses
if address :all :comparator &quot;i;ascii-casemap&quot; :is [&quot;From&quot;, &quot;Sender&quot;, &quot;Resent-From&quot;] &quot;whitelist@foo.com&quot;  {
    keep;
    stop;
}

# Vacation
(...)

# Blacklisted Addresses
if address :all :comparator &quot;i;ascii-casemap&quot; :is [&quot;From&quot;, &quot;Sender&quot;, &quot;Resent-From&quot;] &quot;non@foo.com&quot;  {
    discard;
    stop;
}

# Spamfilter
if header :comparator &quot;i;ascii-casemap&quot; :matches &quot;X-Spam-Status&quot; &quot;yes*&quot;  {
    fileinto &quot;spamblock&quot;;
    stop;
}

# Forwards
if true {
    redirect &quot;fws@foo.com&quot;;
}

# userDefined Rule (Name: fileInto userDefinedFolder)
if address :all :comparator &quot;i;ascii-casemap&quot; :contains &quot;To&quot; &quot;x&quot;  {
    fileinto &quot;userDefinedFolder&quot;;
    stop;
}
</artwork>
</section>

<section anchor="oracle-communication-messaging-server"><name>Oracle Communication Messaging Server</name>

<artwork>#RULE: $Name=&quot;Blocked senders&quot; $Type=&quot;BLOCKED_ADDRESSES&quot; $Version=1 $Lz=1 $Order=1
#BEGINFILTER
(...)
#ENDFILTER

#RULE: $Name=&quot;Test Folder Bulkmail&quot; $Type=&quot;DEFAULT_TYPE&quot; $Version=1 $Lz=1 $Order=6
#require &quot;fileinto&quot;;
(...)
#ENDRULE
</artwork>
</section>

<section anchor="openxchange"><name>OpenXchange</name>

<artwork>## Flag: vacation|UniqueId:1|Rulename: vacation notice

## Flag: autoforward|UniqueId:2|Rulename: autoforward

## Flag: |UniqueId:0|Rulename: MyTestFiler
</artwork>
</section>

<section anchor="openwave-intermail"><name>OpenWave/InterMail</name>
</section>
</section>

<section anchor="security-considerations"><name>Security considerations</name>
<t>TBD</t>
</section>

<section anchor="iana-considerations"><name>IANA Considerations</name>
<t>This document has no IANA actions at this time.</t>
</section>

</middle>

<back>
<references><name>Informative References</name>
<reference anchor="TBSieve" target="https://addons.thunderbird.net/de/thunderbird/addon/sieve/">
  <front>
    <title>Thunderbird Sieve Add-On</title>
    <author fullname="Thomas Schmid" initials="T." surname="Schmid"></author>
    <date></date>
  </front>
</reference>
</references>

</back>

</rfc>
