<?xml version="1.0"?>
<rfc ipr="trust200902" docName="draft-ietf-imapmove-command-02"
     category="std">
<?rfc toc="no" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?> 
<?rfc subcompact="no"?>

<!--
   RFC Editor: If this document contains no code components when you
   receive it, then please remove the sentence which starts with "code
   components". Thank you.
-->

<front>

<title abbrev="IMAP Move">
The IMAP Move Extension
</title>

<author initials="A." surname="Gulbrandsen" fullname="Arnt Gulbrandsen">
  <organization/>
  <address>
    <postal>
      <street>Schweppermannstr. 8</street>
      <city>D-81671 Muenchen</city>
      <country>Germany</country>
    </postal>
    <facsimile>+49 89 4502 9758</facsimile>
    <email>arnt@gulbrandsen.priv.no</email>
  </address>
</author>

<author initials="N." surname="Freed" fullname="Ned Freed (editor)">
  <organization>Oracle</organization>
  <address>
    <postal>
      <street>800 Royal Oaks</street>
      <city>Monrovia</city> <region>CA</region>  <code>91016-6347</code>
      <country>USA</country>
    </postal>
    <email>ned+ietf@mrochek.com</email>
  </address>
</author>

<date year="2012" />
<area>Applications</area>
<keyword>RFC</keyword>
<keyword>Request for Comments</keyword>
<keyword>IMAP</keyword>
<keyword>I-D</keyword>
<keyword>Internet-Draft</keyword>

<abstract>
<t>
This document defines an IMAP extension consisting of two new commands, MOVE
and UID MOVE, that are used to move messages from one mailbox to another.
</t>
</abstract>

</front>

<middle>

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

<t>
This document defines an IMAP <xref target="RFC3501"/> extension to facilitate
moving messages from one mailbox to another. This is accomplished by defining
a new MOVE command and extending the UID command to allow
UID MOVE.
</t>

<t>
A move function is not provided in the base IMAP specification, so clients have
instead had to use a combination of the UID STORE, UID COPY and EXPUNGE commands to
perform this very common operation. This has meant needing to cope with partial
failures and side effects that can occur when multiple commands are involved.
</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>
Formal syntax is specified using ABNF <xref target="RFC5234"/>.
</t>

<t>
Example lines prefaced by "C:" are sent by the client and ones
prefaced by "S:" by the server.
</t>

</section>

<section anchor="MOVEandUIDMOVE" title="MOVE and UID MOVE">

<section anchor="MOVE" title="MOVE Command">

<figure>
<artwork>
Arguments: sequence set

    mailbox name

Responses: no specific responses for this command

Result: OK - move completed

        NO - move error: can't move those messages or to that name

        BAD - command unknown or arguments invalid
</artwork>
</figure>

</section>

<section anchor="UIDMOVE" title="UID MOVE Command">

<t>
This extends the first form of the UID command (see <xref target="RFC3501"/>,
Section 6.4.8) to add the MOVE command, defined above, as a valid argument.
</t>

</section>

<section anchor="HowTheyWork" title="Semantics of MOVE and UID MOVE">

<t>
The MOVE command takes two arguments: a message set (sequence
numbers for MOVE, UIDs for UID MOVE) and a named mailbox. Each
message included in the set is moved, rather than copied, from
the selected (source) mailbox to the named (target) mailbox.
</t>

<t>
This means that a new message is created in the target mailbox,
with a new UID, the original message is removed from the source
mailbox, and it appears to the client as a single action. This
has the same effect for each message as this sequence:
</t>

<t>
<list style="numbers">

<t>
[UID] COPY
</t>

<t>
[UID] STORE +FLAGS.SILENT \DELETED
</t>

<t>
UID EXPUNGE
</t>

</list>
</t>

<t>
Each message SHOULD either be moved or unaffected. The server MUST NOT leave a
message in neither mailbox, and SHOULD NOT leave a message in both mailboxes
afterwards, even if the server returns a tagged NO response. Note that these
restrictions only apply to individual messages and not to the command as a whole,
which can fail partway through.
</t>

<t>
Because of the similarity of MOVE to COPY, extensions that
affect COPY affect MOVE in the same way. Response codes such
TRYCREATE (see <xref target="RFC3501"/> Section 6.4.7), as well as those
defined by extensions, are sent as appropriate. See <xref target="ExtensionInteractions"/>
for more information about how MOVE interacts with other IMAP extensions.
</t>

<t>
An example:
</t>

<figure>
<artwork>
    C: a UID MOVE 42:69 forble
    S: * OK [COPYUID 432432 42:69 1202:1229]
    S: * 22 EXPUNGE
    S: (more expunges)
    S: a OK Done
</artwork>
</figure>

<t>
Note that the server may send EXPUNGEs for other messages as well,
if any happen to have been expunged at the same time; this is normal
IMAP operation.
</t>

<t>
Implementers will need to read <xref target="RFC4315"/> to understand what UID
EXPUNGE does, though full implementation of <xref target="RFC4315"/> is not
necessary.
</t>

<t>
Note that moving a message to the currently selected mailbox 
(that is, where the source and target mailboxes are the same)
is allowed when copying the message to the currently selected mailbox is
allowed.
</t>

<t>
The server may send EXPUNGE (or VANISHED) messages before the tagged
response, so the client cannot safely send more commands with message
sequence number arguments while the server is processing MOVE. The
UID MOVE command does not have this limitation.
</t>

<t>
Both MOVE and UID MOVE can be pipelined, however, pipelined MOVE and UID MOVE
commands MUST NOT specify overlapping sets of messages.
</t>

</section>

</section>

<section anchor="ExtensionInteractions" title="Interaction with other extensions">

<t>
This section describes how MOVE interacts with some other IMAP extensions.
</t>

<section anchor="RFC2087interact" title="RFC 2087, QUOTA">

<t>
The QUOTA extension (defined by <xref target="RFC2087"/>) may interact with
MOVE, on some servers, in the sense that a MOVE command may succeed where COPY
would cause a quota overrun. This may be user-visible, but should not
be MUA-visible.
</t>

</section>

<section anchor="RFC4314interact" title="RFC 4314, ACL">

<t>
The ACL rights <xref target="RFC4314"/> required for the UID MOVE are the
union of the ACL rights required for UID STORE, UID COPY and
UID EXPUNGE.
</t>

</section>

<section anchor="RFC4315interact" title="RFC 4315, UIDPLUS">

<t>
Servers supporting UIDPLUS <xref target="RFC4315"/> MUST send COPYUID
in response to a UID MOVE command.
</t>

<t>
Servers implementing UIDPLUS are also advised to
send the COPYUID response code in an untagged OK before sending EXPUNGE for
moved messages.  (Sending it in the tagged OK, as described in the UIDPLUS
specification, means that clients first receive an EXPUNGE for a
message and afterwards COPYUID for the same message. It can be
unnecessarily difficult to process that usefully.)
</t>

</section>

<section anchor="RFC5162interact" title="RFC 5162, QRESYNC">

<t>
The QRESYNC extension <xref target="RFC5162"/>  directs the server to send VANISHED
rather than EXPUNGE in response to the UID EXPUNGE command. The
same requirement applies to the UID MOVE command.
</t>

</section>

<section anchor="SieveInteract" title="IMAP Events in Sieve">

<t>
MOVE applies to IMAP events in Sieve <xref target="I-D.ietf-sieve-imap-sieve"/>
in the same way
as COPY does. Therefore, MOVE can cause a Sieve script to be
invoked with the imap.cause set to "COPY". Because MOVE does not
cause flags to be changed, a MOVE command will not result in a
script invocation with the imap.cause set to "FLAG".
</t>

</section>

</section>

<section anchor="Syntax" title="Formal Syntax">

<t>
The following syntax specification uses the Augmented Backus-Naur
Form (ABNF) notation as specified in <xref target="RFC5234"/>.
<xref target="RFC3501"/> defines the non-terminals "capability",
"command-select", "sequence-set" and "mailbox".
</t>

<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>

<figure>
<artwork type="ABNF">
capability     =/ "MOVE"

command-select =/ move
move = "MOVE" SP sequence-set SP mailbox
uid = "UID" SP (copy / fetch / search / store / move)
</artwork>
</figure>

</section>

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

<t>
MOVE does not introduce any new capabilities to IMAP, and this limits
the security impact. However, the transactional semantics of MOVE may
interact with specific implementations in ways that could have
unexpected consequences. For example, moving messages between folders
under the quota root may require temporary suspension of quota checking.
</t>

<t>
An additional area of concern is interaction with antispam, antivirus,
and other security scanning and auditing mechanisms. Different folders
may have different security policies which could interact with MOVE
in complex ways. Scanning with updated rules may also be required
when messages are moved even with the underlying policy has not changed.
</t>

<t>
MOVE does relieve a problem with the base specification, since client
authors currently have to devise and implement complicated algorithms to
handle partial failures of the STORE/COPY/EXPUNGE trio. Incomplete or
improper implementation of these algorithms can lead to mail loss.
</t>

