<?xml version="1.0" encoding="us-ascii"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
        <!ENTITY rfc2119 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
        <!ENTITY rfc3501 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3501.xml'>
        <!ENTITY rfc3502 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3502.xml'>
        <!ENTITY rfc3516 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3516.xml'>
        <!ENTITY rfc4466 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4466.xml'>
        <!ENTITY rfc4469 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4469.xml'>
]>

<!--///The IPR might need sorting out-->

<rfc category="std" ipr="pre5378Trust200902" docName="draft-melnikov-rfc2088bis-03.txt"
	 obsoletes="2088">
	<?xml-stylesheet href="rfc5162_files/rfc2629.htm" type="text/xsl"?>
        <?rfc strict="yes" ?>
        <?rfc toc="yes" ?>
	<?rfc symrefs="yes" ?>
	<?rfc sortrefs="yes"?>
	<?rfc iprnotified="no" ?>
	<?rfc strict="yes" ?>
	<?rfc comments="yes" ?>
	<?rfc inline="yes" ?>
	<?rfc compact="yes"?>
	<?rfc subcompact="no"?>
	<front>
		<title>IMAP4 non-synchronizing literals</title>

    <author initials="J. G." surname="Myers" fullname="John G. Myers">
      <address>        
<!--///This is likely wrong now-->        
        <email>jgm+@cmu.edu</email>
      </address>
    </author>
    
    <author initials="A." surname="Melnikov" fullname="Alexey Melnikov" role="editor">
			<organization>Isode Ltd</organization>
			<address>
				<postal>
					<street>5 Castle Business Village</street>
					<street>36 Station Road</street>
					<city>Hampton</city>
					<region>Middlesex</region>
					<code>TW12 2BX</code>
					<country>UK</country>
				</postal>
				<email>Alexey.Melnikov@isode.com</email>
			</address>
		</author>
		<date year="2015"/>
    
    <keyword>IMAP</keyword>
    <keyword>LITERAL+</keyword>
    <keyword>LITERAL-</keyword>
    <keyword>APPENDLIMIT</keyword>

    <abstract>
			<t>
        The Internet Message Access Protocol (RFC 3501) contains the "literal"
        syntactic construct for communicating strings.  When sending a
        literal from client to server, IMAP requires the client to wait for
        the server to send a command continuation request between sending the
        octet count and the string data.  This document specifies an
        alternate form of literal which does not require this network round
        trip.
      </t>

      <t>This document specifies 2 IMAP extensions: LITERAL+ and LITERAL-.
      The former allows the alternate form of literals in all IMAP command.
      The latter is the same as LITERAL+, but disallow the alternate form in
      IMAP APPEND.</t>
		</abstract>
	
	</front>
  
	<middle>
		
		<section title="Specification">

      <t>
      The non-synchronizing literal is added an alternate form of literal,
      and may appear in communication from client to server instead of the
      IMAP <xref target="RFC3501"/> form of literal.  The IMAP form of literal,
      used in communication from client to server, is referred to as a
      synchronizing literal.
      The non-synchronizing literal form MUST NOT be sent from server to client.
      </t>

      <t>
      Non-synchronizing literals may be used with any IMAP server
      implementation which returns "LITERAL+" or "LITERAL-" as one of the supported
      capabilities to the CAPABILITY command.  If the server does not
      advertise either of the above capabilities, the client must use synchronizing
      literals instead. The difference between "LITERAL+" and "LITERAL-" extensions
      is explained in <xref target="literal-"/>.
      </t>

      <t>
      The non-synchronizing literal is distinguished from the original
      synchronizing literal by having a plus ('+') between the octet count
      and the closing brace ('}').  The server does not generate a command
      continuation request in response to a non-synchronizing literal, and
      clients are not required to wait before sending the octets of a non-
      synchronizing literal.
      </t>

      <t>
      The protocol receiver of an IMAP server must check the end of every
      received line for an open brace ('{') followed by an octet count, a
      plus ('+'), and a close brace ('}') immediately preceeding the CRLF.
      If it finds this sequence, it is the octet count of a non-
      synchronizing literal and the server MUST treat the specified number
      of following octets and the following line as part of the same
      command.  A server MAY still process commands and reject errors on a
      line-by-line basis, as long as it checks for non-synchronizing
      literals at the end of each line.
      </t>

      <t>
      Example:
      </t>
      
<figure>
<artwork>
C: A001 LOGIN {11+}
C: FRED FOOBAR {7+}
C: fat man
S: A001 OK LOGIN completed
</artwork>
</figure>

		</section>

    
	  <section title="Requirements Notation">
    
			<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>In examples, "C:" and "S:" indicate lines sent by
			the client and server respectively. If a single "C:" or "S:"
			label applies to multiple lines, then the line breaks between
			those lines are for editorial clarity only and are not part
			of the actual protocol exchange.</t>
		
		</section>

		<section title="Considerations on when to use and not to use synchronizing literals">

      <t>This section is important to understand for both client and server developers
      of this IMAP extension.</t>
      
			<t>
      While non-synchronizing literals have clear advantages for clients, such as simplicity of use,
      they might be more difficilt to handle on the server side. When a non synchronizing literal
      is used by a client which is too big for the server to accept, a compliant LITERAL+ server
      implementation has to make a choice between several non optimal choices:
      
      <list style="numbers">
        
        <t>Read the number of bytes specified in the non synchronizing literal and reject
        the command that included the literal anyway. (The server is allowed to send the tagged
        BAD/NO response before reading the whole non synchronizing literal.) This is quite wasteful
        on bandwidth if the literal size is big.</t>

        <t>Send the untagged BYE response explaining the reason for rejecting the literal
        and close the connection. This will force the client to reconnect or report the error to the user.
        In the latter case the error is unlikely to be understandable to the user.
        Additionally, some naive clients are known to blindly reconnect in this case and
        repeat the operation that caused the problem.
        <cref>Possibly also send the ALERT response code?</cref>
        </t>

<!--////Possible have a delay reading anything/responding to the command in addition to eating the literal?-->
        
      </list>
        
			</t>

      <t>The situation can be improved by implementing support for the APPENDLIMIT extension <xref target="I-D.jayantheesh-imap-appendlimit-extension"/>,
      which allows a server to advertise its APPEND limit, so that well behaved clients can check it and avoid uploading big messages in the first place.
      </t>

      <t>The problem described above is most common when using the APPEND command, because most of commands
      don't need to send lots of data from the client to the server. Some server implementations impose limits
      on literal (both synchronizing and non synchronizing) accepted from clients in order to protect from
      Denial Of Service attacks. Implementations can generally impose much lower limits on literal sizes for
      all commands other than APPEND.
      In order to address literal size issue in APPEND, this document introduces a new extension "LITERAL-",
      described in <xref target="literal-"/>.</t>

		</section>

		<section title="LITERAL- capability" anchor="literal-">

      <t>"LITERAL-" extension is almost identical to "LITERAL+", with one exception:
      when "LITERAL-" is advertised, non synchronizing literals used in APPEND
      (and extensions to APPEND such as MULTIAPPEND <xref target="RFC3502"/> and CATENATE <xref target="RFC4469"/>)
      MUST NOT be bigger than 4096 bytes. When any literal used in APPEND is larger than 4096, RFC 3501 synchronizing
      literals MUST be used instead.
      A "LITERAL-" compliant server which encounters a non synchronizing literal in APPEND larget than 4096 bytes MUST reject
      such APPEND command with a tagged BAD response.
      </t>
      
      <t>Because "LITERAL-" is a more restricted version of "LITERAL+", IMAP servers MUST NOT advertise both
      of these capabilities at the same time. (A server implementation can choose to have a configuration option to pick which one to advertise.)</t>
      
    </section>

    <section title="Interaction with BINARY extension">

      <t>
       RFC 4466 <xref target="RFC4466"/> updated the non-terminal "literal8" defined in <xref target="RFC3516"/>
       to allow for non-synchronizing literals if both <xref target="RFC3516"/> and
       "LITERAL+" (or "LITERAL-") extensions are supported by the server.
      </t>

    </section>


    <section title="Formal Syntax">
			<t>
			The following syntax specification uses the Augmented Backus-Naur 
			Form (ABNF) notation as specified in <xref target="ABNF"/>.
			</t>
      
			<t>
			Non-terminals referenced but not defined below are as defined by 
			<xref target="RFC3501"/>.
			</t>

<!--Not needed below:
			<t>
			Except as noted otherwise, all alphabetic characters are case-insensitive.  
			The use of upper or lower case characters to define token strings is for 
			editorial clarity only.  Implementations MUST accept these strings in a 
			case-insensitive fashion.
			</t>
-->

