RFC 8508
IMAP REPLACE Extension
RFC 8508: IMAP REPLACE Extension (part 1 of 2) π
- Number and title: RFC 8508, IMAP REPLACE Extension π
- Author: S. Brandt, from Verizon β¨
- Category: Standards Track, which means it's an official Internet Standards Track document π₯
- Date: January 2019 πΈ
- ISSN: 2070-1721
- Obsoletes / Updates: this header doesn't list either one, so there's nothing it obsoletes or updates π¦
Abstract
okay so this doc defines an IMAP extension that lets you replace an existing message in a message store with a brand-new one π message replacement is super common for clients that auto-save drafts or notes while you're typing, so it's lowkey essential π
Status of This Memo
this is an Internet Standards Track document π
it's a product of the Internet Engineering Task Force (IETF). it represents the consensus of the IETF community, it got public review, and the Internet Engineering Steering Group (IESG) approved it for publication π«Ά for more on Internet Standards, check Section 2 of RFC 7841.
for info on the current status, any errata, and how to give feedback, go to https://www.rfc-editor.org/info/rfc8508 π
Copyright Notice
Copyright (c) 2019 IETF Trust and the persons identified as the document authors. All rights reserved. π
this doc is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) as they stand on the publication date. please read these carefully, because they spell out your rights and restrictions for this document π any Code Components pulled out of this document must include Simplified BSD License text, as described in Section 4.e of the Trust Legal Provisions, and they come without warranty, as the Simplified BSD License describes π
Table of Contents
1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2. Conventions Used in This Document . . . . . . . . . . . . . . 3
3. REPLACE and UID REPLACE . . . . . . . . . . . . . . . . . . . 3
3.1. Advertising Support for REPLACE . . . . . . . . . . . . . 3
3.2. REPLACE Command . . . . . . . . . . . . . . . . . . . . . 3
3.3. UID REPLACE Command . . . . . . . . . . . . . . . . . . . 4
3.4. Semantics of REPLACE and UID REPLACE . . . . . . . . . . 5
3.5. IMAP State Diagram Impacts . . . . . . . . . . . . . . . 6
4. Interaction with Other Extensions . . . . . . . . . . . . . . 6
4.1. ACL . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.2. CATENATE . . . . . . . . . . . . . . . . . . . . . . . . 6
4.3. UIDPLUS . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.4. IMAP Events in Sieve . . . . . . . . . . . . . . . . . . 8
4.5. CONDSTORE/QRESYNC . . . . . . . . . . . . . . . . . . . . 8
4.6. OBJECTID . . . . . . . . . . . . . . . . . . . . . . . . 8
4.7. MULTIAPPEND . . . . . . . . . . . . . . . . . . . . . . . 8
5. Formal Syntax . . . . . . . . . . . . . . . . . . . . . . . . 9
6. Security Considerations . . . . . . . . . . . . . . . . . . . 9
7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 9
8. References . . . . . . . . . . . . . . . . . . . . . . . . . 9
8.1. Normative References . . . . . . . . . . . . . . . . . . 9
8.2. Informative References . . . . . . . . . . . . . . . . . 10
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 11
Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 11
1. Overview β¨
okay bestie, this doc adds an IMAP ([RFC3501]) extension for swapping an existing message out for a new one π¦ it does that by adding a brand-new REPLACE command and by extending the Unique Identifier (UID) command so it accepts UID REPLACE π«
here's the tea: base IMAP has no replace function at all π so clients have been stuck doing three separate commands, one after another: APPEND, STORE, and EXPUNGE. pipelining those three is not recommended, because if any single command fails, the rest should not run, otherwise the original version of the message could get lost π
that non-atomic mess causes real drama. interruptions can leave messages in half-done states that other clients can see and act on π they can also strand older revisions, so the user has to manually clean up a pile of copies of the same message just to stop wasting quota ποΈ and the old sequence can even fail on APPEND because you're over quota, even though the STORE/EXPUNGE that comes after would've freed up enough room for the new revision π€ finally, server efficiencies may be possible with one logical message replacement operation compared to the APPEND/STORE/EXPUNGE sequence π
in its simplest form, REPLACE is a single-command wrapper around APPEND, STORE +flags \DELETED, and UID EXPUNGE for one message π the difference is that it skips the quota implications and the intermediate states that come with the three-command sequence π server devs are encouraged to make REPLACE atomic, since that simplifies error handling, minimizes operational concerns, and reduces potential security problems β¨ for systems where that isn't possible, the communication with the requesting client has to make sure nobody gets confused about the message store state π«Ά
a server MUST NOT generate a response code for the STORE +flags \DELETED portion of the sequence. and servers that support the REPLACE command MUST NOT infer any inheritance of content, flags, or annotations from the message being replaced. no guessing, periodt π ββοΈ
2. Conventions Used in This Document π
the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here π§
formal syntax is defined by [RFC5234] π
example lines that start with "C:" are sent by the client, and the ones that start with "S:" are sent by the server π¬
3. REPLACE and UID REPLACE π
3.1. Advertising Support for REPLACE π£
servers that implement the REPLACE extension return "REPLACE" as one of the supported capabilities in the CAPABILITY command response π
3.2. REPLACE Command π
here's the rundown on the arguments, responses, and results:
Arguments: message sequence number
mailbox name
OPTIONAL flag parenthesized list
OPTIONAL date/time string
message literal
Responses: no specific responses for this command
Result: OK - replace completed
NO - replace error; can't remove specified message
or can't add new message content
BAD - command unknown or arguments invalid
and here's an example, the vibe is totally "happy new year" π
C: A003 REPLACE 4 Drafts (\Seen \Draft) {312}
S: + Ready for literal data
C: Date: Thu, 1 Jan 2015 00:05:00 -0500 (EST)
C: From: Fritz Schmidt <fritz.ze@example.org>
C: Subject: happy new year !!
C: To: miss.mitzy@example.org
C: Message-Id: <B238822388-0100000@example.org>
C: MIME-Version: 1.0
C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
C:
C: Just saw the best fireworks show. Wish you were here.
C:
S: * OK [APPENDUID 1 2000] Replacement Message ready
S: * 5 EXISTS
S: * 4 EXPUNGE
S: A003 OK Replace completed
3.3. UID REPLACE Command π¦
this one extends the first form of the UID command (see Section 6.4.8 of [RFC3501]) so that the REPLACE command from above is a valid argument π this version uses a UID instead of a sequence number as its first parameter π
example time π§
C: A004 UID REPLACE 2000 Drafts (\Seen \Draft) {350}
S: + Ready for literal data
C: Date: Thu, 1 Jan 2015 00:06:00 -0500 (EST)
C: From: Fritz Schmidt <fritz.ze@example.org>
C: Subject: happy new year !!
C: To: miss.mitzy@example.org
C: Message-Id: <B238822389-0100000@example.org>
C: MIME-Version: 1.0
C: Content-Type: TEXT/PLAIN; CHARSET=US-ASCII
C:
C: Just saw the best fireworks show. Wish you were here.
C: Hopefully next year you can join us.
C:
S: * OK [APPENDUID 1 2001] Replacement Message ready
S: * 5 EXISTS
S: * 4 EXPUNGE
S: A004 OK Replace completed
3.4. Semantics of REPLACE and UID REPLACE π§©
both REPLACE and UID REPLACE take five arguments: a message identifier, a named mailbox, an optional parenthesized flag list, an optional message date/time string, and a message literal β¨ the message literal gets appended to the named mailbox, and the message the identifier points to gets removed from the selected mailbox π«§ to the client, all of that looks like one single action. it has the same effect as this sequence:
APPEND[UID] STORE +FLAGS.SILENT \DELETEDUID EXPUNGE
in that sequence, the quota implications of APPEND get evaluated alongside the pending EXPUNGE, so only the net quota consumption counts π° and the EXPUNGE part only applies to the specified message, not to every message flagged as "\Deleted" π―
even though REPLACE has the same effect as those steps, the semantics aren't identical π like MOVE [RFC6851], the intermediate states never happen and the response codes are different π specifically, the response codes for APPEND and EXPUNGE get returned, but the ones for the STORE operation MUST NOT be generated π ββοΈ
when an error happens while processing REPLACE or UID REPLACE, the server MUST NOT leave the selected mailbox in an inconsistent state. and any untagged EXPUNGE response MUST NOT be sent until all the actions are successfully completed π
it's super common for the named mailbox to match the selected mailbox when you're replacing a draft, but the REPLACE extension intentionally does not require the two to be the same πΈ for example, you can use REPLACE to swap a message in the \Drafts special-use mailbox (see Section 2 of [RFC6154]) with a message in the \Sent special-use mailbox after the message gets submitted π€
because REPLACE is so similar to APPEND, any extension that affects APPEND affects REPLACE the same way β¨ response codes like TRYCREATE (see Section 6.3.11 of [RFC3501]), plus the ones defined by extensions, get sent as appropriate π« check Section 4 for more on how REPLACE plays with other IMAP extensions π§
3.5. IMAP State Diagram Impacts πΊοΈ
here's the twist: unlike APPEND, which is valid in the authenticated state, the REPLACE and UID REPLACE commands MUST only be valid in the selected state π that difference from APPEND is necessary because REPLACE operates on message sequence numbers π’ on top of that, the REPLACE extension intentionally follows the UID command convention from Section 6.4.8 of [RFC3501], so the UID variant of the command doesn't support use from the authenticated state either π ββοΈ
4. Interaction with Other Extensions π«Ά
this section explains how REPLACE interacts with some other IMAP extensions π
4.1. ACL π
the Access Control List (ACL) rights [RFC4314] required for UID REPLACE are the union of the ACL rights required for UID STORE and UID EXPUNGE in the current mailbox, plus APPEND in the target mailbox π so you need all three sets to slay this one π
4.2. CATENATE β¨
bestie, if your server does both REPLACE and CATENATE [RFC4469], it MUST support the extra append-data and resp-text-code elements from Section 5 ("Formal Syntax") of [RFC4469] alongside the REPLACE command π . Put those two together and REPLACE gets seriously efficient at message editing π₯.
Example time π:
User composes message and attaches photo
----------------------------------------
C: A010 APPEND Drafts (\Seen \Draft) {1201534}
S: + Ready for literal data
C: Date: Thu, 1 Jan 2015 00:10:00 -0500 (EST)
C: From: Fritz Schmidt <fritz.ze@example.org>
C: Message-ID: <B238822388-0100003@example.org>
C: MIME-Version: 1.0
C: Content-Type: multipart/mixed;
C: boundary="------------030305060306060609050804"
C:
C: --------------030305060306060609050804
C: Content-Type: text/plain; charset=utf-8; format=flowed
C: Content-Transfer-Encoding: 7bit
C:
C: Here is picture from the fireworks
C:
C: Yours...
C: Fritz
C:
C: --------------030305060306060609050804
C: Content-Type: image/jpeg;
C: name="Fireworks.jpg"
C: Content-Transfer-Encoding: base64
C: Content-Disposition: attachment;
C: filename="Fireworks.jpg"
C:
<large base64 encoded part goes here>
C:
C: --------------030305060306060609050804--
S: A010 OK [APPENDUID 1 3002] APPEND complete
User completes message with To: and Subject: fields
---------------------------------------------------
C: A011 UID REPLACE 3002 Drafts CATENATE (TEXT {71}
S: + Ready for literal data
C: To: Mitzy <miss.mitzy@example.org>
C: Subject: My view of the fireworks
C: URL "/Drafts/;UID=3002")
S: * OK [APPENDUID 1 3003] Replacement Message ready
S: * 5 EXISTS
S: * 4 EXPUNGE
S: A011 OK REPLACE completed
4.3. UIDPLUS π¦
Servers that do both REPLACE and UIDPLUS [RFC4315] SHOULD send APPENDUID in response to a UID REPLACE command π«Ά. More details are in Section 3 of [RFC4315]. Servers doing REPLACE and UIDPLUS are also advised to send the APPENDUID response code in an untagged OK before they send the EXPUNGE or replaced responses. Sending APPENDUID in the tagged OK, like the UIDPLUS spec describes, means the client gets EXPUNGE for a message first and APPENDUID for the new one afterwards π. That order is honestly a mess to process, so untagged is the move β¨.
4.4. IMAP Events in Sieve π§
REPLACE works with IMAP events in Sieve [RFC6785] the same way APPEND does π. So REPLACE can cause a Sieve script to run with imap.cause set to "APPEND". The intermediate state STORE +FLAGS.SILENT \DELETED is never exposed by REPLACE, so no action will be taken that results in an imap.cause of FLAG π.
4.5. CONDSTORE/QRESYNC πΈ
Servers doing both REPLACE and CONDSTORE/QRESYNC [RFC7162] MUST treat the message being replaced as if it were removed with a UID EXPUNGE command π. Sections 3.2.9 and 3.2.10 of [RFC7162] are especially relevant here π.
4.6. OBJECTID π
Servers doing both REPLACE and OBJECTID [RFC8474] MUST return different EMAILIDs for the replaced message and the replacing message π. There's one exception: the case in Section 5 ("EMAILID Identifier for Identical Messages") of [RFC8474], where the server detects that both messages have identical immutable content π«Ά.
4.7. MULTIAPPEND β
REPLACE has no interaction with MULTIAPPEND [RFC3502] at all π. This document also doesn't describe a way to replace multiple messages at once, so don't look for it here π« .
5. Formal Syntax π
The syntax below is written in Augmented Backus-Naur Form (ABNF) as specified in [RFC5234]. [RFC3501] defines the non-terminals "capability", "command-select", "mailbox", "seq-number", and "uid". [RFC4466] defines the non-terminal "append-message".
Unless noted otherwise, all alphabetic characters are case insensitive. Uppercase or lowercase letters are only used to define token strings for editorial clarity π. Implementations MUST accept these strings in a case-insensitive way β¨.
capability =/ "REPLACE"
command-select =/ replace
replace = "REPLACE" SP seq-number SP mailbox append-message
uid =/ "UID" SP replace
6. Security Considerations π
This document is believed to add no security problems beyond those that may already exist with the base IMAP specification π΅οΈββοΈ. Now here's the plot twist: the REPLACE command may actually prevent some potential security problems, because it avoids the intermediate message states that an attacker could possibly exploit π±π₯.
7. IANA Considerations ποΈ
IANA has added REPLACE to the "IMAP Capabilities" registry at https://www.iana.org/assignments/imap-capabilities π.
8. References π
8.1. Normative References
[RFC2119]Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997,https://www.rfc-editor.org/info/rfc2119.[RFC3501]Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1", RFC 3501, DOI 10.17487/RFC3501, March 2003,https://www.rfc-editor.org/info/rfc3501.[RFC4314]Melnikov, A., "IMAP4 Access Control List (ACL) Extension", RFC 4314, DOI 10.17487/RFC4314, December 2005,https://www.rfc-editor.org/info/rfc4314.[RFC4315]Crispin, M., "Internet Message Access Protocol (IMAP) - UIDPLUS extension", RFC 4315, DOI 10.17487/RFC4315, December 2005,https://www.rfc-editor.org/info/rfc4315.[RFC4466]Melnikov, A. and C. Daboo, "Collected Extensions to IMAP4 ABNF", RFC 4466, DOI 10.17487/RFC4466, April 2006,https://www.rfc-editor.org/info/rfc4466.[RFC4469]Resnick, P., "Internet Message Access Protocol (IMAP) CATENATE Extension", RFC 4469, DOI 10.17487/RFC4469, April 2006,https://www.rfc-editor.org/info/rfc4469.[RFC5234]Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", STD 68, RFC 5234, DOI 10.17487/RFC5234, January 2008,https://www.rfc-editor.org/info/rfc5234.[RFC6785]Leiba, B., "Support for Internet Message Access Protocol (IMAP) Events in Sieve", RFC 6785, DOI 10.17487/RFC6785, November 2012,https://www.rfc-editor.org/info/rfc6785.[RFC7162]Melnikov, A. and D. Cridland, "IMAP Extensions: Quick Flag Changes Resynchronization (CONDSTORE) and Quick Mailbox Resynchronization (QRESYNC)", RFC 7162, DOI 10.17487/RFC7162, May 2014,https://www.rfc-editor.org/info/rfc7162.[RFC8174]Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017,https://www.rfc-editor.org/info/rfc8174.[RFC8474]Gondwana, B., Ed., "IMAP Extension for Object Identifiers", RFC 8474, DOI 10.17487/RFC8474, September 2018,https://www.rfc-editor.org/info/rfc8474.
8.2. Informative References
[RFC3502]Crispin, M., "Internet Message Access Protocol (IMAP) - MULTIAPPEND Extension", RFC 3502, DOI 10.17487/RFC3502, March 2003,https://www.rfc-editor.org/info/rfc3502.[RFC6154]Leiba, B. and J. Nicolson, "IMAP LIST Extension for Special-Use Mailboxes", RFC 6154, DOI 10.17487/RFC6154, March 2011,https://www.rfc-editor.org/info/rfc6154.[RFC6851]Gulbrandsen, A. and N. Freed, Ed., "Internet Message Access Protocol (IMAP) - MOVE Extension", RFC 6851, DOI 10.17487/RFC6851, January 2013,https://www.rfc-editor.org/info/rfc6851.
Acknowledgements π«Ά
Huge thanks to the IMAPEXT participants π. Special shoutouts go to Arnt Gulbrandsen, Alexey Melnikov, Chris Newman, and Bron Gondwana for their specific contributions π.
Author's Address π
Stuart Brandt
Verizon
22001 Loudoun County Parkway
Ashburn, VA 20147
United States of America
Email: stujenerin@aol.com
π¦ where this page comes from
- ietf: rfc8508 2019-01
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms