<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<rfc ipr="full3978" docName="draft-freed-sieve-ihave-03" category="std">
<?rfc toc="no" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc comments="yes" ?>
	
<front>

<title abbrev="Sieve Ihave Extension">
Sieve Email Filtering: 
Ihave Extension
</title>
<author initials="N." surname="Freed" fullname="Ned Freed">
<organization>Sun Microsystems</organization>
<address>
<postal>
<street>800 Royal Oaks</street>
<city>Monrovia</city> <region>CA</region>  <code>91016-6347</code>
<country>USA</country>
</postal>
<phone>+1 909 457 4293</phone>
<email>ned.freed@mrochek.com</email>
</address>
</author>
<date year="2008" />
<area>Applications</area>
<keyword>RFC</keyword>
<keyword>Request for Comments</keyword>
<keyword>SMTP</keyword>
<keyword>ESMTP</keyword>
<keyword>Sieve</keyword>
<keyword>I-D</keyword>
<keyword>Internet-Draft</keyword>

<abstract><t>
This document describes the "ihave" extension to the Sieve
email filtering language. The "ihave" extension provides a means to write scripts
that can take advantage of optional Sieve features but can still run when those
optional features are not available. The extension also defines a new error
control command intended to be used to report situations where no combination
of available extensions satisfies the needs of the script.
</t></abstract>

<note title='Change History (to be removed prior to publication as an RFC)'>
<t>
Changed the comparator used in the ihave test from "i;ascii-casemap" to
"i;octet".
</t>
<t>
Updated the IANA registration template.
</t>
<t>
Simplified the semantics of ihave to be independent of block structure.
</t>
<t>
Moved the environment extension to a separate document so the standards
status of the two extensions can be different.
</t>
<t>
Added error action.
</t>
<t>
Added some text to make the portability advantages of ihave clearer.
</t>
<t>
Added a note about the possibility that the argument to error uses UTF-8
characters.
</t>
<t>
(from WGLC) Various editorial fixups.
</t>
<t>
(from WGLC) Incorporated the same short-circuit,
left to right requirements the variables extension imposes, because without
it invocation of the variables extension could potentially change the meaning of ihave
constructs in anyof or allof clauses.
</t>
<t>
(from WGLC) Added a resriction that ihave MUST NOT be used with any extension that
changes the underlying Sieve grammar. Hopefully there won't be any such extensions,
but better safe than sorry.
</t>

</note>

</front>

<middle>

<section anchor="intro" title="Introduction">

<t>
Sieve <xref target='RFC5228' /> is a language for filtering email
messages at or around the time of final delivery.  It is designed to be
implementable on either a mail client or mail server. It is suitable for
running on a mail server where users may not be allowed to execute arbitrary
programs, such as on black box Internet Message Access Protocol
<xref target="RFC3501" />
servers, as it has no user-controlled loops or the ability to run external
programs.
</t>

<t>
Various sieve extensions have already been defined, e.g.,
<xref target="RFC5229"/> <xref target="RFC5230"/>
<xref target="RFC5231"/> <xref target="RFC5232"/>
<xref target="RFC5233"/> <xref target="RFC5235"/>,
and many more are sure to be created over time. Sieve's require clause is used
to specify the extensions a particular sieve needs; an error results if the script's
require clause calls for an extension that isn't available. This mechanism
is sufficient in most situations. However, there can be cases where a script
may be able to take advantage of an extension if it is available but can
still operate if it is not, possibly with some degradation of functionality.
Cases can also arise where a script would prefer one extension but can
employ a different one if the first one is not available.
</t>

<t>
The "ihave" extension provides a means to write scripts that make use of
extensions only when they are actually available. Ihave defines a new ihave test
that takes a list of capability names as an argument and succeeds if and only if
all of those capabilities are present. Additionally, specification of the
"ihave" extension in the require clause disables parse time checking of extension
use in scripts; run-time checking must be used instead. This makes it possible to
write portable scripts that can operate in multiple environments making
effective use of whatever extensions are available even though differing sets
of extensions are provided in different places.
</t>

<t>
The "ihave" extension also defines a new error control command. Error
causes script execution to terminate with the error message given as the
argument to the error control.
</t>

</section>

<section anchor="conventions" 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='RFC2119' />.
</t>

<t>
The terms used to describe the various components of the Sieve
language are taken from Section 1.1 of <xref target='RFC5228' />.
</t>

</section>

<section title='Capability Identifiers'>

<t>
The capability string associated with the extension defined in this
document is "ihave".
</t>

</section>

<section anchor="ihave" title="Ihave Test">

<figure><artwork><![CDATA[
Usage:   ihave <capabilities: string-list>
]]></artwork></figure>

<t>
The ihave test provides a means for Sieve scripts to test for the
existence of a given extension prior to actually using it. The
capabilities argument to ihave is the same as the similarly-named
argument to the require control statement: It specifies the names
of one or more Sieve extensions or comparators. The ihave test
succeeds if all the extensions specified in the capabilities list are
available to the script.
</t>

<t>
Unlike most Sieve tests, ihave accepts no match or comparator arguments.
The type of match for ihave is always  ":is" and the comparator is always
"i;octet".
</t>

<t>
The strings in the capabilities list are constant strings in the context of Sieve
variables <xref target='RFC5229' />. It is an error
to pass a non-constant string as an argument to ihave.
</t>

<t>
The Sieve base specification demands that all Sieve extensions used
in a given script be specified in the initial require control statement.
It is an error for a script to call for extensions the interpreter doesn't
support or to attempt to use extensions that have not been listed
in the script's require clause. Using ihave changes Sieve
interpreter behavior and the underlying requirements in
the following ways:
</t>

<t>

<list style='numbers'>

<t>
Use of a given extension is allowed subsequent to the successful evaluation
of an ihave test on that extension all the way to the end of the script,
even outside the block enclosed by the ihave test. In other words,
subsequent to a successful ihave things operate just as if the extension had
been specified in the script's require clause. The extension cannot
be used prior to the evaluation of such a test and a runtime error MUST be
generated if such usage is attempted. However, subsequent use of that extension
may still need to be conditionally handled via an ihave test to deal with the
case where it is not supported. The extension cannot be used prior to the
evaluation of such a test and a runtime error MUST be generated if such usage
is attempted.
</t>

<t>
Sieve interpreters normally have the option of checking extension
use at either parse time or execution time. The specification of
"ihave" in a script's require clause changes this behavior: Scripts
MUST either defer extension checking to run time or else take
the presence of ihave tests into account at parse time. Note that since
ihave can be used inside of anyof, allof, and not tests full parse time
checking of ihave may be very difficult to implement.
</t>

<t>
Although it makes little sense to do so, an extension can be specified
in both the require control statement and in an ihave test. If this
is done and the extension has been implemented the extension can be used
anywhere in the script and an ihave test of that extension will always return true.
</t>

<t>
Ihave accepts a list of capabilities. The ihave test fails and none of the
capabilities are enabled if any of the specified capabilities are unavailable.
</t>

<t>
The Sieve base specification does not require that interpreters evaluate
arguments in any particular order or that test evaluation be short-circuited.
If ihave is enabled the interpreter MUST short-circuit tests, i.e., not
perform more tests than necessary to find the result. Additionally, evaluation
order MUST be left to right if ihave is enabled.
</t>

</list>

</t>

<t>
Ihave is designed to be used with extensions that add tests, actions,
comparators, or arguments. It MUST NOT be used with extensions that change
the underlying Sieve grammer or extensions like variables <xref target='RFC5229' />
that change how the content of Sieve scripts are interpreted.
</t>

</section>

<section anchor="error" title="Error Control">

<figure><artwork><![CDATA[
Usage:   error <message: string>
]]></artwork></figure>

<t>
The error control causes script execution to terminate with a run-time
error. The message argument provides a text description of the error
condition that SHOULD be included in any generated report regarding the error.
Section 2.10.6 of <xref target='RFC5228' />
describes how run-time errors are handled in Sieve.
</t>

<t>
Note that the message argument, like all Sieve strings, employs the UTF-8
charset and can contain non-US-ASCII characters. This must be taken into
consideration when reporting script errors.
</t>

<t>
The error control is included as part of the ihave extension so that
it is unconditionally available to scripts using ihave.
</t>

</section>

<section anchor="security" title="Security Considerations">

<t>
A potential security issue with Sieve scripts is that when a script fails
to run due to the lack of some extension it may fail to block dangerous
email. The ihave extension makes it possible to improve script portability and
generality, which may improve the overall security provided by Sieve.
</t>

<t>
Script robustness aside, ihave is essentially a more flexible variant of Sieve's
existing require mechanism. As such, it does not add any additional capabilities
to a Sieve implementation that could create security issues.
Of course all of the security considerations given in the base Sieve
specification and in any extensions that are employed are still relevant.
</t>

</section>

<section anchor="IANA" title="IANA Considerations">

<figure>
<preamble>
The following template specifies the IANA registration of the Sieve
extension specified in this document:
</preamble>
<artwork>
   To: iana@iana.org
   Subject: Registration of new Sieve extension

   Capability name: ihave
   Description:     The "ihave" extension provides a means to write
                    scripts that make use of other extensions only
                    when they are actually available. 
   RFC number:      RFC &rfc.number;
   Contact address: Sieve discussion list &lt;ietf-mta-filters@imc.org&gt;
   </artwork>
</figure>
</section>

</middle>

<back>

<references title="Normative references">

<?rfc include="reference.RFC.2119" ?>
<?rfc include="reference.RFC.5228" ?>

</references>

<references title="Informative references">

<?rfc include="reference.RFC.3501" ?>
<?rfc include="reference.RFC.5229" ?>
<?rfc include="reference.RFC.5230" ?>
<?rfc include="reference.RFC.5231" ?>
<?rfc include="reference.RFC.5232" ?>
<?rfc include="reference.RFC.5233" ?>
<?rfc include="reference.RFC.5235" ?>

</references>

<section title='Acknowledgements'>

<t>
Stephan Bosch, Cyrus Daboo, Arnt Gulbrandsen, Andrew McKeon, and Alexey Melnikov provided
helpful suggestions and corrections.
</t>

</section>

</back>

</rfc>
