<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' []>
<rfc ipr="trust200902" category="std" docName="draft-gondwana-sieve-mailboxid-01" updates="5228">
<?rfc toc="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc private=""?>
<?rfc topblock="yes"?>
<?rfc comments="no"?>
<front>
<title abbrev="Sieve MAILBOXID">Sieve Email Filtering: delivery by mailboxid</title>

<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>
<region></region>
</postal>
<phone></phone>
<email>brong@fastmailteam.com</email>
<uri>https://www.fastmail.com</uri>
</address>
</author>
<date year="2018" month="August" day="11"/>

<area>Applications</area>
<workgroup>EXTRA</workgroup>
<keyword>sieve</keyword>
<keyword>email</keyword>


<abstract>
<t>The OBJECTID capability of the IMAP protocol (I-D.ietf-extra-imap-objectid)
allows clients to identify mailboxes by a unique identifier which survives
rename. In contrast, the Sieve mail filtering language (RFC 5228) currently
has no such capability.  This memo defines a Sieve extension that fills
this gap: it adds a method for specifying the unique identifier of a mailbox
as a target for fileinto rules, and a method for testing the existence of
a mailbox by its unique identifier.
</t>
</abstract>


</front>

<middle>

<section anchor="introduction" title="Introduction">
<t>Sieve rules are sometimes created using graphical interfaces which
allow users to select the mailbox to be used as a target for a rule.
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 extending <spanx style="verb">fileinto</spanx> to reference an immutable mailboxid, sieve rules
can continue to target the same mailbox, regardless of how it gets
renamed.
</t>
</section>

<section anchor="conventions-used-in-this-document" title="Conventions Used In This Document">
<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 target="RFC8174"/> when, and only when,
they appear in all capitals, as shown here.
</t>
</section>

<section anchor="sieve-capability-string" title="Sieve capability string">
<t>The server advertises the capability &quot;mailboxid&quot;, and scripts which use
the following extensions MUST explicitly request the capability &quot;mailboxid&quot;.
</t>
<t>Example:
</t>

<figure align="center"><artwork align="center">
require "mailboxid";
</artwork></figure>
</section>

<section anchor="argument-mailboxid-to-command-fileinto" title="Argument &quot;:mailboxid&quot; to Command &quot;fileinto&quot;">
<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"/> with the specified <xref target="I-D.ietf-extra-imap-objectid"/>
MAILBOXID.  If that is the case, that mailbox is used for delivery instead.
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 <spanx style="verb">:mailboxid</spanx> to fileinto consumes one additional token,
a string with the objectid of the mailbox to file into.
</t>
<t>Example:
</t>

<figure align="center"><artwork align="center">
require "fileinto";
require "mailboxid";

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

<section anchor="interaction-with-mailbox-extension" title="Interaction with &quot;mailbox&quot; extension">
<t>For servers which also support the <xref target="RFC5490"/> mailbox extension, the &quot;:create&quot;
modifier to fileinto does not create mailbox with the specified mailboxid,
however it may be specified and interacts as normal with all other extensions.
</t>
<t>Example:
</t>

<figure align="center"><artwork align="center">
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.
</artwork></figure>
</section>

<section anchor="interaction-with-specialuse-extension" title="Interaction with &quot;specialuse&quot; extension">
<t>For servers which also support <xref target="I-D.ietf-extra-sieve-special-use"/>, if a
fileinto command has both &quot;:mailboxid&quot; and &quot;:special-use&quot; specified, then
the mailboxid is resolved first.  If the mailboxid does not exist, then
the special-use is evaluated next following the process specified in
<xref target="I-D.ietf-extra-sieve-special-use"/> - this includes processing of <xref target="RFC5490"/>
&quot;:create&quot; tags to add the special-use on creation.
</t>
<t>Example:
</t>

<figure align="center"><artwork align="center">
require "fileinto";
require "mailboxid";
require "special-use";
if header :contains ["from"] "coyote" {
    fileinto :mailboxid "F6352ae03-b7f5-463c-896f-d8b48ee3"
             :specialuse "\\Junk"
             "INBOX.harassment";
}
</artwork></figure>
<t>Example:
</t>

