RFC 5162
IMAP4 Extensions for Quick Mailbox Resynchronization
RFC 5162: IMAP4 Extensions for Quick Mailbox Resynchronization π¦
okay bestie, this one is the RFC for making IMAP reconnects fast, and I'm obsessed π
- Number: RFC 5162 π
- Title: IMAP4 Extensions for Quick Mailbox Resynchronization β¨
- Authors: A. Melnikov, D. Cridland (Isode Ltd), and C. Wilson (Nokia) π
- Stream: Network Working Group πΈ
- Category: Standards Track β (so this is an actual standard, not just vibes)
- Date: March 2008 π
- Obsoletes / Updates: the title block doesn't list anything here, so this one doesn't obsolete or update any other RFC π
Status of This Memo
This document is an Internet standards track protocol for the Internet community, and it's asking for discussion and suggestions for improvements π«Ά For the current standardization state and status of this protocol, check the "Internet Official Protocol Standards" (STD 1). Distribution of this memo is unlimited π
Abstract
so the big idea here π₯ This document defines an IMAP4 extension that lets a client quickly resync any mailbox it opened before. It happens as part of the SELECT command, and there's no need for server-side state or extra client round-trips. It also adds a new response that represents a list of expunged messages in a more compact way. It always includes the Unique Identifiers (UIDs) of the expunged messages π¦
Table of Contents
1. Introduction and Overview . . . . . . . . . . . . . . . . . . 2
2. Requirements Notation . . . . . . . . . . . . . . . . . . . . 4
3. IMAP Protocol Changes . . . . . . . . . . . . . . . . . . . . 4
3.1. QRESYNC Parameter to SELECT/EXAMINE . . . . . . . . . . . 4
3.2. VANISHED UID FETCH Modifier . . . . . . . . . . . . . . . 8
3.3. EXPUNGE Command . . . . . . . . . . . . . . . . . . . . . 10
3.4. CLOSE Command . . . . . . . . . . . . . . . . . . . . . . 11
3.5. UID EXPUNGE Command . . . . . . . . . . . . . . . . . . . 11
3.6. VANISHED Response . . . . . . . . . . . . . . . . . . . . 12
3.7. CLOSED Response Code . . . . . . . . . . . . . . . . . . . 15
4. Server Implementation Considerations . . . . . . . . . . . . . 15
4.1. Server Implementations That Don't Store Extra State . . . 15
4.2. Server Implementations Storing Minimal State . . . . . . . 16
4.3. Additional State Required on the Server . . . . . . . . . 16
5. Updated Synchronization Sequence . . . . . . . . . . . . . . . 17
6. Formal Syntax . . . . . . . . . . . . . . . . . . . . . . . . 19
7. Security Considerations . . . . . . . . . . . . . . . . . . . 20
8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 21
9. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 21
10. References . . . . . . . . . . . . . . . . . . . . . . . . . . 21
10.1. Normative References . . . . . . . . . . . . . . . . . . . 21
10.2. Informative References . . . . . . . . . . . . . . . . . . 22
1. Introduction and Overview β¨
okay so the [CONDSTORE] extension lets a disconnected client quickly resync IMAP flag changes for messages it already saw π Once a mailbox is open, you can use the CHANGEDSINCE FETCH modifier for that. BUT to figure out which messages got expunged, the client still has to send a UID FETCH or a UID SEARCH command. Not ideal, bestie π
So this document extends [CONDSTORE] so a reconnecting client can do a full resync, including finding the expunged messages, in a single round-trip π It also adds a new response, VANISHED, which represents a list of expunged messages in a more compact way. Iconic π
This is especially useful for mobile clients, which can disconnect a lot because of environmental stuff like battery life and signal strength π± Those clients need to reconnect quickly while keeping the delay the user feels short, and also keeping the amount of traffic (and therefore the cost) of resynchronizing low πΈ
By extending the SELECT command to do the extra resync, clients can also cut down on concurrent connections to the IMAP server. Those were only being held open to avoid having to resync, so this is a whole vibe shift π¦
The quick resync IMAP extension is present if an IMAP4 server returns "QRESYNC" as one of its supported capabilities in response to the CAPABILITY command π
Servers supporting this extension MUST implement and advertise support for the [ENABLE] IMAP extension. Also, the presence of the "QRESYNC" capability implies support for the [CONDSTORE] IMAP extension, even if the CONDSTORE capability isn't advertised πΈ A server compliant with this specification is REQUIRED to support "ENABLE QRESYNC" and "ENABLE QRESYNC CONDSTORE" (which are "CONDSTORE enabling commands", as defined in [CONDSTORE], and have identical results). There's no requirement for a compliant server to support "ENABLE CONDSTORE" by itself π The "ENABLE QRESYNC"/"ENABLE QRESYNC CONDSTORE" command also tells the server that it SHOULD start sending VANISHED responses (see Section 3.6) instead of EXPUNGE responses. This change stays in effect until the connection is closed π₯
For compatibility with clients that only support the [CONDSTORE] IMAP extension, servers SHOULD also advertise CONDSTORE in the CAPABILITY response π«Ά
A client using this extension MUST issue "ENABLE QRESYNC" once it is authenticated. A server MUST respond with a tagged BAD response if the QRESYNC parameter to the SELECT/EXAMINE command or the VANISHED UID FETCH modifier is specified and the client hasn't issued "ENABLE QRESYNC" in the current connection π«
This document puts additional requirements on a server implementing the [CONDSTORE] extension π Each mailbox that supports persistent storage of mod-sequences (meaning the server has sent a HIGHESTMODSEQ untagged OK response code on a successful SELECT/EXAMINE) MUST increment the per-mailbox mod-sequence when one or more messages are expunged due to EXPUNGE, UID EXPUNGE, or CLOSE. The server MUST associate the incremented mod-sequence with the UIDs of the expunged messages π’
Now the tea π΅ A client that supports CONDSTORE but not this extension might resync a mailbox and discover that its HIGHESTMODSEQ has increased from the value the client cached. If the increase is only because messages were expunged since the client last synced, the client is likely to send a FETCH ... CHANGEDSINCE command that returns no data. So a client that supports CONDSTORE but not this extension might take an unneeded round-trip when resyncing some mailboxes. Those are the ones that had messages expunged but no flag changes since the last sync π
That extra round-trip only happens for clients that support CONDSTORE but not this extension, and only when a mailbox had messages expunged but no flag changes to the messages that weren't expunged. Since CONDSTORE is a relatively new extension, it's thought likely that clients supporting it will also support this extension π
2. Requirements Notation
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 [RFC2119]. Those are the capitalized rules-words, so read them carefully π§
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, the line breaks between those lines are for editorial clarity only and are not part of the actual protocol exchange. The five characters [...] mean that something has been elided βοΈ
Understanding of the IMAP message sequence numbers, UIDs, and the EXPUNGE response [RFC3501] is essential when reading this document π§ no cap, you need these basics first.
3. IMAP Protocol Changes π
3.1. QRESYNC Parameter to SELECT/EXAMINE β¨
okay so the Quick Resynchronization parameter for SELECT/EXAMINE is giving main character energy π and it takes four arguments:
- the last known UIDVALIDITY,
- the last known modification sequence,
- the optional set of known UIDs, and
- an optional parenthesized list of known sequence ranges and their corresponding UIDs.
A server MUST respond with a tagged BAD response if the Quick Resynchronization parameter to a SELECT/EXAMINE command is specified and the client hasn't issued "ENABLE QRESYNC" in the current connection. no skipping that step, bestie π ββοΈ
Before the server opens the mailbox, it checks every argument for syntactic validity π. If any parameter isn't syntactically valid, the server returns the tagged BAD response and the mailbox remains unselected. Once the check passes, the server opens the mailbox as if no SELECT/EXAMINE parameters were specified (this is subject to processing of other parameters as defined in other extensions). The big deal here is that the server MUST send all untagged responses as specified in Sections 6.3.1 and 6.3.2 of [RFC3501] πΈ
After that, the server checks the UIDVALIDITY value the client sent. If the provided UIDVALIDITY doesn't match the UIDVALIDITY for the mailbox being opened, the server MUST ignore the remaining parameters and behave as if no dynamic message data changed. The client can spot this by comparing the UIDVALIDITY value the server sends back. This behaviour means the client doesn't have to synchronize the mailbox or pick the best synchronization strategy, which is honestly such a relief π«Ά
Example: Attempting to resynchronize INBOX, but the provided UIDVALIDITY parameter doesn't match the current UIDVALIDITY value.
C: A02 SELECT INBOX (QRESYNC (67890007 20050715194045000
41,43:211,214:541))
S: * 464 EXISTS
S: * 3 RECENT
S: * OK [UIDVALIDITY 3857529045] UIDVALIDITY
S: * OK [UIDNEXT 550] Predicted next UID
S: * OK [HIGHESTMODSEQ 90060128194045007]
S: * OK [UNSEEN 12] Message 12 is first unseen
S: * FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
S: * OK [PERMANENTFLAGS (\Answered \Flagged \Draft
\Deleted \Seen \*)] Permanent flags
S: A02 OK [READ-WRITE] Sorry, UIDVALIDITY mismatch
Modification Sequence and UID Parameters π
A server that doesn't support persistent storage of mod-sequences for the mailbox MUST send the OK untagged response, including the NOMODSEQ response code, with every successful SELECT or EXAMINE command, as described in [CONDSTORE]. Such a server doesn't need to remember mod-sequences for expunged messages in the mailbox. It MUST ignore the remaining parameters and behave as if no dynamic message data changed π
If the provided UIDVALIDITY matches that of the selected mailbox, the server then checks the last known modification sequence β
The server sends the client any pending flag changes (using FETCH responses that MUST contain UIDs) and expunges those that have occurred in this mailbox since the provided modification sequence. It's giving "catch you up on everything you missed" π
If the client also provided a list of known UIDs, the server should only report flag changes and expunges for the specified messages. If the client didn't provide a list of UIDs, the server acts as if the client has specified 1:<maxuid>, where <maxuid> is the mailbox's UIDNEXT value minus 1. If the mailbox is empty and never had any messages in it, then a missing list of UIDs is interpreted as an empty set of UIDs π§
So the client can process just these pending events and skip the full resync entirely π¦ Without the message sequence number matching information, the result of this step is semantically equivalent to the client issuing:
tag1 UID FETCH "known-uids" (FLAGS) (CHANGEDSINCE
"mod-sequence-value" VANISHED)
Example:
C: A03 SELECT INBOX (QRESYNC (67890007
90060115194045000 41,43:211,214:541))
S: * OK [CLOSED]
S: * 314 EXISTS
S: * 15 RECENT
S: * OK [UIDVALIDITY 67890007] UIDVALIDITY
S: * OK [UIDNEXT 567] Predicted next UID
S: * OK [HIGHESTMODSEQ 90060115205545359]
S: * OK [UNSEEN 7] There are some unseen messages in the mailbox
S: * FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
S: * OK [PERMANENTFLAGS (\Answered \Flagged \Draft
\Deleted \Seen \*)] Permanent flags
S: * VANISHED (EARLIER) 41,43:116,118,120:211,214:540
S: * 49 FETCH (UID 117 FLAGS (\Seen \Answered) MODSEQ
(90060115194045001))
S: * 50 FETCH (UID 119 FLAGS (\Draft $MDNSent) MODSEQ
(90060115194045308))
S: ...
S: * 100 FETCH (UID 541 FLAGS (\Seen $Forwarded) MODSEQ
(90060115194045001))
S: A03 OK [READ-WRITE] mailbox selected
Message Sequence Match Data π
A client MAY provide a parenthesized list of a message sequence set and the corresponding UID sets. Both MUST be provided in ascending order. The server uses this data to restrict the range for which it provides expunged message information π
Conceptually, the client gives the server a small sample of sequence numbers it knows the UIDs for. The server then compares each sequence number and UID pair the client provides with the current state of the mailbox. If a pair matches, the client knows about any expunges up to and including that message, so that range won't appear in the VANISHED response, even if the "mod-sequence-value" the client sent is too old for the server to have data on when those messages were expunged π«§
So, if the Nth message number in the first set in the list is 4, and the Nth UID in the second set in the list is 8, and the mailbox's fourth message has UID 8, then no UIDs equal to or less than 8 are present in the VANISHED response. If the (N+1)th message number is 12, and the (N+1)th UID is 24, and the (N+1)th message in the mailbox has UID 25, then the lowest UID included in the VANISHED response would be 9 π
In the following two examples, the server can't remember expunges at all, and only UIDs with messages divisible by three are present in the mailbox. In the first example, the client doesn't use the fourth parameter; in the second, it does. This one is kinda extreme, but it shows that using the sequence match data wisely can save a serious amount of bandwidth πβ¨
Example:
C: A04 SELECT INBOX (QRESYNC (67890007
90060115194045000 1:29997))
S: * 10003 EXISTS
S: * 5 RECENT
S: * OK [UIDVALIDITY 67890007] UIDVALIDITY
S: * OK [UIDNEXT 30013] Predicted next UID
S: * OK [HIGHESTMODSEQ 90060115205545359]
S: * OK [UNSEEN 7] There are some unseen messages in the mailbox
S: * FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
S: * OK [PERMANENTFLAGS (\Answered \Flagged \Draft
\Deleted \Seen \*)] Permanent flags
S: * VANISHED (EARLIER) 1:2,4:5,7:8,10:11,13:14 [...]
29998:29999,30001:30002,30004:30005,30007:30008
S: * 9889 FETCH (UID 29667 FLAGS (\Seen \Answered) MODSEQ
(90060115194045027))
S: * 9890 FETCH (UID 29670 FLAGS (\Draft $MDNSent) MODSEQ
(90060115194045028))
S: ...
S: * 9999 FETCH (UID 29997 FLAGS (\Seen $Forwarded) MODSEQ
(90060115194045031))
S: A04 OK [READ-WRITE] mailbox selected
Example:
C: B04 SELECT INBOX (QRESYNC (67890007
90060115194045000 1:29997 (5000,7500,9000,9990:9999 15000,
22500,27000,29970,29973,29976,29979,29982,29985,29988,29991,
29994,29997)))
S: * 10003 EXISTS
S: * 5 RECENT
S: * OK [UIDVALIDITY 67890007] UIDVALIDITY
S: * OK [UIDNEXT 30013] Predicted next UID
S: * OK [HIGHESTMODSEQ 90060115205545359]
S: * OK [UNSEEN 7] There are some unseen messages in the mailbox
S: * FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
S: * OK [PERMANENTFLAGS (\Answered \Flagged \Draft
\Deleted \Seen \*)] Permanent flags
S: * VANISHED (EARLIER) 29998:29999,30001:30002,30004:30005,30007:
30008
S: * 9889 FETCH (UID 29667 FLAGS (\Seen \Answered) MODSEQ
(90060115194045027))
S: * 9890 FETCH (UID 29670 FLAGS (\Draft $MDNSent) MODSEQ
(90060115194045028))
S: ...
S: * 9999 FETCH (UID 29997 FLAGS (\Seen $Forwarded) MODSEQ
(90060115194045031))
S: B04 OK [READ-WRITE] mailbox selected
3.2. VANISHED UID FETCH Modifier π¦
[IMAPABNF] extended the syntax of the FETCH and UID FETCH commands to include an optional FETCH modifier. This document defines a new UID FETCH modifier: VANISHED π
Note, the VANISHED UID FETCH modifier is NOT allowed with a FETCH command. The server MUST return a tagged BAD response if this modifier is specified on the FETCH command π«
A server MUST respond with a tagged BAD response if the VANISHED UID FETCH modifier is specified and the client hasn't issued "ENABLE QRESYNC" in the current connection.
The VANISHED UID FETCH modifier MUST only be specified together with the CHANGEDSINCE UID FETCH modifier. they're a package deal π
The VANISHED UID FETCH modifier tells the server to report those messages from the UID set parameter that have been expunged and whose associated mod-sequence is larger than the specified mod-sequence. In other words, the client asks to be told about messages from the specified set that were expunged since the specified mod-sequence. Note that the mod-sequence(s) associated with these messages were updated when the messages were expunged (as described above). The expunged messages get reported using the VANISHED response described in Section 3.6, which MUST contain the EARLIER tag. Any VANISHED (EARLIER) responses MUST be returned before any FETCH responses, otherwise the client might get confused about how message numbers map to UIDs π
Note: A server that receives a mod-sequence smaller than<minmodseq>, where<minmodseq>is the value of the smallest expunged mod-sequence it remembers minus one, MUST behave as if it was requested to report all expunged messages from the provided UID set parameter. π§
Example 1: Without the VANISHED UID FETCH modifier, a CONDSTORE-aware client [CONDSTORE] has to issue separate commands to learn about flag changes and expunged messages since its last synchronization:
C: s100 UID FETCH 300:500 (FLAGS) (CHANGEDSINCE 12345)
S: * 1 FETCH (UID 404 MODSEQ (65402) FLAGS (\Seen))
S: * 2 FETCH (UID 406 MODSEQ (75403) FLAGS (\Deleted))
S: * 4 FETCH (UID 408 MODSEQ (29738) FLAGS ($NoJunk
$AutoJunk $MDNSent))
S: s100 OK FETCH completed
C: s101 UID SEARCH 300:500
S: * SEARCH 404 406 407 408 410 412
S: s101 OK search completed
Where 300 and 500 are the lowest and highest UIDs from the client's cache. The second SEARCH response tells the client that the messages with UIDs 407, 410, and 412 are still present, but their flags haven't changed since the specified modification sequence π₯Ή
Using the VANISHED UID FETCH modifier, a single command is enough:
C: s100 UID FETCH 300:500 (FLAGS) (CHANGEDSINCE 12345
VANISHED)
S: * VANISHED (EARLIER) 300:310,405,411
S: * 1 FETCH (UID 404 MODSEQ (65402) FLAGS (\Seen))
S: * 2 FETCH (UID 406 MODSEQ (75403) FLAGS (\Deleted))
S: * 4 FETCH (UID 408 MODSEQ (29738) FLAGS ($NoJunk
$AutoJunk $MDNSent))
S: s100 OK FETCH completed
One command, zero drama πβ¨
3.3. EXPUNGE Command β¨
Arguments: none
Responses: untagged responses: EXPUNGE or VANISHED
Result: OK - expunge completed
NO - expunge failure: can't expunge (e.g., permission denied)
BAD - command unknown or arguments invalid
okay bestie, EXPUNGE is the command that actually deletes stuff ποΈπ
It permanently removes every message in the currently selected mailbox that has the \Deleted flag set. Before the server says OK, it has to report those removed messages using either a VANISHED response or EXPUNGE responses π¦
This section updates the EXPUNGE command definition from Section 6.4.3 of [RFC3501], so it's a glow-up for the old version π
If the server can store modification sequences for the selected mailbox, it MUST increment the per-mailbox mod-sequence whenever at least one message gets permanently removed by EXPUNGE π₯ For each removed message, the server MUST remember the incremented mod-sequence and the matching UID π§ And if anything got expunged, the server MUST send the updated per-mailbox modification sequence in the tagged OK response, using the HIGHESTMODSEQ response code (defined in [CONDSTORE]) π
Here's the example π
Example: C: A202 EXPUNGE
S: * 3 EXPUNGE
S: * 3 EXPUNGE
S: * 5 EXPUNGE
S: * 8 EXPUNGE
S: A202 OK [HIGHESTMODSEQ 20010715194045319] expunged
Note: messages 3, 4, 7, and 11 had the\Deletedflag set π The first* 3 EXPUNGEreports message # 3 as expunged. The second* 3 EXPUNGEreports message # 4 as expunged, because its message number got decremented after the previous EXPUNGE response π See the description of the EXPUNGE response in [RFC3501] for the full story.
Now, if the server always sends VANISHED responses instead of EXPUNGE responses, the same example might look like this π¦
Example: C: B202 EXPUNGE
S: * VANISHED 405,407,410,425
S: B202 OK [HIGHESTMODSEQ 20010715194045319] expunged
So messages with message numbers 3, 4, 7, and 11 have UIDs 405, 407, 410, and 425 respectively π
3.4. CLOSE Command πΈ
Arguments: none
Responses: no specific responses for this command
Result: OK - close completed, now in authenticated state
BAD - command unknown or arguments invalid
This section updates the CLOSE command definition from Section 6.4.2 of [RFC3501] β¨
CLOSE permanently removes every message with the \Deleted flag set from the currently selected mailbox, and then it drops you from the selected state back to the authenticated state π§ No untagged EXPUNGE (or VANISHED) responses get sent. Very quiet, very mysterious π
Same mod-sequence drama as before: if the server can store modification sequences for the selected mailbox, it MUST increment the per-mailbox mod-sequence if at least one message was permanently removed due to CLOSE π For each removed message, the server MUST remember the incremented mod-sequence and corresponding UID. If at least one message got expunged, the server MUST send the updated per-mailbox modification sequence using the HIGHESTMODSEQ response code (defined in [CONDSTORE]) in the tagged OK response π₯
Example π
Example: C: A202 CLOSE
S: A202 OK [HIGHESTMODSEQ 20010715194045319] done
3.5. UID EXPUNGE Command π¦
Arguments: message set
Responses: untagged responses: EXPUNGE or VANISHED
Result: OK - expunge completed
NO - expunge failure: can't expunge (e.g., permission denied)
BAD - command unknown or arguments invalid
This section updates the UID EXPUNGE command definition from Section 2.1 of [UIDPLUS] π Servers that implement both [UIDPLUS] and QRESYNC extensions must implement UID EXPUNGE as described in this section. That's the rule, bestie π
UID EXPUNGE permanently removes, from the currently selected mailbox, every message that has BOTH the \Deleted flag set AND a UID inside the specified message set π― If a message doesn't have \Deleted set, or its UID isn't in the message set, it's left alone π«Ά
This one is super useful for disconnected mode clients π± Instead of EXPUNGE, you use UID EXPUNGE when you resync with the server, so you don't accidentally nuke messages that other clients marked as \Deleted between the time you were last connected and the time you resynced π Protect your messages, protect your vibe π
Before returning an OK, the removed messages get reported with VANISHED or EXPUNGE responses β¨
If the server can store modification sequences for the selected mailbox, it MUST increment the per-mailbox mod-sequence if at least one message was permanently removed due to UID EXPUNGE. For each removed message, the server MUST remember the incremented mod-sequence and corresponding UID. If at least one message got expunged, the server MUST send the updated per-mailbox modification sequence using the HIGHESTMODSEQ response code (defined in [CONDSTORE]) in the tagged OK response π
Example π
Example: C: . UID EXPUNGE 3000:3002
S: * 3 EXPUNGE
S: * 3 EXPUNGE
S: * 3 EXPUNGE
S: . OK [HIGHESTMODSEQ 20010715194045319] Ok
Note: at least messages with message numbers 3, 4, and 5 (UIDs 3000 to 3002) had the\Deletedflag set π The first* 3 EXPUNGEreports message # 3 as expunged. The second* 3 EXPUNGEreports message # 4 as expunged, because its message number got decremented after the previous EXPUNGE response. See the description of the EXPUNGE response in [RFC3501] for further explanation πΈ
3.6. VANISHED Response π
Contents: an optional EARLIER tag
list of UIDs
The VANISHED response says that the specified UIDs have been permanently removed from the mailbox π¦ It's similar to the EXPUNGE response [RFC3501], but it can cover multiple messages at once, and it returns UIDs instead of message numbers. The first perk saves bandwidth, and the second is way more convenient for clients that only use UIDs to talk to the IMAP server π«Ά
VANISHED has the same restrictions on when it can be sent as EXPUNGE does (see below) β¨
VANISHED comes in two forms π The first form has the EARLIER tag, which tells you the response was caused by a UID FETCH (VANISHED) or a SELECT/EXAMINE (QRESYNC) command. It gets sent if the UID set parameter of the UID FETCH (VANISHED) command includes UIDs of messages that are no longer in the mailbox. When the client sees a VANISHED EARLIER response, it MUST NOT decrement message sequence numbers for each successive message in the mailbox π
The second form has no EARLIER tag, and we'll get to it below π§ Once a client has issued "ENABLE QRESYNC", the server SHOULD use the VANISHED response without the EARLIER tag instead of the EXPUNGE response π₯ The server SHOULD keep using VANISHED in place of EXPUNGE for the rest of the connection. This especially affects the EXPUNGE [RFC3501] and UID EXPUNGE [UIDPLUS] commands, and also messages expunged in other connections π A VANISHED response like this MUST NOT contain the EARLIER tag π
A VANISHED response sent because of an EXPUNGE or UID EXPUNGE command, or because messages were expunged in other connections (so, a VANISHED response without the EARLIER tag), also decrements the number of messages in the mailbox. The server doesn't need to send an EXISTS response with the new value π¦ It also decrements message sequence numbers for each successive message in the mailbox (see the example at the end of this section) π Note that a VANISHED response caused by EXPUNGE, UID EXPUNGE, or messages expunged in other connections SHOULD only contain UIDs for messages expunged since the last VANISHED/EXPUNGE response sent for the currently opened mailbox, or since the mailbox was opened. In other words, servers SHOULD NOT send UIDs for previously expunged messages, unless the UID FETCH (VANISHED) command explicitly asks for them π
Note that client implementors must take care to properly decrement the number of messages in the mailbox, even if a server violates this last SHOULD or repeats the same UID multiple times in the returned UID set π In general, a client using this extension should either avoid using message numbers entirely, or keep a complete mapping of UIDs to message sequence numbers for the selected mailbox π§
Because clients handle the two forms of VANISHED differently, servers MUST NOT report UIDs from a UID FETCH (VANISHED) or a SELECT/EXAMINE (QRESYNC) in the same VANISHED response as UIDs of messages expunged now (messages expunged in other connections). Instead, the server MUST send separate VANISHED responses: one with the EARLIER tag and one without π
A VANISHED response MUST NOT be sent when no command is in progress, nor while responding to a FETCH, STORE, or SEARCH command π₯ This rule exists to prevent a loss of synchronization of message sequence numbers between client and server π«Ά A command is not "in progress" until the complete command has been received. In particular, a command is not "in progress" during the negotiation of command continuation πΈ
Note: UID FETCH, UID STORE, and UID SEARCH are different commands from FETCH, STORE, and SEARCH π A VANISHED response MAY be sent during a UID command. However, the VANISHED response MUST NOT be sent during a UID SEARCH command that contains message numbers in the search criteria π¦
The update from the VANISHED response MUST be recorded by the client π
Example time! π Let's assume the following mapping between message numbers and UIDs in the currently selected mailbox. Here "X" marks messages with the \Deleted flag set, and "x" stands for UIDs that don't matter for this example π§
Message numbers: 1 2 3 4 5 6 7 8 9 10 11
UIDs: x 504 505 507 508 x 510 x x x 625
\Deleted messages: X X X X
With the extension defined in this document, you get this π
C: A202 EXPUNGE
S: * VANISHED 505,507,510,625
S: A202 OK EXPUNGE completed
Without the QRESYNC extension, the same example might look like this π
C: A202 EXPUNGE
S: * 3 EXPUNGE
S: * 3 EXPUNGE
S: * 5 EXPUNGE
S: * 8 EXPUNGE
S: A202 OK EXPUNGE completed
(Continuing previous example) If messages with UIDs 504 and 508 get marked as \Deleted later on π
C: A210 EXPUNGE
S: * VANISHED 504,508
S: A210 OK EXPUNGE completed
That's it for this bit. The last VANISHED response only contains UIDs of messages expunged since the previous VANISHED response π«Άβ¨
3.7. CLOSED Response Code β¨
Okay so the CLOSED response code has no parameters, just vibes π . A server that implements this extension MUST return CLOSED when the currently selected mailbox gets closed implicitly because someone ran SELECT/EXAMINE on a different mailbox. It's the boundary line π¦: everything before CLOSED is about the mailbox that just got closed, and everything after it is about the newly opened one.
No need to send CLOSED when you finish a CLOSE or an UNSELECT [UNSELECT] (or similar) command, since those just close the selected mailbox without opening a new one π«Ά
4. Server Implementation Considerations πΈ
This section walks through a minimalist implementation, a moderate one, and an example of a full implementation π§
4.1. Server Implementations That Don't Store Extra State
Strictly speaking, a server that doesn't remember the mod-sequences of expunged messages can still be compliant with this spec π These servers return every expunged message in the UID set of the UID FETCH (VANISHED) command every single time, ignoring the CHANGEDSINCE mod-sequence you gave them. They're discouraged, though, because they can end up sending VANISHED responses that are bigger than the result of a UID SEARCH command for the same UID set π
Clients that use the message sequence match data can seriously shrink this VANISHED response π Especially when no expunges happened, or they only happened toward the end of the mailbox.
4.2. Server Implementations Storing Minimal State
A server that stores the HIGHESTMODSEQ value at the time of the last EXPUNGE can skip the VANISHED response when a client gives a MODSEQ value that is equal to, or higher than, the current value of this datum. In other words, when there have been no EXPUNGEs β¨
A client providing message sequence match data can shrink the scope as above too. And if there have been no expunges, the server can just ignore that data π
4.3. Additional State Required on the Server
Compared to the [CONDSTORE] extension, this one makes servers store extra state about expunged messages π Implementations don't have to keep this state in persistent storage, but honestly? Using persistent storage is advisable π
One possible way to get this right is to store a queue of <UID set, mod-sequence> pairs. The <UID set> part can be represented as a sequence of <min UID, max UID> pairs π
When messages get expunged, one or more entries are added to the tail of the queue π
When the server gets a request for messages expunged since a given mod-sequence, it searches the queue from the tail (so going from the highest expunged mod-sequence down to the lowest) until it hits the first record with a mod-sequence less than or equal to the given one, or it reaches the head of the queue β
Storing info about expunged messages forever can cause storage problems π In the worst case, that could mean almost 64Gb of storage for each IMAP mailbox. Say an implementation stores<min UID, max UID, mod-sequence>triples for each range of messages expunged at the same time. Each triple takes 16 octets: 4 octets for each of the two UIDs, and 8 octets for the mod-sequence. Now imagine a mailbox with a single message whose UID is2**32-1(the maximum possible UID value), where messages used to exist with UIDs starting at 1 and got expunged one at a time. For that mailbox alone, the server would need to store these triples:
<1, 1, modseq1>, <2, 2, modseq2>, ..., <2**32-2, 2**32-2, modseq4294967294>
Hence, implementations are encouraged to adopt strategies that protect against this storage mess π¦ For example, they can limit the size of the queue used for expunged-message mod-sequences and "expire" older records once that limit is hit. When the chosen implementation-specific queue limit is reached, the oldest record(s) get deleted from the queue (those live at the queue head, fyi). For all these "expired" records, the server needs to store one single mod-sequence: the highest mod-sequence among all the "expired" expunged messages π
Also, if the client provides the message sequence match data, that can heavily cut the data cost of sending a complete set of missing UIDs. So it's less of a problem for clients when a server can't persist much of this queue. And if the queue already has data going back to the requested mod-sequence, that data can be ignored π
Last thing: if the UIDVALIDITY of the mailbox changes, or the mailbox gets deleted, then any state about expunged messages doesn't need to be kept around and SHOULD be deleted π«§
5. Updated Synchronization Sequence π₯
This section updates how optimized synchronization is described in Section 6.1 of the [IMAP-DISC] π
An advanced disconnected mail client should use the QRESYNC and [CONDSTORE] extensions when the server supports them π The client takes the value from the HIGHESTMODSEQ OK response code it gets when opening a mailbox, and uses it to figure out whether it needs to resynchronize. Once the sync is complete, it MUST cache the received value (unless the mailbox UIDVALIDITY value has changed; see below) β¨ The client MUST also update its copy of the HIGHESTMODSEQ value whenever the server sends a later HIGHESTMODSEQ OK response code π«Ά
After a full synchronization, the client MUST also take note of any unsolicited MODSEQ FETCH data items the server sends πΈ Whenever the client gets a tagged response to a command, it works out the highest value among all the MODSEQ FETCH data items received since the last tagged response. If that value is bigger than the client's copy of HIGHESTMODSEQ, then the client MUST use it as the new HIGHESTMODSEQ value π
Note: It is not safe to update the client's copy of HIGHESTMODSEQ with a MODSEQ FETCH data item value the moment it arrives, because servers are not required to send MODSEQ FETCH data items in increasing modseqence order. That could make the client miss some changes if the connection drops π
When opening the mailbox for sync, the client uses the QRESYNC parameter on the SELECT/EXAMINE command π¦ The QRESYNC parameter is followed by the UIDVALIDITY and mailbox HIGHESTMODSEQ values, as the client knows them. It can optionally be followed by a set of UIDs, for example if the client only cares about partial sync of the mailbox. The client may also send a list containing its knowledge of message numbers π§
If the SELECT/EXAMINE command succeeds, the client compares UIDVALIDITY the way step d)1) in Section 3 of the [IMAP-DISC] describes π If the cached UIDVALIDITY value matches the one the server returns, and the server also returns the HIGHESTMODSEQ response code, then the server reports expunged messages and returns flag changes for all messages in the UID set the client specified (or for every message in the mailbox, if the client left out the UID set parameter). At this point the client is synchronized, except maybe for the new messages π
If, after a successful SELECT/EXAMINE (QRESYNC) command, the client gets a NOMODSEQ OK untagged response (instead of the HIGHESTMODSEQ response code), it MUST remove the last known HIGHESTMODSEQ value from its cache, and follow the more general instructions in Section 3 of the [IMAP-DISC] π
At this point, the client is in sync with the server about old messages π It can now fetch info about new messages (if the user asked for that) β
Step d) ("Server-to-client synchronization") in Section 4 of the [IMAP-DISC], when the QRESYNC & CONDSTORE extensions are in play, gets amended like this π
d) "Server-to-client synchronization" -- for each mailbox that
requires synchronization, do the following:
1a) Check the mailbox UIDVALIDITY (see Section 4.1 of the [IMAP-DISC]
for more details) after issuing SELECT/EXAMINE (QRESYNC) command.
If the UIDVALIDITY value returned by the server differs, the
client MUST
* empty the local cache of that mailbox;
* "forget" the cached HIGHESTMODSEQ value for the mailbox;
* remove any pending "actions" which refer to UIDs in that
mailbox. Note, this doesn't affect actions performed on
client generated fake UIDs (see Section 5 of the
[IMAP-DISC]);
2) Fetch the current "descriptors";
I) Discover new messages.
3) Fetch the bodies of any "interesting" messages that the client
doesn't already have.
Here's an example where the UIDVALIDITY is the same, but the HIGHESTMODSEQ value changed on the server while the client was offline π
C: A142 SELECT INBOX (QRESYNC (3857529045 20010715194032001 1:198))
S: * 172 EXISTS
S: * 1 RECENT
S: * OK [UNSEEN 12] Message 12 is first unseen
S: * OK [UIDVALIDITY 3857529045] UIDs valid
S: * OK [UIDNEXT 201] Predicted next UID
S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited
S: * OK [HIGHESTMODSEQ 20010715194045007]
S: * VANISHED (EARLIER) 1:5,7:8,10:15
S: * 2 FETCH (UID 6 MODSEQ (20010715205008000)
FLAGS (\Deleted))
S: * 5 FETCH (UID 9 MODSEQ (20010715195517000)
FLAGS ($NoJunk $AutoJunk $MDNSent))
...
S: A142 OK [READ-WRITE] SELECT completed
6. Formal Syntax β¨
okay so this is the grammar bit π€ it's written in ABNF (Augmented Backus-Naur Form), which is the notation from [ABNF] βοΈ
any non-terminals we use but don't define here come from [RFC3501], [CONDSTORE], or [IMAPABNF] π
all alphabetic characters are case-insensitive, and the upper and lower case letters in token strings are just there to make it easier to read π implementations MUST accept these strings in a case-insensitive fashion π«Ά
capability =/ "QRESYNC"
select-param = "QRESYNC" SP "(" uidvalidity SP
mod-sequence-value [SP known-uids]
[SP seq-match-data] ")"
;; conforms to the generic select-param
;; syntax defined in [IMAPABNF]
seq-match-data = "(" known-sequence-set SP known-uid-set ")"
uidvalidity = nz-number
known-uids = sequence-set
;; sequence of UIDs, "*" is not allowed
known-sequence-set = sequence-set
;; set of message numbers corresponding to
;; the UIDs in known-uid-set, in ascending order.
;; * is not allowed.
known-uid-set = sequence-set
;; set of UIDs corresponding to the messages in
;; known-sequence-set, in ascending order.
;; * is not allowed.
message-data =/ expunged-resp
expunged-resp = "VANISHED" [SP "(EARLIER)"] SP known-uids
rexpunges-fetch-mod = "VANISHED"
;; VANISHED UID FETCH modifier conforms
;; to the fetch-modifier syntax
;; defined in [IMAPABNF]. It is only
;; allowed in the UID FETCH command.
resp-text-code =/ "CLOSED"
7. Security Considerations π
okay bestie, this one is serious π it's really important to test your clients AND servers thoroughly with this extension, because it changes how the server tells the client which messages got expunged π
security stuff that matters for [CONDSTORE] also matters here π«Ά
and this document doesn't bring any brand new security concerns that weren't already covered by [CONDSTORE] or [RFC3501] β¨ no new drama, just the old drama π
8. IANA Considerations π
IMAP4 capabilities get registered by publishing a standards track or IESG approved experimental RFC π the registry lives here:
http://www.iana.org/assignments/imap4-capabilities
this document defines the QRESYNC IMAP capability, and IANA has already added it to the registry π¦ iconic π
9. Acknowledgments π«Ά
huge thanks to Steve Hole, Cyrus Daboo, and Michael Wener for encouraging this document to exist π
valuable comments came in from Timo Sirainen, Michael Wener, Randall Gellens, Arnt Gulbrandsen, Chris Newman, Peter Coates, Mark Crispin, Elwyn Davies, Dan Karp, Eric Rescorla, and Mike Zraly πΈ some agreed, some totally disagreed, and that's how the good stuff gets made π₯
this document takes a lot of its text from [RFC3501] by Mark Crispin π
10. References π
10.1. Normative References
- [ABNF] Crocker, D. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", STD 68, RFC 5234, January 2008.
- [CONDSTORE] Melnikov, A. and S. Hole, "IMAP Extension for Conditional STORE Operation or Quick Flag Changes Resynchronization", RFC 4551, June 2006.
- [ENABLE] Gulbrandsen, A., Ed. and A. Melnikov, Ed., "The IMAP ENABLE Extension", RFC 5161, March 2008.
- [IMAPABNF] Melnikov, A. and C. Daboo, "Collected Extensions to IMAP4 ABNF", RFC 4466, April 2006.
- [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.
- [RFC3501] Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION 4rev1", RFC 3501, March 2003.
- [UIDPLUS] Crispin, M., "Internet Message Access Protocol (IMAP) - UIDPLUS extension", RFC 4315, December 2005.
10.2. Informative References
- [IMAP-DISC] Melnikov, A., Ed., "Synchronization Operations For Disconnected Imap4 Clients", RFC 4549, June 2006.
- [UNSELECT] Melnikov, A., "Internet Message Access Protocol (IMAP) UNSELECT command", RFC 3691, February 2004.
Authors' Addresses ποΈ
Alexey Melnikov
Isode Ltd
5 Castle Business Village
36 Station Road
Hampton, Middlesex TW12 2BX
UK
EMail: Alexey.Melnikov@isode.com
Dave Cridland
Isode Ltd
5 Castle Business Village
36 Station Road
Hampton, Middlesex TW12 2BX
UK
EMail: dave.cridland@isode.com
Corby Wilson
Nokia
5 Wayside Rd.
Burlington, MA 01803
USA
EMail: corby@computer.org
Full Copyright Statement βοΈ
Copyright (C) The IETF Trust (2008).
This document is subject to the rights, licenses and restrictions contained in BCP 78, and except as set forth therein, the authors retain all their rights.
This document and the information contained herein are provided on an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
Intellectual Property π
The IETF takes no position regarding the validity or scope of any Intellectual Property Rights or other rights that might be claimed to pertain to the implementation or use of the technology described in this document, or the extent to which any license under such rights might or might not be available. It also doesn't claim it has made any independent effort to identify any such rights. Information on the procedures with respect to rights in RFC documents can be found in BCP 78 and BCP 79.
Copies of IPR disclosures made to the IETF Secretariat, any assurances of licenses to be made available, or the result of an attempt made to obtain a general license or permission for the use of such proprietary rights by implementers or users of this specification can be obtained from the IETF on-line IPR repository at http://www.ietf.org/ipr.
The IETF invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that may cover technology that may be required to implement this standard. Please address the information to the IETF at ietf-ipr@ietf.org. π¦
π¦ where this page comes from
- ietf: rfc5162 2008-03
- π girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms