<?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-ietf-extra-sieve-mailboxid-08" submissionType="IETF" category="std" xml:lang="en" xmlns:xi="http://www.w3.org/2001/XInclude" updates="5228" consensus="true">

<front>
<title abbrev="Sieve MAILBOXID">Sieve Email Filtering: delivery by mailboxid</title><seriesInfo value="draft-ietf-extra-sieve-mailboxid-08" stream="IETF" status="standard" name="Internet-Draft"></seriesInfo>
<author role="editor" initials="B." surname="Gondwana" fullname="Bron Gondwana"><organization>Fastmail</organization><address><postal><street>Level 2, 114 William St</street>
<city>Melbourne</city>
<code>VIC 3000</code>
<country>Australia</country>
</postal><email>brong@fastmailteam.com</email>
<uri>https://www.fastmail.com</uri>
</address></author>
<date year="2021" month="March" day="16"></date>
<area>Applications</area>
<workgroup>EXTRA</workgroup>
<keyword>sieve</keyword>
<keyword>email</keyword>

<abstract>
<t>The OBJECTID capability of the IMAP protocol (RFC8474) allows clients to
identify mailboxes by a unique identifier which survives rename.</t>
<t>This document extends the Sieve mail filtering language (RFC5228) to
allow using that same unique identifier as a target for fileinto rules,
and for testing the existance of mailboxes.</t>
</abstract>

</front>

<middle>

<section anchor="introduction"><name>Introduction</name>
<t><xref target="RFC5228"></xref> Sieve rules 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 multi-step 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 &quot;fileinto&quot; 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 &quot;MUST&quot;, &quot;MUST NOT&quot;, &quot;REQUIRED&quot;, &quot;SHALL&quot;, &quot;SHALL
NOT&quot;, &quot;SHOULD&quot;, &quot;SHOULD NOT&quot;, &quot;RECOMMENDED&quot;, &quot;NOT RECOMMENDED&quot;,
&quot;MAY&quot;, and &quot;OPTIONAL&quot; in this document are to be interpreted as
described in BCP 14 <xref target="RFC2119"></xref> <xref target="RFC8174"></xref> 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 which use the following extensions MUST explicitly require
the capability &quot;mailboxid&quot;.</t>
<t>Example:</t>

<artwork>require &quot;mailboxid&quot;;
</artwork>
</section>

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

<artwork>require &quot;fileinto&quot;;
require &quot;mailboxid&quot;;

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

<section anchor="interaction-with-mailbox-extension"><name>Interaction with &quot;mailbox&quot; extension</name>
<t>For servers which also support the <xref target="RFC5490"></xref> mailbox extension, if both the
&quot;:create&quot; and &quot;:mailboxid&quot; arguments are provided to a &quot;fileinto&quot; 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 ([RFC5228] section 4.1), however it will get a different mailboxid
(chosen by the server) rather than the one specified by the &quot;:mailboxid&quot;
argument to fileinto.</t>
<t>Example:</t>

<artwork>require &quot;fileinto&quot;;
require &quot;mailboxid&quot;;
require &quot;mailbox&quot;;

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

<section anchor="interaction-with-specialuse-extension"><name>Interaction with &quot;specialuse&quot; extension</name>
<t>For servers which also support <xref target="RFC8579"></xref> delivery to special-use mailboxes,
it is an error to specify both &quot;:mailboxid&quot; and &quot;:specialuse&quot; in the same
fileinto command.</t>
<t>Advanced filtering based on both special-use and mailboxid can be
built with explicit &quot;specialuse_exists&quot; and &quot;mailboxidexists&quot; tests.</t>
<t>Note to developers of sieve generation tools: 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
mailflow).</t>
</section>
</section>

<section anchor="interaction-with-fcc-extension"><name>Interaction with &quot;fcc&quot; extension</name>
<t>This document extends the definition of the &quot;:fcc&quot; argument defined in
<xref target="RFC8580"></xref> so that it can optionally be used with the &quot;:mailboxid&quot;
argument.</t>

<artwork>FCC-OPTS =/ [&quot;:mailboxid&quot; &lt;mailboxid: string&gt;]
</artwork>
<t>If the optional &quot;:mailboxid&quot; argument is specified with &quot;:fcc&quot;, 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 &quot;:fcc&quot; target mailbox.</t>
<t>As with fileinto, it is an error to specify both &quot;:mailboxid&quot;
and &quot;:specialuse&quot; for the same fcc rule.</t>
<t>Example:</t>

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

<section anchor="test-mailboxidexists"><name>Test &quot;mailboxidexists&quot;</name>
<t>The &quot;mailboxidexists&quot; test is true if all mailboxes listed in the
&quot;mailboxids&quot; argument exist in the mailstore, and each allows the
user in whose context the Sieve script runs to &quot;deliver&quot; messages
into it.  When the mailstore is an IMAP server, &quot;delivery&quot; of
messages is possible if:</t>
<t>a) the READ-WRITE response code is present for the mailbox (see
   Section 7.1 of <xref target="RFC3501"></xref>), if IMAP Access Control List (ACL)
   <xref target="RFC4314"></xref> is not supported by the server, or</t>
<t>b) the user has 'p' or 'i' rights for the mailbox (see Section 5.2
   of <xref target="RFC4314"></xref>).</t>
<t>Note that a successful &quot;mailboxidexists&quot; test for a mailbox doesn't
necessarily mean that a &quot;fileinto :mailboxid&quot; action on this mailbox
would succeed.  For example, the &quot;fileinto&quot; action might put user over
quota.  The &quot;mailboxidexists&quot; test only verifies existence of the
mailbox and whether the user in whose context the Sieve script runs
has permissions to execute &quot;fileinto&quot; on it.</t>
<t>Example:</t>