<figure align="center"><artwork align="center">
require "fileinto";
require "mailboxid";
require "mailbox";
require "special-use";

fileinto :mailboxid "F1234567"
         :specialuse "\\Archive"
         :create
         "INBOX.Archive";
            # creates INBOX.Archive with use \Archive but
            # with a different mailboxid.
</artwork></figure>
</section>

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

<figure align="center"><artwork align="center">
FCC =/ [":mailboxid" &lt;mailboxid: string&gt;]
</artwork></figure>
<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>Example:
</t>

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

<section anchor="test-mailboxidexists" title="Test &quot;:mailboxidexists&quot;">
<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"/>), if IMAP Access Control List (ACL)
   <xref target="RFC4314"/> 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"/>).
</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; 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>

<figure align="center"><artwork align="center">
require "fileinto";
require "mailboxid";

if header :contains ["from"] "coyote" {
    if mailboxidexists "F6352ae03-b7f5-463c-896f-d8b48ee3" {
        fileinto :mailboxid "F6352ae03-b7f5-463c-896f-d8b48ee3"
                            "INBOX.harassment";
    } else {
        fileinto "INBOX.harassment";
    }
}
</artwork></figure>
<t>Not to implementers: this test behaves identically to the
<spanx style="verb">mailboxexists</spanx> test defined in <xref target="RFC5490"/> but operates on
mailboxids rather than mailbox names.
</t>
</section>

<section anchor="formal-syntax" title="Formal Syntax">

<figure align="center"><artwork align="center">
test /= ":mailboxidexists" string-list

tag /= ":mailboxid" string
</artwork></figure>
<t>If <xref target="I-D.ietf-extra-sieve-fcc"/> is supported:
</t>

<figure align="center"><artwork align="center">
FCC =/ [":mailboxid" &lt;mailboxid: string&gt;]
</artwork></figure>
</section>

<section anchor="security-considerations" title="Security considerations">
<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 those documents in <xref target="RFC5228"/>, <xref target="I-D.ietf-extra-imap-objectid"/>.
</t>
</section>

<section anchor="iana-considerations" title="IANA considerations">
<t>IANA are requested to add a capability to the sieve-extensions registry:
</t>

<figure align="center"><artwork align="center">
To: iana@iana.org
Subject: Registration of new Sieve extension

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

<section anchor="acknowledgements" title="Acknowledgements">
<t>This document borrows heavily from <xref target="RFC5490"/> for the matching
mailboxexists test, and from <xref target="I-D.ietf-extra-sieve-special-use"/>
for an example of modifying the fileinto command.
</t>
<t>Thanks to Ned Freed and Ken Murchison for feedback on the EXTRA
mailing list.
</t>
</section>

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

<section anchor="draftgondwanasievemailboxid01" title="draft-gondwana-sieve-mailboxid-01">
<t>
<list style="symbols">
<t>Switch to :mailboxid tagged parameter value with fallback mailbox name.</t>
<t>Document interation with special-use.</t>
<t>Document security considerations around :mailboxid and :create.</t>
</list>
</t>
</section>

<section anchor="draftgondwanasievemailboxid00" title="draft-gondwana-sieve-mailboxid-00">
<t>
<list style="symbols">
<t>Initial version.</t>
</list>
</t>
</section>
</section>

<section anchor="todo" title="TODO">
<t>Is there a more explicit way to update the grammar?  It seems less
fully specified than IMAP.
</t>
</section>

</middle>
<back>
<references title="Normative References">
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.ietf-extra-imap-objectid.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.2342.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.5228.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"?>
</references>
<references title="Informative References">
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.ietf-extra-sieve-fcc.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml3/reference.I-D.ietf-extra-sieve-special-use.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.3501.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.4314.xml"?>
<?rfc include="https://xml2rfc.tools.ietf.org/public/rfc/bibxml/reference.RFC.5490.xml"?>
</references>

</back>
</rfc>