<!--
From RFC 4466:
   In addition, the non-terminal "literal8" defined in [BINARY] got
   extended to allow for non-synchronizing literals if both [BINARY] and
   [LITERAL+] extensions are supported by the server.
   
   literal8        = "~{" number ["+"] "}" CRLF *OCTET
                      ;; A string that might contain NULs.
                      ;; <number> represents the number of OCTETs
                      ;; in the response string.
                      ;; The "+" is only allowed when both LITERAL+ and
                      ;; BINARY extensions are supported by the server.
-->
     
<figure>
<artwork>
  literal = "{" number ["+"] "}" CRLF *CHAR8
             ; Number represents the number of CHAR8 octets

  CHAR8   = &lt;defined in RFC 3501&gt;
  
  literal8 = &lt;defined in RFC 4466&gt;
</artwork>
</figure>

		</section>
    
		<section title="Security Considerations">
      
			<t>This document doesn't raise any new security concerns not already raised
      by <xref target="RFC3501"/>.</t>

<!--///A new avenue for DoS attacks?-->      
      
		</section>
		
		<section title="IANA Considerations">
		    <t>
		    IMAP4 capabilities are registered by publishing a standards track or
		    IESG approved experimental RFC.  The registry is currently located
		    at:
		    </t>

<figure>
    <artwork>
   http://www.iana.org/assignments/imap-capabilities
    </artwork>
</figure>

		    <t>
		    This document requests that IANA updated the above registry
        to include the entry for LITERAL+ capability pointing to this document.
		    </t>
      
		    <t>
		    This document also requests that IANA adds "LITERAL-" capability
        pointing to this document to the above registry.
		    </t>
		</section>

    <section title="To Do">

      <t>
      Reference draft-jayantheesh-imap-appendlimit-extension which allows advertising limits for the APPEND command.
      </t>

    </section>
    
    <section title="Acknowledgments">

      <t>TBD</t>

<!--      
			<t>
			Valuable comments, both in agreement and in dissent, were received from
			Timo Sirainen, Dave Cridland.
			</t>
-->      

		</section>
	</middle>
	<back>
		<references title="Normative References">

      <reference anchor="ABNF">
<front>
<title>Augmented BNF for Syntax Specifications: ABNF</title>
<author initials="D." surname="Crocker" fullname="D. Crocker">
<organization/></author>
<author initials="P." surname="Overell" fullname="P. Overell">
<organization/></author>
<date year="2008" month="January"/>
<abstract>
<t>Internet technical specifications often need to define a formal syntax.  Over the years, a modified version of Backus-Naur Form (BNF), called Augmented BNF (ABNF), has been popular among many Internet specifications.  The current specification documents ABNF.  It balances compactness and simplicity with reasonable representational power.  The differences between standard BNF and ABNF involve naming rules, repetition, alternatives, order-independence, and value ranges.  This specification also supplies additional rule definitions and encoding for a core lexical analyzer of the type common to several Internet specifications. [STANDARDS TRACK]</t></abstract></front>

<seriesInfo name="STD" value="68"/>

<seriesInfo name="RFC" value="5234"/>
<format type="TXT" octets="26359" target="ftp://ftp.isi.edu/in-notes/rfc5234.txt"/>
			</reference>

      &rfc2119;
      &rfc3501;
      &rfc3516;
      &rfc4466;
    
		</references>

		<references title="Informative References">

      &rfc3502;
      &rfc4469;

      <reference anchor="I-D.jayantheesh-imap-appendlimit-extension">
        <front>
          <title>The IMAP APPENDLIMIT Extension</title>
          <author initials="N" surname="Bisht" fullname="Narendra Bisht">
            <organization/>
          </author>
          <date month="February" day="27" year="2015"/>
          <abstract>
            <t>
              This memo defines an extension to the IMAP service whereby a server can advertise its capability, to support maximum mail upload size using CAPABILITY, SELECT/EXAMINE and LIST command.
            </t>
          </abstract>
        </front>
        <seriesInfo name="Internet-Draft" value="draft-jayantheesh-imap-appendlimit-extension-04"/>
        <format type="TXT" target="http://www.ietf.org/internet-drafts/draft-jayantheesh-imap-appendlimit-extension-04.txt"/>
      </reference>


    </references>

    <section title="Changes since RFC 2088">

      <t>
      Added IANA registration.
      </t>

      <t>
      Updated references. Also updated considerations about interactions of IMAP extensions.
      </t>

      <t>
      Additional implementation considerations based on the IMAP mailing list discussions.
      </t>
      
      <t>LITERAL- capability description.</t>

    </section>


  </back>
</rfc>