</section>

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

<t>
The IANA is requested to add MOVE to the "IMAP 4 Capabilities"
registry, http://www.iana.org/assignments/imap4-capabilities.
</t>

</section>

<section title="Acknowledgments">

<t>
An extension like this has been proposed many times, by many people.
This document is based on several of those, most recently that by
Witold Krecicki. Witold, Adrien W. de Croy, Bron Gondwana, Dan Karp,
Barry Leiba, Alexey Melnikov, and others provided valuable comments.
</t>

</section>

</middle>

<back>

<references title="Normative References">

<?rfc include="reference.RFC.2119" ?>
<?rfc include="reference.RFC.3501" ?>
<?rfc include="reference.RFC.4314" ?>
<?rfc include="reference.RFC.4315" ?>
<?rfc include="reference.RFC.5234" ?>

</references>

<references title="Informative References">

<?rfc include="reference.RFC.2087" ?>
<?rfc include="reference.RFC.5162" ?>

<reference anchor='I-D.ietf-sieve-imap-sieve'>
<front>
<title>Support for Internet Message Access Protocol (IMAP) Events in Sieve</title>

<author initials='B' surname='Leiba' fullname='Barry Leiba'>
    <organization>Huawei Technologies</organization>
</author>

<date month='September' day='14' year='2012' />

</front>

<seriesInfo name='Internet-Draft' value='draft-ietf-sieve-imap-sieve-09' />
<format type='TXT'
        target='http://tools.ietf.org/id/draft-ietf-sieve-imap-sieve-09'/>
</reference>

</references>

<section title="Change History">

<t>
RFC Editor: Please delete this section from the final RFC.
</t>

<section title="Changes since -00">

<t>
<list style="numbers">

<t>
Fixed two bad nouns. Mailboxes aren't messages.
</t>

<t>
Adrien's server can easily do UID MOVE but not so easily MSN-based moves.
</t>

</list>
</t>

</section>

<section title="Changes since -01">

<t>
<list style="numbers">

<t>
Changed to Informative, on Barry's suggestion. Or did I ask him? Whatever.
</t>

<t>
Removed the 'reasons to avoid', it was doubleplusungood.
</t>

</list>
</t>

</section>

<section title="Changes since draft-gulbrandsen-imap-move-02">

<t>
<list style="numbers">

<t>
Various wording changes from Barry's review.
</t>

<t>
Open issue: Delete the \deleted rule?
</t>

<t>
Back to PS, informative didn't fly in the IESG
</t>

<t>
Turned into a WG document in order to get write access to the IMAP4
capabilities registry
</t>

<t>
Mention VANISHED in 5162
</t>

<t>
Added bad boilerplate to please idnits. This document contains no code.
</t>

</list>
</t>

</section>

<section title="Changes since -00">

<t>
<list style="numbers">

<t>
Added MSN-based move. The consensus seems mildly in favour. I think.
We'll see once this is posted.
</t>

<t>
Advise sending COPYUID earlier, to help clients. Requiring out of
order processing is unnecessarily nasty.
</t>

<t>
Note that moving to the source inbox has to work. I think it does
have to work, but this is a draft, it says so on every page.
</t>

</list>
</t>

</section>

<section title="Changes since -01">

<t>
<list style="numbers">

<t>
(Issue tracker #1)
Changed command-select ABNF to conform with the conventions used in RFC 3501.
</t>

<t>
(Issue tracker #2)
Banned overlapped pipelined MOVE and UID MOVE.
</t>

<t>
(Issue tracker #3)
Added section about interaction with IMAP Sieve.
</t>

<t>
(Issue tracker #4)
Revised security considerations.
</t>

<t>
(Issue tracker #5)
Removed text that characterized MOVE as the same as COPY/STORE/EXPUNGE.
</t>

<t>
(Issue tracker #6)
RFC 4314 is now a normative reference.
</t>

<t>
(Issue tracker #7)
Major rewrite of the command description text as a result of AD review.
</t>

<t>
(Issue tracker #8)
Revised abstract.
</t>

<t>
(Issue tracker #9)
Added text saying partial failures are allowed.
</t>

<t>
(Issue tracker #10)
Some additional tweaks to the security considerations section were made.
</t>

<t>
The abstract and introduction were out of whack as a result of other changes,
so some revisions were made to bring them back into sync.
</t>

</list>
</t>

</section> 

</section>

</back>

</rfc>
