<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629-xhtml.ent">

<rfc version="3" ipr="trust200902" docName="draft-ietf-extra-sieve-mailboxid-09" number="9042" submissionType="IETF" category="std" consensus="true" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" updates="5228" sortRefs="true" symRefs="true" tocInclude="true">

<front>
<title abbrev="Sieve MAILBOXID">Sieve Email Filtering: Delivery by
MAILBOXID</title>
<seriesInfo name="RFC" value="9042"/>
<author role="editor" initials="B." surname="Gondwana" fullname="Bron Gondwana">
<organization>Fastmail</organization>
<address>
<postal>
<extaddr>Level 2</extaddr>
<street>114 William St</street>
<city>Melbourne</city>
<region>VIC</region>
<code>3000</code>
<country>Australia</country>
</postal>
<email>brong@fastmailteam.com</email>
<uri>https://www.fastmail.com</uri>
</address></author>
<date year="2021" month="June"></date>
<area>Applications</area>
<workgroup>EXTRA</workgroup>
<keyword>sieve</keyword>
<keyword>email</keyword>

<abstract>
<t>The OBJECTID capability of IMAP (RFC 8474) allows clients to
identify mailboxes by a unique identifier that survives renaming.</t>
<t>This document extends the Sieve email filtering language (RFC 5228) to
allow using that same unique identifier as a target for fileinto rules
and for testing the existence of mailboxes.</t>
</abstract>

</front>

<middle>

<section anchor="introduction"><name>Introduction</name>
<t>Sieve rules <xref target="RFC5228"></xref> are sometimes created using graphical interfaces,
which allow users to select the mailbox to be used as a target for a rule.</t>
<t>If that mailbox is renamed, the client may also update its internal
representation of the rule and update the Sieve script to match;
however, this is a multistep process and subject to partial failures.
Also, if the folder is renamed by a different mechanism (e.g., another
IMAP client), the rules will get out of sync.</t>
<t>By telling fileinto to reference the immutable MAILBOXID specified
by <xref target="RFC8474"></xref>, using the extension specified herein, Sieve rules can
continue to target the same mailbox, even if it gets renamed.</t>
</section>

<section anchor="conventions-used-in-this-document"><name>Conventions Used in This Document</name>
        <t>
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>", "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL
    NOT</bcp14>", "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>", "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be interpreted as
    described in BCP&nbsp;14 <xref target="RFC2119"/> <xref target="RFC8174"/> 
    when, and only when, they appear in all capitals, as shown here.
        </t>
</section>

<section anchor="sieve-capability-string"><name>Sieve Capability String</name>
<t>Scripts that use the extensions defined in this document <bcp14>MUST</bcp14> explicitly require
the capability "mailboxid".</t>
<t>Example:</t>

<sourcecode type=""><![CDATA[
require "mailboxid";
]]></sourcecode>
</section>

<section anchor="argument-mailboxid-to-command-fileinto">
<name>Argument :mailboxid to Command fileinto</name>
<t>Normally, the fileinto command delivers the message in the mailbox
specified using its positional mailbox argument.  However, if the
optional :mailboxid argument is also specified, the fileinto
command first checks whether a mailbox exists in the user's personal
namespace <xref target="RFC2342"></xref> with the specified MAILBOXID <xref target="RFC8474"></xref>.</t>
<t>If a matching mailbox is found, that mailbox is used for delivery.</t>
<t>If there is no such mailbox, the fileinto action proceeds as it would
without the :mailboxid argument.</t>
<t>The tagged argument :mailboxid to fileinto consumes one additional token,
a string containing the OBJECTID of the target mailbox.</t>
<t>Example:</t>

<sourcecode type=""><![CDATA[
require "fileinto";
require "mailboxid";

if header :contains ["from"] "coyote" {
    fileinto :mailboxid "F6352ae03-b7f5-463c-896f-d8b48ee3"
             "INBOX.harassment";
}
]]></sourcecode>

<section anchor="interaction-with-mailbox-extension"><name>Interaction with Mailbox Extension</name>
<t>For servers that also support the mailbox extension defined in <xref target="RFC5490"></xref>, if both the
:create and :mailboxid arguments are provided to a fileinto command and
no matching mailbox is found, then a new mailbox will be created.</t>
<t>This new mailbox will have the name specified by the positional mailbox
argument (<xref target="RFC5228" sectionFormat="comma" section="4.1"/>); however, it will get a different MAILBOXID
(chosen by the server) rather than the one specified by the :mailboxid
argument to fileinto.</t>
<t>Example:</t>

<sourcecode type=""><![CDATA[
require "fileinto";
require "mailboxid";
require "mailbox";

fileinto :mailboxid "Fnosuch"
         :create
         "INBOX.no-such-folder";
            # creates INBOX.no-such-folder, but it doesn't
            # get the "Fnosuch" mailboxid.
]]></sourcecode>
</section>

<section anchor="interaction-with-specialuse-extension"><name>Interaction with Special-Use Extension</name>
<t>For servers that also support delivery to special-use mailboxes <xref target="RFC8579"></xref>,
it is an error to specify both :mailboxid and :specialuse in the same
fileinto command.</t>
<t>Advanced filtering based on both special-use and MAILBOXID can be
built with explicit specialuse_exists and mailboxidexists tests.</t>
<aside>
<t>Note to developers of Sieve generation tools:</t>
<t>It is advisable to use
special-use rather than MAILBOXID when creating rules that are based
on a special-use purpose (e.g., delivery directly to the Junk folder
based on a header that was added by a scanning agent earlier in the
mail flow).</t>
</aside>
</section>
</section>