<artwork>require &quot;fileinto&quot;;
require &quot;mailboxid&quot;;

if header :contains [&quot;from&quot;] &quot;coyote&quot; {
    if mailboxidexists &quot;F6352ae03-b7f5-463c-896f-d8b48ee3&quot; {
        fileinto :mailboxid &quot;F6352ae03-b7f5-463c-896f-d8b48ee3&quot;
                            &quot;INBOX.name.will.not.be.used&quot;;
    } else {
        fileinto &quot;INBOX.harassment&quot;;
    }
}
</artwork>
<t>Note to implementers: this test behaves identically to the
<tt>mailboxexists</tt> test defined in <xref target="RFC5490"></xref> but operates on
mailboxids rather than mailbox names.</t>
</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
MUST NOT allow sieve to make an endrun around this protection by
creating mailboxes with the specified ID by using &quot;:create&quot; and
&quot;:mailboxid&quot; in a fileinto rule for a non-existant 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 are requested to add a capability to the sieve-extensions registry:</t>

<artwork>To: iana@iana.org
Subject: Registration of new Sieve extension

Capability name: mailboxid
Description: adds a test for checking mailbox existence by objectid,
             and new optional arguments to fileinto and :fcc which
             allow selecting the destination mailbox by objectid.
RFC number: this RFC
Contact address: The EXTRA discussion list &lt;extra@ietf.org&gt;
</artwork>
</section>

<section anchor="acknowledgements"><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 Ned Freed and Ken Murchison and Alexey Melnikov for feedback
on the EXTRA mailing list.</t>
</section>

<section anchor="changes"><name>Changes</name>
<t>(EDITOR: remove this section before publication)</t>

<section anchor="draft-ietf-sieve-mailboxid-08"><name>draft-ietf-sieve-mailboxid-08</name>

<ul>
<li>IETF110 discussion - re-add FCC-OPTS syntax, and clarify that :mailboxid
is incompatible with :specialuse to parallel the fileinto behaviour</li>
</ul>
</section>

<section anchor="draft-ietf-sieve-mailboxid-07"><name>draft-ietf-sieve-mailboxid-07</name>

<ul>
<li>Martin Duke review - remove formal section</li>
<li>Martin Duke review - wording for section 4.1 (interaction with :create)</li>
<li>Ken Murchison review - fixed :special-use to :specialuse per RFC8579</li>
</ul>
</section>

<section anchor="draft-ietf-sieve-mailboxid-06"><name>draft-ietf-sieve-mailboxid-06</name>

<ul>
<li>GENART review - fixed example to not be semantically pointless</li>
<li>GENART review - fixed !@ to @! in RFC reference mmark syntax</li>
</ul>
</section>

<section anchor="draft-ietf-sieve-mailboxid-05"><name>draft-ietf-sieve-mailboxid-05</name>

<ul>
<li>disallow :mailboxid and :special-use in the same fileinto action.</li>
</ul>
</section>

<section anchor="draft-ietf-sieve-mailboxid-04"><name>draft-ietf-sieve-mailboxid-04</name>

<ul>
<li>made RFC5490 and RFC8579 normative</li>
<li>clarified wording based on AD feedback from Barry</li>
</ul>
</section>

<section anchor="draft-ietf-sieve-mailboxid-03"><name>draft-ietf-sieve-mailboxid-03</name>

<ul>
<li>Fixed ABNF syntax error</li>
</ul>
</section>

<section anchor="draft-ietf-sieve-mailboxid-02"><name>draft-ietf-sieve-mailboxid-02</name>

<ul>
<li>removed bogus : from &quot;mailboxidexists&quot; test title</li>
<li>moved FCC to its own top-level section since it is not used
with the fileinto command.</li>
</ul>
</section>

<section anchor="draft-ietf-sieve-mailboxid-01"><name>draft-ietf-sieve-mailboxid-01</name>

<ul>
<li>fixed idnits - RFC5228 not mentioned in the abstract</li>
<li>fixed other I-D references I had missed, oops</li>
</ul>
</section>

<section anchor="draft-ietf-sieve-mailboxid-00"><name>draft-ietf-sieve-mailboxid-00</name>

<ul>
<li>Adopted into working group per adoption call on list</li>
<li>Updated references to old drafts which have since been published.</li>
<li>Fixed some typoes and simplified some language.</li>
<li>Removed stray leading colon on mailboxexists (thanks Alexey)</li>
<li>Added :fcc to the IANA registration description (thanks Alexey)</li>
<li>Mentioned that variables can be expanded (thanks Alexey)</li>
</ul>
</section>

<section anchor="draft-gondwana-sieve-mailboxid-02"><name>draft-gondwana-sieve-mailboxid-02</name>

<ul>
<li>Update document date by a couple of years!  Ooops, it got forgotten after
a WGLC which got not dissent.</li>
<li>Create xml2rfc v3 output.</li>
</ul>
</section>

<section anchor="draft-gondwana-sieve-mailboxid-01"><name>draft-gondwana-sieve-mailboxid-01</name>

<ul>
<li>Switch to :mailboxid tagged parameter value with fallback mailbox name.</li>
<li>Document interaction with &quot;mailbox&quot;.</li>
<li>Document interaction with &quot;special-use&quot;.</li>
<li>Document interaction with &quot;fcc&quot;.</li>
<li>Document security considerations around :mailboxid and :create.</li>
</ul>
</section>

<section anchor="draft-gondwana-sieve-mailboxid-00"><name>draft-gondwana-sieve-mailboxid-00</name>

<ul>
<li>Initial version.</li>
</ul>
</section>
</section>

</middle>

<back>
<references><name>Normative References</name>
<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.5228.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.4314.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.8579.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.5229.xml"/>
</references>

</back>

</rfc>
