<?xml version="1.0" encoding="US-ASCII"?>

<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<!-- used by XSLT processors -->
<?rfc strict="yes" ?>
<?rfc toc="yes"?>
<?rfc tocdepth="4"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes" ?>
<?rfc compact="yes" ?>
<?rfc subcompact="no" ?>

<rfc category="std" docName="draft-bosch-sieve-special-use-00" ipr="trust200902">
<!-- ***** FRONT MATTER ***** -->

<front>
<title abbrev="Sieve: Special-Use Mailboxes">
Sieve Email Filtering: Delivering to Special-Use Mailboxes
</title>

<author fullname="Stephan Bosch" initials="S." surname="Bosch">
	<organization>Dovecot Oy</organization>
  <address>
    <postal>
			<street>Lars Sonckin Kaari 16</street>
			<code>02600</code>
			<city>Espoo</city>
			<country>Finland</country>
    </postal>
    <email>stephan.bosch@dovecot.fi</email>
  </address>
</author>

<date/>

<area>General</area>
<!--<workgroup>Sieve Working Group</workgroup>-->
<keyword>sieve</keyword>
<keyword>mailbox</keyword>
<keyword>special-use</keyword>

<abstract>
<t>The SPECIAL-USE capability of the IMAP protocol (RFC 6154) allows clients to
identify special-use mailboxes; e.g., where draft or sent messages should be
put. This simplifies client configuration. 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 test for checking whether a special-use
attribute is assigned for a particular mailbox or any mailbox, and it adds the
ability to file messages into an anonymous mailbox that has a particular
special-use attribute assigned.</t>
</abstract>
</front>

<middle>

<section title="Introduction">
<t>Commonly, several mailboxes in an
<xref target="IMAP">IMAP message store</xref> have a special use; e.g.
it is where the user's draft messages are stored, where a copy of sent messages
are kept, or it is where spam messages are filed automatically at delivery. The
<xref target="SPECIAL-USE">SPECIAL-USE capability</xref> of the IMAP protocol
defines mailbox attributes that identify these special mailboxes explicitly to
the client. This way, client configuration is simplified significantly. Using
the <xref target="SPECIAL-USE">CREATE-SPECIAL-USE capability</xref>, IMAP
clients can also configure these attributes dynamically based on user
preference.</t>

<t>Unlike the IMAP protocol, the Sieve mail filtering language
<xref target="SIEVE"/> currently cannot freely access these special-use
mailbox attributes. Particularly, the Sieve interpreter cannot find an anonymous
mailbox that has a particular special-use attribute assigned. This would be very
useful for example to find the user's Spam mailbox at delivery.</t>

<t>In Sieve, limited access to the special-use attributes is provided using the
<xref target="MAILBOX">"mboxmetadata" extension</xref>, which allows
testing for the presence of a special-use attribute in the "/private/specialuse"
<xref target="IMAP-METADATA">IMAP METADATA</xref> entry of a mailbox.
Still, not all implementers will be willing to add the complexity of the IMAP
METADATA capability, just to provide access to special-use attributes to the
Sieve interpreter.</t>

<t>This document defines an extension to the Sieve mail filtering language that
adds the ability to freely access mailbox special-use attributes. It adds a test
called "specialuse_exists" that checks whether a special-use attribute is
assigned for a particular mailbox or - if omitted - any mailbox. It also adds
the ability to file messages into an anonymous mailbox that has a particular
special-use attribute assigned using a ":specialuse" argument for the
<xref target="SIEVE">"fileinto" command</xref>.</t>
</section>

<section title="Conventions Used in This Document">
<t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in <xref target="KEYWORDS"/>.</t>
<t>Conventions for notations are as in <xref target="SIEVE"/> Section 1.1,
including use of the "Usage:" label for the definition of action and tagged
arguments syntax.</t>
</section>

<section title="Test &quot;specialuse_exists&quot;">

<?rfc needLines="3" ?>
<figure>
<artwork><![CDATA[
Usage:  specialuse_exists [<mailbox: string>]
                          <special-use-flags: string-list>
]]></artwork>
</figure>

<t>If the "mailbox" string argument is omitted, the "specialuse_exists" test
yields true if all of the following statements are true for each of the
special-use flags listed in the "special-use-flags" argument:
<list style="letters">
<t>at least one mailbox exists in the mail store that has that particular
special-use flag assigned, and</t>
<t>that mailbox allows the user in whose context the Sieve script runs to
"deliver" messages into it.</t>
</list>
</t>

<t>If the "mailbox" argument is specified, the "specialuse_exists" test yields
true if all of the following statements are true:
<list style="letters">
<t>the indicated mailbox exists, </t>
<t>that mailbox allows the user in whose context the Sieve script runs
to "deliver" messages into it, and</t>
<t>that mailbox has all of the special-use flags listed in the
"special-use-flags" argument assigned to it.</t>
</list>
</t>

<t>Refer to the specification of the "mailboxexists" test in Section 3.1 of
<xref target="MAILBOX">RFC 5490</xref> for a definition of when "delivery"
of messages into a mailbox is deemed possible.</t>

</section>

<section title="&quot;:specialuse&quot; Argument to &quot;fileinto&quot; Command">

<?rfc needLines="3" ?>
<figure>
<artwork><![CDATA[
Usage:  fileinto [:specialuse <special-use-flag: string>]
                 <mailbox: string>
]]></artwork>
</figure>

<t>Normally, the "fileinto" command delivers the message in the mailbox
specified using its positional mailbox argument. However, if the optional
":specialuse" argument is also specified, the "fileinto" command first checks
whether a mailbox exists with the specified special-use flag assigned to it.
If that is the case, that special-use mailbox is used for delivery instead. If
there is no such mailbox or if the specified special-use flag is unknown to the
implementation in general, the "fileinto" action proceeds as it would without
the ":specialuse" argument.</t>

<t>Summarizing, if the ":specialuse" argument is specified, the fileinto
command deals with two mailboxes that may or may not exist:
<list style="symbols">
<t>An anonymous special-use mailbox, which has at least the special-use flag
specified with the ":specialuse" argument assigned to it.</t>
<t>The default mailbox named by the positional string argument of the
"fileinto" command, which is used when the special-use mailbox is not found.
</t>
</list>
</t>

<t>The special-use flag specified with the ":specialuse" argument MUST conform
to the "use-attr" syntax described in Section 6 of
<xref target="MAILBOX">RFC6154</xref>. Implementations SHOULD handle an invalid
special-use flag in the same way as an invalid mailbox name is handled. The
string parameter of the ":specialuse" argument is not a constant string, which
means that variable substitutions are allowed when the
<xref target="VARIABLES">"variables" extension</xref> is active. In that case,
the syntax of the special-use flag is only verified at runtime.</t>

<t>If neither the special-use mailbox nor the default mailbox exists, the 
"fileinto" action MUST proceed exactly as it does in case the ":specialuse"
is argument is absent and the mailbox named by its positional argument does
not exist. The various options for handling this situation are described in
Section 4.1 of <xref target="SIEVE">RFC5228</xref>.</t>

<t>More than one mailbox can have a particular special-use flag assigned. In
that case, the mailbox that is chosen for delivery is implementation-defined.
However, implementations MUST ensure that this choice is made consistently,
so that the same mailbox is used every time.</t>

<t>If delivery to the special-use mailbox fails for reasons not relating to its
existence, the Sieve interpreter MUST NOT subsequently attempt delivery in
the indicated default mailbox as a fall-back. Instead, it MUST proceed exactly
as it does in case the ":specialuse" argument is absent and delivery to the
mailbox named by its positional argument fails. This prevents the situation
where messages are unexpectedly spread over two mailboxes in case transient or
intermittent delivery failures occur.</t>

<section title="Interaction with &quot;:create&quot; Argument to &quot;fileinto&quot; Command">

<t>The <xref target="MAILBOX">"mailbox" extension</xref> adds the optional
":create" argument to the "fileinto" command. If the optional ":create" argument
is specified with "fileinto", it instructs the Sieve interpreter to create the
specified mailbox if needed, before attempting to deliver the message into the
specified mailbox.</t>

