<?xml version="1.0"?>
<rfc ipr="trust200902" docName="draft-ietf-imapmove-command-05"
     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 Extension">
Internet Message Access Protocol (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 COPY, STORE, and EXPUNGE commands to
perform this very common operation.
</t>

<t>
Implementors have long pointed out some shortcomings with this
approach. Because the moving of a message is not an atomic process,
interruptions can leave messages in intermediate states. Because
multiple clients can be accessing the mailboxes at the same time,
clients can see messages in intermediate states even without
interruptions. If the source mailbox contains other messages that are
flagged for deletion, the third step can have the side effect of
expunging more than just the set of moved messages. And servers with
certain types of back-end message stores might have efficient ways of
moving messages, which don't involve actual copying of data. Such
efficiencies are often not available to the COPY/STORE/EXPUNGE
process.
</t>

<t>
The MOVE extension is present in any IMAP4 implementation which
returns "MOVE" as one of the supported capabilities to the
CAPABILITY command.
</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>
Although the effect of the MOVE is the same as the preceding steps,
the semantics are not identical: The intermediate states produced by
those steps do not occur, and the response codes are different. In
particular, though the COPY and EXPUNGE response codes will be returned,
response codes for a STORE MUST NOT be generated and the \DELETED
flag MUST NOT be set for any message.
</t>

<t>
Because a MOVE applies to a set of messages, it might fail partway
through the set.  Regardless of whether the command is successful in
moving the entire set, each individual message SHOULD either be moved
or unaffected.  The server MUST leave each message in a state where
it is in at least one of the source or target mailboxes (no message can
be lost or orphaned).  The server SHOULD NOT leave any message in
both mailboxes (it would be bad for a partial failure to result in a bunch
of duplicate messages).  This is true even if the server returns a tagged
NO response to the command.
</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 unrelated EXPUNGE responses 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) responses 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 with other commands, but care
has to be taken.   Both commands modify sequence numbers and also allow
unrelated EXPUNGE responses.  The renumbering of other messages in the
source mailbox following any EXPUNGE response can be surprising, and
makes it unsafe to pipeline any command that relies on message sequence
numbers after a MOVE or UID MOVE.  Similarly, MOVE cannot be pipelined
with a command that might cause message renumbering.  See
<xref target="RFC3501"/>, Section 5.5, for more information about ambiguities
as well as handling requirements for both clients and servers.
</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.
</t>

</section>

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

<t>
The ACL rights <xref target="RFC4314"/> required for 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 or
moved responses.  (Sending COPYUID 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 sequence usefully.)
</t>

</section>

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

<t>
The QRESYNC extension <xref target="RFC5162"/> states that the server SHOULD
send VANISHED
rather than EXPUNGE in response to the UID EXPUNGE command.
The same requirement applies to MOVE, and a QRESYNC-enabled client
needs to handle both VANISHED and EXPUNGE responses to a UID MOVE
command.
</t>

<t>
If the server is capable of storing modification sequences for the
selected mailbox, it MUST increment the per-mailbox mod-sequence if
at least one message was permanently moved due to the execution of
the MOVE/UID MOVE command.  For each permanently removed message,
the server MUST remember the incremented mod-sequence and corresponding
UID.  If at least one message was moved, the server MUST send the
updated per-mailbox modification sequence using the HIGHESTMODSEQ
response code (defined in <xref target="RFC4551"/>) in the tagged or untagged
OK response.
</t>

<t>
When a message is moved to a target mailbox, if the server is capable
of storing modification sequences for the mailbox, the server MUST
generate a new modification sequence that is higher than the highest
modification sequence of all messages in the mailbox and assign it
to the moved message.
</t>

</section>

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

<t>
MOVE applies to IMAP events in Sieve <xref target="RFC6785"/>
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 mailboxes
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 mailboxes
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 when 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, Benoit Claise, Adrien W. de Croy, Stephen Farrell,
Bron Gondwana, Dan Karp, Christian Ketterer, Murray Kucherawy, Jan Kundrat,
Barry Leiba, Alexey Melnikov,  Kathleen Moriarty,  Zoltan Ordogh, 
Pete Resnick, Timo Sirainen, Michael Slusarz, 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.4551" ?>
<?rfc include="reference.RFC.5162" ?>
<?rfc include="reference.RFC.5234" ?>

</references>

<references title="Informative References">

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

</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 favor. 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 title="Changes since -02">

<t>
<list style="numbers">

<t>
Corrected various typos, clarified several paragraphs discussing MOVE
semantics.
</t>

<t>
Added the usual text about the extension only being available when it is
reported by the CAPABILITIES command.
</t>

<t>
Revised the text about QRESYNC to make clear what the requirements are.
</t>

<t>
Removed a suggestion about MUA/user behavior from the discussion of the
QUOTA extension.
</t>

<t>
Updated the main and running title to conform to other IMAP RFCs.
</t>

</list>
</t>

</section> 

<section title="Changes since -03">

<t>
<list style="numbers">

<t>
Corrected another bad noun. Responses aren't messages.
</t>

<t>
More minor editorial changes.
</t>

<t>
The text on command pipelining has been completely rewritten.
</t>

<t>
Added text stating that the effects of setting the \Deleted flag aren't
visible.
</t>

</list>
</t>

</section> 

<section title="Changes since -04">

<t>
<list style="numbers">

<t>
Added some additional requirements text for QRESYNC.
</t>

<t>
Took some text from the charter and added it to the introduction in order
to clarify why this extension is useful.
</t>

</list>
</t>

</section> 

</section>

</back>

</rfc>
