<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?xml-stylesheet type="text/xsl" href="rfc2629.xslt"?>
<?rfc compact="yes"?>
<?rfc sortrefs="yes"?>
<?rfc rfcedstyle="yes"?>
<rfc number="5032" category="std" updates="3501">

  <front>
    <title abbrev="Search Within">WITHIN Search extension to the IMAP
    Protocol</title>

    <author fullname="Eric W. Burger" initials="E.W." role="editor"
            surname="Burger">
      <organization>BEA Systems, Inc.</organization>

      <address>
        <postal>
          <street></street>

          <city></city>

          <region></region>

          <code></code>

          <country>USA</country>
        </postal>

        <email>eric.burger@bea.com</email>

        <uri>http://www.standardstrack.com</uri>
      </address>
    </author>

    <date month="August" year="2007" />

<!-- [rfced] Please insert any keywords (beyond those that appear in
the title) for use on http://www.rfc-editor.org/rfcsearch.html. -->

<keyword>example</keyword>

    <area>Applications</area>

    <workgroup>Lemonade</workgroup>

    <abstract>
      <t>This document describes the WITHIN extension to IMAP SEARCH. IMAP
      SEARCH returns messages whose internal date is within or outside a
      specified interval. The mechanism described here, OLDER and YOUNGER,
      differs from BEFORE and SINCE in that the client specifies an interval,
      rather than a date. WITHIN is useful for persistent searches where
      either the device does not have the capacity to perform the search at
      regular intervals or the network is of limited bandwidth and thus there
      is a desire to reduce network traffic from sending repeated requests and
      redundant responses.</t>
    </abstract>
  </front>

  <middle>
    <section anchor="intro" title="Introduction" toc="default">
      <t>This extension exposes two new search keys, OLDER and YOUNGER, each
      of which takes a non-zero integer argument corresponding to a time
      interval in seconds. The server calculates the time of interest by
      subtracting the time interval the client presents from the
current date and time of the server. The server then either returns
messages older or younger than the resultant time and date, depending
on the search key used.</t>

    <section title="Conventions Used in This Document">
      <t>In examples, "C:" and "S:" indicate lines sent by the client and
      server, respectively.</t>

      <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">RFC 2119</xref>.</t>

      <t>When describing the general syntax, we omit some definitions, as <xref
      target="RFC3501">RFC 3501</xref> defines them.</t>
    </section>
    </section>

    <section title="Protocol Operation">
      <t>An IMAP4 server that supports the capability described here MUST
      return "WITHIN" as one of the server supported capabilities in the
      CAPABILITY command.</t>

      <t>For both the OLDER and YOUNGER search keys, the server calculates a
      target date and time by subtracting the interval, specified in seconds,
      from the current date and time of the server. The server then compares
      the target time with the INTERNALDATE of the message, as specified in
      <xref target="RFC3501">IMAP</xref>. For OLDER, messages match if the
      INTERNALDATE is less recent than or equal to the target time. For
      YOUNGER, messages match if the INTERNALDATE is more recent than or
      equal to the target time.</t>

      <t>Both OLDER and YOUNGER searches always result in exact matching, to
      the resolution of a second. However, if one is doing a dynamic
      evaluation, for example, in a <xref target="CONTEXT">context</xref>, one
      needs to be aware that the server might perform the evaluation periodically.
      Thus, the server may delay the updates. Clients MUST be aware that
      dynamic search results may not reflect the current state of the mailbox.
      If the client needs a search result that reflects the current state of
      the mailbox, we RECOMMEND that the client issue a new search.</t>
    </section>

    <section title="Formal Syntax">
      <t>The following syntax specification uses the Augmented Backus-Naur
      Form (ABNF) notation. Elements not defined here can be found in the
      formal syntax of <xref target="RFC4234">ABNF</xref> and <xref
      target="RFC3501">IMAP</xref>.</t>

      <t>This document extends <xref target="RFC3501">RFC 3501</xref> with two
      new search keys: OLDER &lt;interval&gt; and YOUNGER
      &lt;interval&gt;.</t>