<t>When combined with the ":specialuse" argument, the ":create" argument
instructs the Sieve interpreter to create the specified default mailbox if
needed. This need arises when both the special-use and the default mailbox are
not found.</t>

<t>If the server implementation supports the
<xref target="SPECIAL-USE">CREATE-SPECIAL-USE capability</xref> for IMAP, i.e.
it allows assigning special-use flags to new mailboxes, it SHOULD assign the
special-use flag specified with the ":specialuse" argument to the newly created
mailbox.</t> 

</section>
</section>

<section title="Sieve Capability Strings">
<t>A Sieve implementation that defines the "specialuse_exists" test and
the ":specialuse" argument for the "fileinto" command  will advertise the
capability string "special-use".
</t>
</section>

<section title="Examples">

<t>The following example saves the message in the mailbox where messages deemed
to be junk mail are held. This mailbox is identified using the "\Junk"
special-use attribute. If no mailbox has this attribute assigned, the message
is filed into the mailbox named "Spam".</t>

<?rfc needLines="5" ?>
<figure>
<artwork><![CDATA[
require "fileinto";
require "special-use";

fileinto :specialuse "\\Junk" "Spam";
]]></artwork>
</figure>

<t>The following very similar example handles the case in which neither a
"\Junk" special-use mailbox nor the "Spam" mailbox exist. In that case, a
mailbox called "Spam" is created, and the message is stored there. Additionally,
the "\Junk" special-use attribute may be assigned to it.
</t>

<?rfc needLines="6" ?>
<figure>
<artwork><![CDATA[
require "fileinto";
require "special-use";
require "mailbox";

fileinto :specialuse "\\Junk" :create "Spam";
]]></artwork>
</figure>

<t>The following example is used in a Sieve script that is triggered from an
IMAP event, rather than at message delivery <xref target="IMAPSIEVE"/>. This
Sieve script redirects messages to an automated recipient that processes junk
mail, if those messages are copied or moved into a mailbox that has the "\Junk"
special-use attribute assigned.</t>

<?rfc needLines="15" ?>
<figure>
<artwork><![CDATA[
require "imapsieve";
require "special-use";
require "environment";
require "variables";

if environment :contains "imap.mailbox" "*" {
	set "mailbox" "${1}";
}

if allof(
	environment "imap.cause" "COPY",
	specialuse_exists "${mailbox}" "\\Junk") {
	redirect "spam-report@example.org";
}
]]></artwork>
</figure>

</section>


<section anchor="Security" title="Security Considerations">
<t>[FIXME]</t>
<t>Additional security considerations are discussed in
<xref target="SIEVE"/>.</t>
</section>

<section anchor="IANA" title="IANA Considerations">

<t>The following template specifies the IANA registration of the Sieve
extension specified in this document:</t>

<?rfc needLines="13" ?>
<figure>
<artwork><![CDATA[
   To: iana@iana.org
   Subject: Registration of new Sieve extension

   Capability name: special-use
   Description:     adds a test for checking whether an IMAP
                    special-use attribute is assigned for a
                    particular mailbox or any mailbox, and it adds
                    the ability to file messages into an anonymous
                    mailbox that has a particular IMAP special-use
                    attribute assigned.
   RFC number:      this RFC
   Contact address: Sieve mailing list <sieve@ietf.org>
]]></artwork>
</figure>

<t>This information should be added to the list of sieve extensions
given on http://www.iana.org/assignments/sieve-extensions.</t>
</section>
</middle>

<!--  *****BACK MATTER ***** -->

<back>
<!-- References split into informative and normative -->