<section anchor="interaction-with-fcc-extension"><name>Interaction with FCC Extension</name>
<t>This document extends the definition of the :fcc argument defined in
<xref target="RFC8580"></xref> so that it can optionally be used with the :mailboxid
argument.  The syntax for FCC is extended here using ABNF <xref target="RFC5234"></xref>:</t>

<sourcecode type="abnf"><![CDATA[
MAILBOXID-OPT = ":mailboxid" objectid

FCC-OPTS =/ MAILBOXID-OPT
]]></sourcecode>
<t>If the optional :mailboxid argument is specified with :fcc, it
instructs the Sieve interpreter to check whether a mailbox exists
with the specific MAILBOXID.  If such a mailbox exists, the generated
message is filed into that mailbox.  Otherwise, the generated message
is filed into the :fcc target mailbox.</t>
<t>As with fileinto, it is an error to specify both :mailboxid
and :specialuse for the same fcc rule.</t>
<t>Example:</t>

<sourcecode type=""><![CDATA[
require ["enotify", "fcc", "mailboxid"];
notify :fcc "INBOX.Sent"
       :mailboxid "F6352ae03-b7f5-463c-896f-d8b48ee3"
       :message "You got mail!"
       "mailto:ken@example.com";
]]></sourcecode>
</section>


<section anchor="test-mailboxidexists"><name>Test mailboxidexists</name>
<t>Usage: mailboxidexists &lt;mailbox-objectids: string-list&gt;</t>
<t>The mailboxidexists test is true if every string argument provided is the MAILBOXID of a mailbox that exists in the mailstore and that allows the user in whose context the Sieve script runs to deliver messages into it.</t>
<t>When the mailstore is an IMAP server that also supports IMAP
Access Control List (ACL) <xref target="RFC4314"></xref>, delivery is allowed if the user has the 'p' or 'i' rights for the mailbox (see
   <xref target="RFC4314" sectionFormat="of" section="5.2"/>).</t>
<t> When the mailstore is an IMAP server that does not support IMAP ACL, delivery is allowed if the READ-WRITE response code is present for the mailbox when selected by the user (see <xref target="RFC3501" sectionFormat="of" section="7.1"/>).</t>
<t>Note that a successful mailboxidexists test for a mailbox doesn't
necessarily mean that a &quot;fileinto :mailboxid&quot; action on this mailbox
would succeed.  For example, the fileinto action might put the user over
quota.  The mailboxidexists test only verifies existence of the
mailbox and whether the user in whose context the Sieve script runs
has permissions to execute fileinto on it.</t>
<t>Example:</t>

<sourcecode type=""><![CDATA[
require "fileinto";
require "mailboxid";

if header :contains ["from"] "coyote" {
    if mailboxidexists "F6352ae03-b7f5-463c-896f-d8b48ee3" {
        fileinto :mailboxid "F6352ae03-b7f5-463c-896f-d8b48ee3"
                            "INBOX.name.will.not.be.used";
    } else {
        fileinto "INBOX.harassment";
    }
}
]]></sourcecode>
<aside>
<t>Note to implementers:</t> 
<t>This test behaves identically to the
mailboxexists test defined in <xref target="RFC5490"></xref> but operates on
MAILBOXIDs rather than mailbox names.</t>
</aside>
</section>

<section anchor="interaction-with-variables-extension"><name>Interaction with Variables Extension</name>
<t>There is no special interaction defined; however, as an OBJECTID
is a string in this document, OBJECTID values can contain
variable expansions if <xref target="RFC5229"></xref> is enabled.</t>
</section>

<section anchor="security-considerations"><name>Security Considerations</name>
<t>Because MAILBOXID is always generated by the server, implementations
<bcp14>MUST NOT</bcp14> allow Sieve to make an end run around this protection by
creating mailboxes with the specified ID by using :create and
:mailboxid in a fileinto rule for a nonexistent mailbox.</t>
<t>Implementers are referred to the Security Considerations sections
of <xref target="RFC5228"></xref> and <xref target="RFC8474"></xref>.</t>
</section>
<section anchor="iana-considerations"><name>IANA Considerations</name>
<t>IANA has added the following capability to the "Sieve Extensions" registry
at <eref brackets="angle"
target="https://www.iana.org/assignments/sieve-extensions"/>:</t>

<dl newline="false" spacing="compact">
  <dt>Capability name:</dt> 
  <dd>mailboxid</dd>
  <dt>Description:</dt> 
  <dd>adds a test for checking mailbox existence by OBJECTID
             and new optional arguments to fileinto and :fcc that
             allow selecting the destination mailbox by OBJECTID.</dd>
  <dt>RFC number:</dt> 
  <dd>RFC 9042</dd>
  <dt>Contact address:</dt> 
  <dd>EXTRA discussion list &lt;extra@ietf.org&gt;</dd>
</dl>
</section>
</middle>
<back>
<references><name>References</name>
<references><name>Normative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5228.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8474.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5234.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2342.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8580.xml"/>
</references>
<references><name>Informative References</name>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.8579.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5490.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.3501.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4314.xml"/>
<xi:include href="https://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5229.xml"/>
</references>
</references>
<section anchor="acknowledgements" numbered="false"><name>Acknowledgements</name>
<t>This document borrows heavily from <xref target="RFC5490"></xref> for the matching
mailboxexists test and from <xref target="RFC8579"></xref> for an example of modifying
the fileinto command.</t>
<t>Thanks to <contact fullname="Ned Freed"/>, <contact fullname="Ken Murchison"/>, and <contact fullname="Alexey Melnikov"/> for feedback
on the EXTRA mailing list.</t>
</section>
</back>
</rfc>