<t></t>
      <figure>
        <artwork><![CDATA[search-key =/ ( "OLDER" / "YOUNGER" ) SP nz-number
               ; search-key defined in RFC 3501]]></artwork>
      </figure>
    </section>

    <section title="Example">
<t></t>
      <figure>
        <artwork><![CDATA[C: a1 SEARCH UNSEEN YOUNGER 259200
S: a1 * SEARCH 4 8 15 16 23 42]]></artwork>
      </figure>

      <t>Search for all unseen messages within the past 3 days, or 259200
      seconds, according to the server's current time.</t>
    </section>

    <section anchor="security" title="Security Considerations" toc="default">
      <t>The WITHIN extension does not raise any security considerations that
      are not present in the base protocol. Considerations are the same as for
      <xref target="RFC3501">IMAP</xref>.</t>
    </section>

    <section title="IANA Considerations">
      <t>Per the <xref target="RFC3501">IMAP RFC</xref>, registration of a new
      IMAP capability in the IMAP Capability registry requires the publication
      of a standards-track RFC or an IESG approved experimental RFC. The
      registry is currently located at
      &lt;http://www.iana.org/assignments/imap4-capabilities&gt;. This
      standards-track document defines the WITHIN IMAP capability.
      IANA has added this extension to the IANA IMAP Capability registry.</t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <reference anchor="RFC2119">
        <front>
          <title>Key words for use in RFCs to Indicate Requirement
          Levels</title>

          <author initials="S." surname="Bradner">
            <organization></organization>
          </author>

          <date month="March" year="1997" />
        </front>

        <seriesInfo name="RFC" value="2119" />

        <seriesInfo name="BCP" value="14" />
      </reference>

      <reference anchor="RFC3501">
        <front>
          <title>Internet Message Access Protocol - Version 4rev1</title>

          <author fullname="Mark Crispin" initials="M." surname="Crispin">
            <organization>University of Washington</organization>
          </author>

          <date month="March" year="2003" />
        </front>

        <seriesInfo name="RFC" value="3501" />
      </reference>

      <reference anchor="RFC4234">
        <front>
          <title>Augmented BNF for Syntax Specifications: ABNF</title>

          <author fullname="David Crocker" initials="D." surname="Crocker" role="editor">
            <organization></organization>
          </author>

          <author fullname="P. Overell" initials="P." surname="Overell">
            <organization></organization>
          </author>

          <date month="October" year="2005" />
        </front>

        <seriesInfo name="RFC" value="4234" />

        <format octets="33752" target="ftp://ftp.isi.edu/in-notes/rfc4234.txt"
                type="TXT" />
      </reference>
    </references>

    <references title="Informative References">
      <reference anchor="CONTEXT">
        <front>
          <title>Contexts for IMAP4</title>

          <author fullname="Dave Cridland" initials="D." surname="Melnikov">
            <organization>Isode Limited</organization>
          </author>

          <author fullname="Curtis King" initials="C." surname="King">
            <organization>Isode Limited</organization>
          </author>

          <date day="18" month="May" year="2006" />
        </front>

        <seriesInfo name="Work in"
                    value="Progress" />
      </reference>
    </references>
<?rfc needLines="100" ?>
    <section title="Contributors">
      <t>Stephane Maes and Ray Cromwell wrote the original version of this
      document as part of P-IMAP, as well as the first versions for the IETF.
      From an attribution perspective, they are clearly authors.</t>
    </section>

    <section title="Acknowledgements">
      <t>The authors want to thank all who have contributed key insight and
      who have extensively reviewed and discussed the concepts of
      LPSEARCH. They also thank the authors of its early introduction in P-IMAP.</t>

      <t>We also want to give a special thanks to Arnt Gilbrandsen, Ken
      Murchison, Zoltan Ordogh, and most especially Dave Cridland for their
      review and suggestions. A special thank you goes to Alexey Melnikov for
      his choice submission of text.</t>
    </section>
  </back>
</rfc>