<references title="Normative References">
  <reference anchor='KEYWORDS'>
    <front>
    <title abbrev='RFC Key Words'>Key words for use in RFCs to Indicate Requirement Levels</title>
    <author initials='S.' surname='Bradner' fullname='Scott Bradner'>
    <organization>Harvard University</organization>
    <address>
      <postal>
        <street>1350 Mass. Ave.</street>
        <street>Cambridge</street>
        <street>MA 02138</street>
      </postal>
      <phone>- +1 617 495 3864</phone>
      <email>sob@harvard.edu</email>
    </address>
    </author>
    <date year='1997' month='March' />
    <area>General</area>
    <keyword>keyword</keyword>
		</front>

    <seriesInfo name='BCP' value='14' />
    <seriesInfo name='RFC' value='2119' />
    <format type='TXT' octets='4723' target='http://www.rfc-editor.org/rfc/rfc2119.txt' />
    <format type='HTML' octets='17491' target='http://xml.resource.org/public/rfc/html/rfc2119.html' />
    <format type='XML' octets='5777' target='http://xml.resource.org/public/rfc/xml/rfc2119.xml' />
  </reference>

  <reference anchor='MAILBOX'>
    <front>
    <title>The Sieve Mail-Filtering Language -- Extensions for Checking Mailbox Status and Accessing Mailbox Metadata</title>
    <author initials='A.' surname='Melnikov' fullname='A. Melnikov'>
    <organization /></author>
    <date year='2009' month='March' />
    </front>

    <seriesInfo name='RFC' value='5490' />
    <format type='TXT' octets='16065' target='http://www.rfc-editor.org/rfc/rfc5490.txt' />
  </reference>

	<reference anchor='IMAP-METADATA' target='http://www.rfc-editor.org/info/rfc5464'>
		<front>
		<title>The IMAP METADATA Extension</title>
		<author initials='C.' surname='Daboo' fullname='C. Daboo'><organization /></author>
		<date year='2009' month='February' />
		</front>
		<seriesInfo name='RFC' value='5464'/>
		<seriesInfo name='DOI' value='10.17487/RFC5464'/>
	</reference>

  <reference anchor='SIEVE'>
    <front>
    <title>Sieve: An Email Filtering Language</title>
    <author initials='P.' surname='Guenther' fullname='P. Guenther'>
    <organization /></author>
    <author initials='T.' surname='Showalter' fullname='T. Showalter'>
    <organization /></author>
    <date year='2008' month='January' />
    </front>
    <seriesInfo name='RFC' value='5228' />
    <format type='TXT' octets='87531' target='http://www.rfc-editor.org/rfc/rfc5228.txt' />
  </reference>

	<reference anchor='SPECIAL-USE' target='http://www.rfc-editor.org/info/rfc6154'>
		<front>
		<title>IMAP LIST Extension for Special-Use Mailboxes</title>
		<author initials='B.' surname='Leiba' fullname='B. Leiba'><organization /></author>
		<author initials='J.' surname='Nicolson' fullname='J. Nicolson'><organization /></author>
		<date year='2011' month='March' />
		</front>
		<seriesInfo name='RFC' value='6154'/>
		<seriesInfo name='DOI' value='10.17487/RFC6154'/>
	</reference>  

  <reference anchor='VARIABLES'>
    <front>
    <title>Sieve Email Filtering: Variables Extension</title>
    <author initials='K.' surname='Homme' fullname='K. Homme'>
    <organization /></author>
    <date year='2008' month='January' />
    </front>
    <seriesInfo name='RFC' value='5229' />
    <format type='TXT' octets='20023' target='http://www.rfc-editor.org/rfc/rfc5229.txt' />
  </reference>

</references>

<references title="Informative References">

	<reference anchor='IMAP' target='http://www.rfc-editor.org/info/rfc3501'>
		<front>
		<title>INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1</title>
		<author initials='M.' surname='Crispin' fullname='M. Crispin'><organization /></author>
		<date year='2003' month='March' />
		</front>
		<seriesInfo name='RFC' value='3501'/>
		<seriesInfo name='DOI' value='10.17487/RFC3501'/>
	</reference>

	<reference  anchor='IMAPSIEVE' target='http://www.rfc-editor.org/info/rfc6785'>
		<front>
		<title>Support for Internet Message Access Protocol (IMAP) Events in Sieve</title>
		<author initials='B.' surname='Leiba' fullname='B. Leiba'><organization /></author>
		<date year='2012' month='November' />
		</front>
		<seriesInfo name='RFC' value='6785'/>
		<seriesInfo name='DOI' value='10.17487/RFC6785'/>
	</reference>

</references>
</back>

</rfc>
