idnits 2.17.00 (12 Aug 2021) /tmp/idnits15279/draft-ietf-qresync-rfc4551bis-01.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** There are 10 instances of too long lines in the document, the longest one being 7 characters in excess of 72. -- The draft header indicates that this document obsoletes RFC4551, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document updates RFC2683, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document updates RFC3501, but the abstract doesn't seem to directly say this. It does mention RFC3501 though, so this could be OK. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year (Using the creation date from RFC2683, updated by this document, for RFC5378 checks: 1997-09-09) -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (June 06, 2013) is 3270 days in the past. Is this intentional? Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: 'UNSEEN 12' is mentioned on line 814, but not defined == Missing Reference: 'UIDVALIDITY 3857529045' is mentioned on line 815, but not defined == Missing Reference: 'UIDNEXT 4392' is mentioned on line 816, but not defined == Missing Reference: 'HIGHESTMODSEQ 715194045007' is mentioned on line 819, but not defined == Missing Reference: 'HIGHESTMODSEQ 12111230047' is mentioned on line 369, but not defined == Missing Reference: 'MODIFIED 7' is mentioned on line 397, but not defined -- Looks like a reference, but probably isn't: '9' on line 397 == Missing Reference: 'MODIFIED 12' is mentioned on line 407, but not defined == Missing Reference: 'MODIFIED 101' is mentioned on line 501, but not defined == Missing Reference: 'MODIFIED 2' is mentioned on line 535, but not defined ** Obsolete normative reference: RFC 3501 (Obsoleted by RFC 9051) -- Obsolete informational reference (is this intentional?): RFC 1305 (Obsoleted by RFC 5905) Summary: 2 errors (**), 0 flaws (~~), 10 warnings (==), 7 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group A. Melnikov 3 Internet-Draft Isode Ltd. 4 Obsoletes: 4551 (if approved) June 06, 2013 5 Updates: 3501, 2683 (if approved) 6 Intended status: Standards Track 7 Expires: December 08, 2013 9 IMAP Extension for Conditional STORE Operation or Quick Flag Changes 10 Resynchronization 11 draft-ietf-qresync-rfc4551bis-01.txt 13 Abstract 15 Often, multiple IMAP (RFC 3501) clients need to coordinate changes to 16 a common IMAP mailbox. Examples include different clients working on 17 behalf of the same user, and multiple users accessing shared 18 mailboxes. These clients need a mechanism to synchronize state 19 changes for messages within the mailbox. They must be able to 20 guarantee that only one client can change message state (e.g., 21 message flags) at any time. An example of such an application is use 22 of an IMAP mailbox as a message queue with multiple dequeueing 23 clients. 25 The Conditional Store facility provides a protected update mechanism 26 for message state information that can detect and resolve conflicts 27 between multiple writing mail clients. 29 The Conditional Store facility also allows a client to quickly 30 resynchronize mailbox flag changes. 32 This document defines an extension to IMAP (RFC 3501). 34 Status of This Memo 36 This Internet-Draft is submitted in full conformance with the 37 provisions of BCP 78 and BCP 79. 39 Internet-Drafts are working documents of the Internet Engineering 40 Task Force (IETF). Note that other groups may also distribute 41 working documents as Internet-Drafts. The list of current Internet- 42 Drafts is at http://datatracker.ietf.org/drafts/current/. 44 Internet-Drafts are draft documents valid for a maximum of six months 45 and may be updated, replaced, or obsoleted by other documents at any 46 time. It is inappropriate to use Internet-Drafts as reference 47 material or to cite them other than as "work in progress." 48 This Internet-Draft will expire on December 08, 2013. 50 Copyright Notice 52 Copyright (c) 2013 IETF Trust and the persons identified as the 53 document authors. All rights reserved. 55 This document is subject to BCP 78 and the IETF Trust's Legal 56 Provisions Relating to IETF Documents 57 (http://trustee.ietf.org/license-info) in effect on the date of 58 publication of this document. Please review these documents 59 carefully, as they describe your rights and restrictions with respect 60 to this document. Code Components extracted from this document must 61 include Simplified BSD License text as described in Section 4.e of 62 the Trust Legal Provisions and are provided without warranty as 63 described in the Simplified BSD License. 65 Table of Contents 67 1. Introduction and Overview . . . . . . . . . . . . . . . . . . 2 68 2. Conventions Used in This Document . . . . . . . . . . . . . . 5 69 3. IMAP Protocol Changes . . . . . . . . . . . . . . . . . . . . 5 70 3.1. New OK Untagged Responses for SELECT and EXAMINE . . . . 5 71 3.1.1. HIGHESTMODSEQ Response Code . . . . . . . . . . . . . 6 72 3.1.2. NOMODSEQ Response Code . . . . . . . . . . . . . . . 7 73 3.2. STORE and UID STORE Commands . . . . . . . . . . . . . . 7 74 3.3. FETCH and UID FETCH Commands . . . . . . . . . . . . . . 13 75 3.3.1. CHANGEDSINCE FETCH Modifier . . . . . . . . . . . . . 13 76 3.3.2. MODSEQ Message Data Item in FETCH Command . . . . . . 13 77 3.4. MODSEQ Search Criterion in SEARCH . . . . . . . . . . . . 16 78 3.5. Modified SEARCH Untagged Response . . . . . . . . . . . . 17 79 3.6. HIGHESTMODSEQ Status Data Items . . . . . . . . . . . . . 17 80 3.7. CONDSTORE Parameter to SELECT and EXAMINE . . . . . . . . 17 81 3.8. Additional Quality-of-Implementation Issues . . . . . . . 18 82 4. Formal Syntax . . . . . . . . . . . . . . . . . . . . . . . . 18 83 5. Server Implementation Considerations . . . . . . . . . . . . 21 84 6. Long Command Lines . . . . . . . . . . . . . . . . . . . . . 22 85 7. Security Considerations . . . . . . . . . . . . . . . . . . . 22 86 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 22 87 9. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 23 88 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 23 89 10.1. Normative References . . . . . . . . . . . . . . . . . . 23 90 10.2. Informative References . . . . . . . . . . . . . . . . . 23 91 Appendix A. Changes since RFC 4551 . . . . . . . . . . . . . . . 24 92 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 24 94 1. Introduction and Overview 95 The Conditional STORE extension is present in any IMAP4 96 implementation that returns "CONDSTORE" as one of the supported 97 capabilities in the CAPABILITY command response. 99 An IMAP server that supports this extension MUST associate a positive 100 unsigned 64-bit value called a modification sequence (mod-sequence) 101 with every IMAP message. This is an opaque value updated by the 102 server whenever a metadata item is modified. The server MUST 103 guarantee that each STORE command performed on the same mailbox 104 (including simultaneous stores to different metadata items from 105 different connections) will get a different mod-sequence value. 106 Also, for any two successful STORE operations performed in the same 107 session on the same mailbox, the mod-sequence of the second completed 108 operation MUST be greater than the mod-sequence of the first 109 completed. Note that the latter rule disallows the use of the system 110 clock as a mod-sequence, because if system time changes (e.g., an NTP 111 [RFC1305] client adjusting the time), the next generated value might 112 be less than the previous one. 114 Mod-sequences allow a client that supports the CONDSTORE extension to 115 determine if a message metadata has changed since some known moment. 116 Whenever the state of a flag changes (i.e., the flag is added where 117 previously it wasn't set, or the flag is removed and before it was 118 set) the value of the modification sequence for the message MUST be 119 updated. Adding the flag when it is already present or removing when 120 it is not present SHOULD NOT change the mod-sequence. 122 When a message is appended to a mailbox (via the IMAP APPEND command, 123 COPY to the mailbox, or using an external mechanism) the server 124 generates a new modification sequence that is higher than the highest 125 modification sequence of all messages in the mailbox and assigns it 126 to the appended message. 128 The server MAY store separate (per-message) modification sequence 129 values for different metadata items. If the server does so, per- 130 message mod-sequence is the highest mod-sequence of all metadata 131 items for the specified message. 133 The server that supports this extension is not required to be able to 134 store mod-sequences for every available mailbox. Section 3.1.2 135 describes how the server may act if a particular mailbox doesn't 136 support the persistent storage of mod-sequences. 138 This extension makes the following changes to the IMAP4 protocol: 140 a. adds UNCHANGEDSINCE STORE modifier. 142 b. adds the MODIFIED response code which should be used with an OK 143 response to the STORE command. (It can also be used in a NO 144 response.) 146 c. adds a new MODSEQ message data item for use with the FETCH 147 command. 149 d. adds CHANGEDSINCE FETCH modifier. 151 e. adds a new MODSEQ search criterion. 153 f. extends the syntax of untagged SEARCH responses to include mod- 154 sequence. 156 g. adds new OK untagged responses for the SELECT and EXAMINE 157 commands. 159 h. defines an additional parameter to SELECT/EXAMINE commands. 161 i. adds the HIGHESTMODSEQ status data item to the STATUS command. 163 A client supporting CONDSTORE extension indicates its willingness to 164 receive mod-sequence updates in all untagged FETCH responses by 165 issuing: 167 o a SELECT or EXAMINE command with the CONDSTORE parameter, 169 o a STATUS (HIGHESTMODSEQ) command, 171 o a FETCH or SEARCH command that includes the MODSEQ message data 172 item, 174 o a FETCH command with the CHANGEDSINCE modifier, or 176 o a STORE command with the UNCHANGEDSINCE modifier. 178 The server MUST include mod-sequence data in all subsequent untagged 179 FETCH responses (until the connection is closed), whether they were 180 caused by a regular STORE, a STORE with UNCHANGEDSINCE modifier, or 181 an external agent. 183 This document uses the term "CONDSTORE-aware client" to refer to a 184 client that announces its willingness to receive mod-sequence updates 185 as described above. The term "CONDSTORE enabling command" will refer 186 any of the commands listed above. A future extension to this 187 document may extend the list of CONDSTORE enabling commands. A first 188 CONDSTORE enabling command executed in the session MUST cause the 189 server to return HIGHESTMODSEQ (Section 3.1.1) unless the server has 190 sent NOMODSEQ (Section 3.1.2) response code when the currently 191 selected mailbox was selected. 193 The rest of this document describes the protocol changes more 194 rigorously. 196 2. Conventions Used in This Document 198 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 199 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 200 document are to be interpreted as described in RFC 2119 [RFC2119]. 202 In examples, lines beginning with "S:" are sent by the IMAP server, 203 and lines beginning with "C:" are sent by the client. Line breaks 204 may appear in example commands solely for editorial clarity; when 205 present in the actual message, they are represented by "CRLF". 207 Formal syntax is defined using ABNF [RFC5234]. 209 The term "metadata" or "metadata item" is used throughout this 210 document. It refers to any system or user-defined keyword. Future 211 documents may extend "metadata" to include other dynamic message 212 data. 214 Some IMAP mailboxes are private, accessible only to the owning user. 215 Other mailboxes are not, either because the owner has set an Access 216 Control List [RFC4314] that permits access by other users, or because 217 it is a shared mailbox. Let's call a metadata item "shared" for the 218 mailbox if any changes to the metadata items are persistent and 219 visible to all other users accessing the mailbox. Otherwise, the 220 metadata item is called "private". Note that private metadata items 221 are still visible to all sessions accessing the mailbox as the same 222 user. Also note that different mailboxes may have different metadata 223 items as shared. 225 See Section 1 for the definition of a "CONDSTORE-aware client" and a 226 "CONDSTORE enabling command". 228 3. IMAP Protocol Changes 230 3.1. New OK Untagged Responses for SELECT and EXAMINE 232 This document adds two new response codes, HIGHESTMODSEQ and 233 NOMODSEQ. One of those response codes MUST be returned in the OK 234 untagged response for a successful SELECT/EXAMINE command. 236 When opening a mailbox, the server must check if the mailbox supports 237 the persistent storage of mod-sequences. If the mailbox supports the 238 persistent storage of mod-sequences and the mailbox open operation 239 succeeds, the server MUST send the OK untagged response including 240 HIGHESTMODSEQ response code. If the persistent storage for the 241 mailbox is not supported, the server MUST send the OK untagged 242 response including NOMODSEQ response code instead. 244 3.1.1. HIGHESTMODSEQ Response Code 246 This document adds a new response code that is returned in the OK 247 untagged response for the SELECT and EXAMINE commands. A server 248 supporting the persistent storage of mod-sequences for the mailbox 249 MUST send the OK untagged response including HIGHESTMODSEQ response 250 code with every successful SELECT or EXAMINE command: 252 OK [HIGHESTMODSEQ ] 254 where is the highest mod-sequence value of 255 all messages in the mailbox. When the server changes UIDVALIDITY 256 for a mailbox, it doesn't have to keep the same HIGHESTMODSEQ for 257 the mailbox. 259 A disconnected client can use the value of HIGHESTMODSEQ to check if 260 it has to refetch metadata from the server. If the UIDVALIDITY value 261 has changed for the selected mailbox, the client MUST delete the 262 cached value of HIGHESTMODSEQ. If UIDVALIDITY for the mailbox is the 263 same, and if the HIGHESTMODSEQ value stored in the client's cache is 264 less than the value returned by the server, then some metadata items 265 on the server have changed since the last synchronization, and the 266 client needs to update its cache. The client MAY use SEARCH MODSEQ 267 (Section 3.4) to find out exactly which metadata items have changed. 268 Alternatively, the client MAY issue FETCH with the CHANGEDSINCE 269 modifier (Section 3.3.1) in order to fetch data for all messages that 270 have metadata items changed since some known modification sequence. 272 C: A142 SELECT INBOX 273 S: * 172 EXISTS 274 S: * 1 RECENT 275 S: * OK [UNSEEN 12] Message 12 is first unseen 276 S: * OK [UIDVALIDITY 3857529045] UIDs valid 277 S: * OK [UIDNEXT 4392] Predicted next UID 278 S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) 279 S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited 280 S: * OK [HIGHESTMODSEQ 715194045007] 281 S: A142 OK [READ-WRITE] SELECT completed 283 Example 1 285 3.1.2. NOMODSEQ Response Code 287 A server that doesn't support the persistent storage of mod-sequences 288 for the mailbox MUST send the OK untagged response including NOMODSEQ 289 response code with every successful SELECT or EXAMINE command. A 290 server that returned NOMODSEQ response code for a mailbox, which 291 subsequently receives one of the following commands while the mailbox 292 is selected: 294 o a FETCH command with the CHANGEDSINCE modifier, 296 o a FETCH or SEARCH command that includes the MODSEQ message data 297 item, or 299 o a STORE command with the UNCHANGEDSINCE modifier 301 MUST reject any such command with the tagged BAD response. 303 C: A142 SELECT INBOX 304 S: * 172 EXISTS 305 S: * 1 RECENT 306 S: * OK [UNSEEN 12] Message 12 is first unseen 307 S: * OK [UIDVALIDITY 3857529045] UIDs valid 308 S: * OK [UIDNEXT 4392] Predicted next UID 309 S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) 310 S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited 311 S: * OK [NOMODSEQ] Sorry, this mailbox format doesn't support 312 modsequences 313 S: A142 OK [READ-WRITE] SELECT completed 315 Example 2 317 3.2. STORE and UID STORE Commands 319 This document defines the following STORE modifier (see Section 2.5 320 of [RFC4466]): 322 UNCHANGEDSINCE For each message specified in the 323 message set, the server performs the following. If the mod- 324 sequence of any metadata item of the message is equal or less than 325 the specified UNCHANGEDSINCE value, then the requested operation 326 (as described by the message data item) is performed. If the 327 operation is successful, the server MUST update the mod-sequence 328 attribute of the message. An untagged FETCH response MUST be 329 sent, even if the .SILENT suffix is specified, and the response 330 MUST include the MODSEQ message data item. This is required to 331 update the client's cache with the correct mod-sequence values. 332 See Section 3.3.2 for more details. 334 However, if the mod-sequence of any metadata item of the message is 335 greater than the specified UNCHANGEDSINCE value, then the requested 336 operation MUST NOT be performed. In this case, the mod-sequence 337 attribute of the message is not updated, and the message number (or 338 unique identifier in the case of the UID STORE command) is added to 339 the list of messages that failed the UNCHANGEDSINCE test. 341 When the server finished performing the operation on all the messages 342 in the message set, it checks for a non-empty list of messages that 343 failed the UNCHANGEDSINCE test. If this list is non-empty, the 344 server MUST return in the tagged response a MODIFIED response code. 345 The MODIFIED response code includes the message set (for STORE) or 346 set of UIDs (for UID STORE) of all messages that failed the 347 UNCHANGEDSINCE test. 349 All messages pass the UNCHANGEDSINCE test. 351 C: a103 UID STORE 6,4,8 (UNCHANGEDSINCE 12121230045) 352 +FLAGS.SILENT (\Deleted) 353 S: * 1 FETCH (UID 4 MODSEQ (12121231000)) 354 S: * 2 FETCH (UID 6 MODSEQ (12121230852)) 355 S: * 4 FETCH (UID 8 MODSEQ (12121130956)) 356 S: a103 OK Conditional Store completed 358 Example 3 360 C: a104 STORE * (UNCHANGEDSINCE 12121230045) +FLAGS.SILENT 361 (\Deleted $Processed) 362 S: * 50 FETCH (MODSEQ (12111230047)) 363 S: a104 OK Store (conditional) completed 365 Example 4 367 C: c101 STORE 50 (UNCHANGEDSINCE 12121230045) -FLAGS.SILENT 368 (\Deleted) 369 S: * OK [HIGHESTMODSEQ 12111230047] 370 S: * 50 FETCH (MODSEQ (12111230048)) 371 S: c101 OK Store (conditional) completed 373 HIGHESTMODSEQ response code was sent by the server presumably because 374 this was the first CONDSTORE enabling command. 376 Example 5 378 In spite of the failure of the conditional STORE operation for 379 message 7, the server continues to process the conditional STORE in 380 order to find all messages that fail the test. 382 C: d105 STORE 7,5,9 (UNCHANGEDSINCE 320162338) 383 +FLAGS.SILENT (\Deleted) 384 S: * 5 FETCH (MODSEQ (320162350)) 385 S: d105 OK [MODIFIED 7,9] Conditional STORE failed 387 Example 6 389 Same as above, but the server follows the SHOULD recommendation in 390 Section 6.4.6 of [RFC3501]. 392 C: d105 STORE 7,5,9 (UNCHANGEDSINCE 320162338) 393 +FLAGS.SILENT (\Deleted) 394 S: * 7 FETCH (MODSEQ (320162342) FLAGS (\Seen \Deleted)) 395 S: * 5 FETCH (MODSEQ (320162350)) 396 S: * 9 FETCH (MODSEQ (320162349) FLAGS (\Answered)) 397 S: d105 OK [MODIFIED 7,9] Conditional STORE failed 399 Use of UNCHANGEDSINCE with a modification sequence of 0 always fails 400 if the metadata item exists. A system flag MUST always be considered 401 existent, whether it was set or not. 403 Example 7 405 C: a102 STORE 12 (UNCHANGEDSINCE 0) 406 +FLAGS.SILENT ($MDNSent) 407 S: a102 OK [MODIFIED 12] Conditional STORE failed 409 The client has tested the presence of the $MDNSent user-defined 410 keyword. 412 Example 8 414 Note: A client trying to make an atomic change to the state of a 415 particular metadata item (or a set of metadata items) should be 416 prepared to deal with the case when the server returns the MODIFIED 417 response code if the state of the metadata item being watched hasn't 418 changed (but the state of some other metadata item has). This is 419 necessary, because some servers don't store separate mod-sequences 420 for different metadata items. However, a server implementation 421 SHOULD avoid generating spurious MODIFIED responses for +FLAGS/-FLAGS 422 STORE operations, even when the server stores a single mod-sequence 423 per message. Section 5 describes how this can be achieved. 425 Unless the server has included an unsolicited FETCH to update 426 client's knowledge about messages that have failed the UNCHANGEDSINCE 427 test, upon receipt of the MODIFIED response code, the client SHOULD 428 try to figure out if the required metadata items have indeed changed 429 by issuing FETCH or NOOP command. It is RECOMMENDED that the server 430 avoids the need for the client to do that by sending an unsolicited 431 FETCH response (Examples 9 and 10). 433 If the required metadata items haven't changed, the client SHOULD 434 retry the command with the new mod-sequence. The client SHOULD allow 435 for a configurable but reasonable number of retries (at least 2). 437 In the example below, the server returns the MODIFIED response code 438 without sending information describing why the STORE UNCHANGEDSINCE 439 operation has failed. 441 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 442 +FLAGS.SILENT ($Processed) 443 S: * 100 FETCH (MODSEQ (303181230852)) 444 S: * 102 FETCH (MODSEQ (303181230852)) 445 ... 446 S: * 150 FETCH (MODSEQ (303181230852)) 447 S: a106 OK [MODIFIED 101] Conditional STORE failed 449 The flag $Processed was set on the message 101... 451 C: a107 NOOP 452 S: * 101 FETCH (MODSEQ (303011130956) FLAGS ($Processed)) 453 S: a107 OK 455 Example 9 457 Or the flag hasn't changed, but another has (note that this server 458 behaviour is discouraged. Server implementers should also see 459 Section 5)... 461 C: b107 NOOP 462 S: * 101 FETCH (MODSEQ (303011130956) FLAGS (\Deleted \Answered)) 463 S: b107 OK 465 ...and the client retries the operation for the message 101 with 466 the updated UNCHANGEDSINCE value 468 C: b108 STORE 101 (UNCHANGEDSINCE 303011130956) 469 +FLAGS.SILENT ($Processed) 470 S: * 101 FETCH (MODSEQ (303181230852)) 471 S: b108 OK Conditional Store completed 473 Same as above, but the server avoids the need for the client to poll 474 for changes. 476 The flag $Processed was set on the message 101 by another 477 client... 479 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 480 +FLAGS.SILENT ($Processed) 481 S: * 100 FETCH (MODSEQ (303181230852)) 482 S: * 101 FETCH (MODSEQ (303011130956) FLAGS ($Processed)) 483 S: * 102 FETCH (MODSEQ (303181230852)) 484 ... 485 S: * 150 FETCH (MODSEQ (303181230852)) 486 S: a106 OK [MODIFIED 101] Conditional STORE failed 488 Example 10 490 Or the flag hasn't changed, but another has (note that this server 491 behaviour is discouraged. Server implementers should also see 492 Section 5)... 494 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 495 +FLAGS.SILENT ($Processed) 496 S: * 100 FETCH (MODSEQ (303181230852)) 497 S: * 101 FETCH (MODSEQ (303011130956) FLAGS (\Deleted \Answered)) 498 S: * 102 FETCH (MODSEQ (303181230852)) 499 ... 500 S: * 150 FETCH (MODSEQ (303181230852)) 501 S: a106 OK [MODIFIED 101] Conditional STORE failed 503 ...and the client retries the operation for the message 101 with 504 the updated UNCHANGEDSINCE value 506 C: b108 STORE 101 (UNCHANGEDSINCE 303011130956) 507 +FLAGS.SILENT ($Processed) 508 S: * 101 FETCH (MODSEQ (303181230852)) 509 S: b108 OK Conditional Store completed 511 Or the flag hasn't changed, but another has (nice server behaviour. 512 Server implementers should also see Section 5)... 514 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 515 +FLAGS.SILENT ($Processed) 516 S: * 100 FETCH (MODSEQ (303181230852)) 517 S: * 101 FETCH (MODSEQ (303011130956) FLAGS ($Processed \Deleted 518 \Answered)) 519 S: * 102 FETCH (MODSEQ (303181230852)) 520 ... 521 S: * 150 FETCH (MODSEQ (303181230852)) 522 S: a106 OK Conditional STORE completed 524 The following example is based on the example from the Section 4.2.3 525 of [RFC2180] and demonstrates that the MODIFIED response code may be 526 also returned in the tagged NO response. 528 Client tries to conditionally STORE flags on a mixture of expunged 529 and non-expunged messages; one message fails the UNCHANGEDSINCE 530 test. 532 C: B001 STORE 1:7 (UNCHANGEDSINCE 320172338) +FLAGS (\SEEN) 533 S: * 1 FETCH (MODSEQ (320172342) FLAGS (\SEEN)) 534 S: * 3 FETCH (MODSEQ (320172342) FLAGS (\SEEN)) 535 S: B001 NO [MODIFIED 2] Some of the messages no longer exist. 537 C: B002 NOOP 538 S: * 4 EXPUNGE 539 S: * 4 EXPUNGE 540 S: * 4 EXPUNGE 541 S: * 4 EXPUNGE 542 S: * 2 FETCH (MODSEQ (320172340) FLAGS (\Deleted \Answered)) 543 S: B002 OK NOOP Completed. 545 By receiving FETCH responses for messages 1 and 3, and EXPUNGE 546 responses that indicate that messages 4 through 7 have been 547 expunged, the client retries the operation only for the message 2. 548 The updated UNCHANGEDSINCE value is used. 550 C: b003 STORE 2 (UNCHANGEDSINCE 320172340) +FLAGS (\Seen) 551 S: * 2 FETCH (MODSEQ (320180050)) 552 S: b003 OK Conditional Store completed 554 Example 11 556 Note: If a message is specified multiple times in the message set, 557 and the server doesn't internally eliminate duplicates from the 558 message set, it MUST NOT fail the conditional STORE operation for the 559 second (or subsequent) occurrence of the message if the operation 560 completed successfully for the first occurrence. For example, if the 561 client specifies: 563 e105 STORE 7,3:9 (UNCHANGEDSINCE 12121230045) +FLAGS.SILENT 564 (\Deleted) 566 the server must not fail the operation for message 7 as part of 567 processing "3:9" if it succeeded when message 7 was processed the 568 first time. 570 Once the client specified the UNCHANGEDSINCE modifier in a STORE 571 command, the server MUST include the MODSEQ fetch response data items 572 in all subsequent unsolicited FETCH responses. 574 This document also changes the behaviour of the server when it has 575 performed a STORE or UID STORE command and the UNCHANGEDSINCE 576 modifier is not specified. If the operation is successful for a 577 message, the server MUST update the mod-sequence attribute of the 578 message. The server is REQUIRED to include the mod-sequence value 579 whenever it decides to send the unsolicited FETCH response to all 580 CONDSTORE-aware clients that have opened the mailbox containing the 581 message. 583 Server implementers should also see Section 3.8 for additional 584 quality of implementation issues related to the STORE command. 586 3.3. FETCH and UID FETCH Commands 588 3.3.1. CHANGEDSINCE FETCH Modifier 590 This document defines the following FETCH modifier (see Section 2.4 591 of [RFC4466]): 593 CHANGEDSINCE CHANGEDSINCE FETCH modifier allows to 594 create a further subset of the list of messages described by 595 sequence set. The information described by message data items is 596 only returned for messages that have mod-sequence bigger than 597 . 599 When CHANGEDSINCE FETCH modifier is specified, it implicitly adds 600 MODSEQ FETCH message data item (Section 3.3.2). 602 C: s100 UID FETCH 1:* (FLAGS) (CHANGEDSINCE 12345) 603 S: * 1 FETCH (UID 4 MODSEQ (65402) FLAGS (\Seen)) 604 S: * 2 FETCH (UID 6 MODSEQ (75403) FLAGS (\Deleted)) 605 S: * 4 FETCH (UID 8 MODSEQ (29738) FLAGS ($NoJunk $AutoJunk 606 $MDNSent)) 607 S: s100 OK FETCH completed 609 Example 12 611 3.3.2. MODSEQ Message Data Item in FETCH Command 613 This extension adds a MODSEQ message data item to the FETCH command. 614 The MODSEQ message data item allows clients to retrieve mod-sequence 615 values for a range of messages in the currently selected mailbox. 617 Once the client specified the MODSEQ message data item in a FETCH 618 request, the server MUST include the MODSEQ fetch response data items 619 in all subsequent unsolicited FETCH responses. 621 Syntax: MODSEQ The MODSEQ message data item causes the server to 622 return MODSEQ fetch response data items. 624 Syntax: MODSEQ ( ) MODSEQ response data items 625 contain per-message mod-sequences. 627 The MODSEQ response data item is returned if the client issued 628 FETCH with MODSEQ message data item. It also allows the server to 629 notify the client about mod-sequence changes caused by conditional 630 STOREs (Section 3.2) and/or changes caused by external sources. 632 C: a FETCH 1:3 (MODSEQ) 633 S: * 1 FETCH (MODSEQ (624140003)) 634 S: * 2 FETCH (MODSEQ (624140007)) 635 S: * 3 FETCH (MODSEQ (624140005)) 636 S: a OK Fetch complete 638 In this example, the client requests per-message mod-sequences for a 639 set of messages. 641 Example 13 643 When a flag for a message is modified in a different session, the 644 server sends an unsolicited FETCH response containing the mod- 645 sequence for the message. 647 (Session 1, authenticated as a user "alex"). The user adds a 648 shared flag \Deleted: 650 C: A142 SELECT INBOX 651 ... 652 S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) 653 S: * OK [PERMANENTFLAGS (\Answered \Deleted \Seen \*)] Limited 654 ... 655 C: A160 STORE 7 +FLAGS.SILENT (\Deleted) 656 S: * 7 FETCH (MODSEQ (2121231000)) 657 S: A160 OK Store completed 659 (Session 2, also authenticated as the user "alex"). Any changes 660 to flags are always reported to all sessions authenticated as the 661 same user as in the session 1. 663 C: C180 NOOP 664 S: * 7 FETCH (FLAGS (\Deleted \Answered) MODSEQ (12121231000)) 665 S: C180 OK Noop completed 667 (Session 3, authenticated as a user "andrew"). As \Deleted is a 668 shared flag, changes in session 1 are also reported in session 3: 670 C: D210 NOOP 671 S: * 7 FETCH (FLAGS (\Deleted \Answered) MODSEQ (12121231000)) 672 S: D210 OK Noop completed 674 The user modifies a private flag \Seen in session 1... 676 C: A240 STORE 7 +FLAGS.SILENT (\Seen) 677 S: * 7 FETCH (MODSEQ (12121231777)) 678 S: A240 OK Store completed 680 ...which is only reported in session 2... 682 C: C270 NOOP 683 S: * 7 FETCH (FLAGS (\Deleted \Answered \Seen) MODSEQ 684 (12121231777)) 685 S: C270 OK Noop completed 687 ...but not in session 3. 689 C: D300 NOOP 690 S: D300 OK Noop completed 692 And finally, the user removes flags \Answered (shared) and \Seen 693 (private) in session 1. 695 C: A330 STORE 7 -FLAGS.SILENT (\Answered \Seen) 696 S: * 7 FETCH (MODSEQ (12121245160)) 697 S: A330 OK Store completed 699 Both changes are reported in the session 2... 701 C: C360 NOOP 702 S: * 7 FETCH (FLAGS (\Deleted) MODSEQ (12121245160)) 703 S: C360 OK Noop completed 705 ...and only changes to shared flags are reported in session 3. 707 C: D390 NOOP 708 S: * 7 FETCH (FLAGS (\Deleted) MODSEQ (12121245160)) 709 S: D390 OK Noop completed 711 Example 14 713 Server implementers should also see Section 3.8 for additional 714 quality of implementation issues related to the FETCH command. 716 3.4. MODSEQ Search Criterion in SEARCH 718 The MODSEQ criterion for the SEARCH command allows a client to search 719 for the metadata items that were modified since a specified moment. 721 Syntax: MODSEQ [ ] 723 Messages that have modification values that are equal to or 724 greater than . This allows a client, for 725 example, to find out which messages contain metadata items that 726 have changed since the last time it updated its disconnected 727 cache. The client may also specify (name of metadata 728 item) and (type of metadata item) before . can be one of "shared", "priv" 730 (private), or "all". The latter means that the server should use 731 the biggest value among "priv" and "shared" mod- sequences for the 732 metadata item. If the server doesn't store internally separate 733 mod-sequences for different metadata items, it MUST ignore and . Otherwise, the server should use them 735 to narrow down the search. 737 For a flag , the corresponding has a form " 738 /flags/" as defined in [RFC4466]. Note that the leading 739 "\" character that denotes a system flag has to be escaped as per 740 Section 4.3 of [RFC3501], as the uses syntax for 741 quoted strings. 743 If client specifies a MODSEQ criterion in a SEARCH command and the 744 server returns a non-empty SEARCH result, the server MUST also append 745 (to the end of the untagged SEARCH response) the highest mod-sequence 746 for all messages being returned. See also Section 3.5. 748 C: a SEARCH MODSEQ "/flags/\\draft" all 620162338 749 S: * SEARCH 2 5 6 7 11 12 18 19 20 23 (MODSEQ 917162500) 750 S: a OK Search complete 752 In the above example, the message numbers of any messages containing 753 the string "IMAP4" in the "value" attribute of the "/comment" entry 754 and having a mod-sequence equal to or greater than 620162338 for the 755 "\Draft" flag are returned in the search results. 757 Example 15 759 C: t SEARCH OR NOT MODSEQ 720162338 LARGER 50000 760 S: * SEARCH 761 S: t OK Search complete, nothing found 763 Example 16 765 3.5. Modified SEARCH Untagged Response 767 Data: zero or more numbers 768 mod-sequence value (omitted if no match) 770 This document extends syntax of the untagged SEARCH response to 771 include the highest mod-sequence for all messages being returned. 773 If a client specifies a MODSEQ criterion in a SEARCH (or UID SEARCH) 774 command and the server returns a non-empty SEARCH result, the server 775 MUST also append (to the end of the untagged SEARCH response) the 776 highest mod-sequence for all messages being returned. See 777 Section 3.5 for examples. 779 3.6. HIGHESTMODSEQ Status Data Items 781 This document defines a new status data item: 783 HIGHESTMODSEQ The highest mod-sequence value of all messages in the 784 mailbox. This is the same value that is returned by the server in 785 the HIGHESTMODSEQ response code in an OK untagged response (see 786 Section 3.1.1). If the server doesn't support the persistent 787 storage of mod-sequences for the mailbox (see Section 3.1.2), the 788 server MUST return 0 as the value of HIGHESTMODSEQ status data 789 item. 791 C: A042 STATUS blurdybloop (UIDNEXT MESSAGES HIGHESTMODSEQ) 792 S: * STATUS blurdybloop (MESSAGES 231 UIDNEXT 44292 793 HIGHESTMODSEQ 7011231777) 794 S: A042 OK STATUS completed 796 Example 17 798 3.7. CONDSTORE Parameter to SELECT and EXAMINE 800 The CONDSTORE extension defines a single optional select parameter, 801 "CONDSTORE", which tells the server that it MUST include the MODSEQ 802 fetch response data items in all subsequent unsolicited FETCH 803 responses. 805 The CONDSTORE parameter to SELECT/EXAMINE helps avoid a race 806 condition that might arise when one or more metadata items are 807 modified in another session after the server has sent the 808 HIGHESTMODSEQ response code and before the client was able to issue a 809 CONDSTORE enabling command. 811 C: A142 SELECT INBOX (CONDSTORE) 812 S: * 172 EXISTS 813 S: * 1 RECENT 814 S: * OK [UNSEEN 12] Message 12 is first unseen 815 S: * OK [UIDVALIDITY 3857529045] UIDs valid 816 S: * OK [UIDNEXT 4392] Predicted next UID 817 S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) 818 S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited 819 S: * OK [HIGHESTMODSEQ 715194045007] 820 S: A142 OK [READ-WRITE] SELECT completed, CONDSTORE is now enabled 822 Example 18 824 3.8. Additional Quality-of-Implementation Issues 826 Server implementations should follow the following rule, which 827 applies to any successfully completed STORE/UID STORE (with and 828 without UNCHANGEDSINCE modifier), as well as to a FETCH command that 829 implicitly sets \Seen flag: 831 Adding the flag when it is already present or removing when it is 832 not present SHOULD NOT change the mod-sequence. 834 This will prevent spurious client synchronization requests. 836 However, note that client implementers MUST NOT rely on this server 837 behavior. A client can't distinguish between the case when a server 838 has violated the SHOULD mentioned above, and that when one or more 839 clients set and unset (or unset and set) the flag in another session. 841 4. Formal Syntax 843 The following syntax specification uses the Augmented Backus-Naur 844 Form (ABNF) [RFC5234] notation. Elements not defined here can be 845 found in the formal syntax of the ABNF [RFC5234], IMAP [RFC3501], and 846 IMAP ABNF extensions [RFC4466] specifications. 848 Except as noted otherwise, all alphabetic characters are case- 849 insensitive. The use of upper- or lowercase characters to define 850 token strings is for editorial clarity only. Implementations MUST 851 accept these strings in a case-insensitive fashion. 853 capability =/ "CONDSTORE" 855 status-att =/ "HIGHESTMODSEQ" 856 ;; extends non-terminal defined in RFC 3501. 858 status-att-val =/ "HIGHESTMODSEQ" SP mod-sequence-valzer 859 ;; extends non-terminal defined in [RFC4466]. 860 ;; Value 0 denotes that the mailbox doesn't 861 ;; support persistent mod-sequences 862 ;; as described in Section 3.1.2 [[Check the ref]] 864 store-modifier =/ "UNCHANGEDSINCE" SP mod-sequence-valzer 865 ;; Only a single "UNCHANGEDSINCE" may be 866 ;; specified in a STORE operation 868 fetch-modifier =/ chgsince-fetch-mod 869 ;; conforms to the generic "fetch-modifier" 870 ;; syntax defined in [RFC4466]. 872 chgsince-fetch-mod = "CHANGEDSINCE" SP mod-sequence-value 873 ;; CHANGEDSINCE FETCH modifier conforms to 874 ;; the fetch-modifier syntax 876 fetch-att =/ fetch-mod-sequence 877 ;; modifies original IMAP4 fetch-att 879 fetch-mod-sequence = "MODSEQ" 881 fetch-mod-resp = "MODSEQ" SP "(" permsg-modsequence ")" 883 msg-att-dynamic =/ fetch-mod-resp 885 search-key =/ search-modsequence 886 ;; modifies original IMAP4 search-key 887 ;; 888 ;; This change applies to all commands 889 ;; referencing this non-terminal, in 890 ;; particular SEARCH. 892 search-modsequence = "MODSEQ" [search-modseq-ext] SP 893 mod-sequence-valzer 895 search-modseq-ext = SP entry-name SP entry-type-req 897 resp-text-code =/ "HIGHESTMODSEQ" SP mod-sequence-value / 898 "NOMODSEQ" / 899 "MODIFIED" SP sequence-set 901 entry-name = entry-flag-name 903 entry-flag-name = DQUOTE "/flags/" attr-flag DQUOTE 904 ;; each system or user defined flag 905 ;; is mapped to "/flags/". 906 ;; 907 ;; follows the escape rules 908 ;; used by "quoted" string as described in 909 ;; Section 4.3 of [RFC3501], e.g., for the flag 910 ;; \Seen the corresponding is 911 ;; "/flags/\\seen", and for the flag 912 ;; $MDNSent, the corresponding 913 ;; is "/flags/$mdnsent". 915 entry-type-resp = "priv" / "shared" 916 ;; metadata item type 918 entry-type-req = entry-type-resp / "all" 919 ;; perform SEARCH operation on private 920 ;; metadata item, shared metadata item or both 922 permsg-modsequence = mod-sequence-value 923 ;; per message mod-sequence 925 mod-sequence-value = 1*DIGIT 926 ;; Positive unsigned 64-bit integer 927 ;; (mod-sequence) 928 ;; (1 <= n < 18,446,744,073,709,551,615) 930 mod-sequence-valzer = "0" / mod-sequence-value 932 search-sort-mod-seq = "(" "MODSEQ" SP mod-sequence-value ")" 934 select-param =/ condstore-param 935 ;; conforms to the generic "select-param" 936 ;; non-terminal syntax defined in [RFC4466]. 938 condstore-param = "CONDSTORE" 940 mailbox-data =/ "SEARCH" [1*(SP nz-number) SP 941 search-sort-mod-seq] 943 attr-flag = "\\Answered" / "\\Flagged" / "\\Deleted" / 944 "\\Seen" / "\\Draft" / attr-flag-keyword / 945 attr-flag-extension 946 ;; Does not include "\\Recent" 948 attr-flag-extension = "\\" atom 949 ;; Future expansion. Client implementations 950 ;; MUST accept flag-extension flags. Server 951 ;; implementations MUST NOT generate 952 ;; flag-extension flags except as defined by 953 ;; future standard or standards-track 954 ;; revisions of [RFC3501]. 956 attr-flag-keyword = atom 958 5. Server Implementation Considerations 960 This section describes how a server implementation that doesn't store 961 separate per-metadata mod-sequences for different metadata items can 962 avoid sending the MODIFIED response to any of the following 963 conditional STORE operations: 965 +FLAGS 967 -FLAGS 969 +FLAGS.SILENT 971 -FLAGS.SILENT 973 Note that the optimization described in this section can't be 974 performed in case of a conditional STORE FLAGS operation. 976 Let's use the following example. The client has issued 978 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 979 +FLAGS.SILENT ($Processed) 981 When the server receives the command and parses it successfully, it 982 iterates through the message set and tries to execute the conditional 983 STORE command for each message. 985 Each server internally works as a client, i.e., it has to cache the 986 current state of all IMAP flags as it is known to the client. In 987 order to report flag changes to the client, the server compares the 988 cached values with the values in its database for IMAP flags. 990 Imagine that another client has changed the state of a flag \Deleted 991 on the message 101 and that the change updated the mod-sequence for 992 the message. The server knows that the mod-sequence for the mailbox 993 has changed; however, it also knows that: 995 a. the client is not interested in \Deleted flag, as it hasn't 996 included it in +FLAGS.SILENT operation; and 998 b. the state of the flag $Processed hasn't changed (the server can 999 determine this by comparing cached flag state with the state of 1000 the flag in the database). 1002 Therefore, the server doesn't have to report MODIFIED to the client. 1003 Instead, the server may set $Processed flag, update the mod-sequence 1004 for the message 101 once again and send an untagged FETCH response 1005 with new mod-sequence and flags: 1007 S: * 101 FETCH (MODSEQ (303011130956) 1008 FLAGS ($Processed \Deleted \Answered)) 1010 See also Section 3.8 for additional quality-of-implementation issues. 1012 6. Long Command Lines 1014 This document updates recommended line length limits specified in 1015 Section 3.2.1.5 of [RFC2683]. While the advice in the first 1016 paragraph of that section still applies ("use compact message/UID set 1017 representations"), the 1000 octet limit suggested in the second 1018 paragraph turned out to be quite problematic when the CONDSTORE 1019 extension is used. The updated recommendation is as follows: a 1020 client should limit the length of the command lines it generates to 1021 approximately 8192 octets (including all quoted strings but not 1022 including literals). 1024 7. Security Considerations 1026 It is believed that the Conditional STORE extension doesn't raise any 1027 new security concerns that are not already discussed in [RFC3501]. 1028 However, the availability of this extension may make it possible for 1029 IMAP4 to be used in critical applications it could not be used for 1030 previously, making correct IMAP server implementation and operation 1031 even more important. 1033 8. IANA Considerations 1035 IMAP4 capabilities are registered by publishing a standards track or 1036 IESG approved experimental RFC. The registry is currently located 1037 at: 1039 http://www.iana.org/assignments/imap4-capabilities 1041 This document defines the CONDSTORE IMAP capability. IANA has added 1042 it to the registry accordingly. 1044 9. Acknowledgements 1046 Thank you to Steve Hole for co-editing RFC 4551. 1048 Thank you to Dave Cridland for helping to convert the original text 1049 RFC to xml2rfc format. 1051 Some text was borrowed from "IMAP ANNOTATE Extension" [RFC5257] by 1052 Randall Gellens and Cyrus Daboo and from "ACAP -- Application 1053 Configuration Access Protocol" [RFC2244] by Chris Newman and John 1054 Myers. 1056 Many thanks to Randall Gellens for his thorough review of the 1057 document. 1059 The authors also acknowledge the feedback provided by Cyrus Daboo, 1060 Larry Greenfield, Chris Newman, Harrie Hazewinkel, Arnt Gulbrandsen, 1061 Timo Sirainen, Mark Crispin, Ned Freed, Ken Murchison, and Dave 1062 Cridland. 1064 10. References 1066 10.1. Normative References 1068 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1069 Requirement Levels", BCP 14, RFC 2119, March 1997. 1071 [RFC3501] Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION 1072 4rev1", RFC 3501, March 2003. 1074 [RFC4466] Melnikov, A. and C. Daboo, "Collected Extensions to IMAP4 1075 ABNF", RFC 4466, April 2006. 1077 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 1078 Specifications: ABNF", STD 68, RFC 5234, January 2008. 1080 10.2. Informative References 1082 [RFC1305] Mills, D., "Network Time Protocol (Version 3) 1083 Specification, Implementation", RFC 1305, March 1992. 1085 [RFC2180] Gahrns, M., "IMAP4 Multi-Accessed Mailbox Practice", RFC 1086 2180, July 1997. 1088 [RFC2244] Newman, C. and J. Myers, "ACAP -- Application 1089 Configuration Access Protocol", RFC 2244, November 1997. 1091 [RFC2683] Leiba, B., "IMAP4 Implementation Recommendations", RFC 1092 2683, September 1999. 1094 [RFC4314] Melnikov, A., "IMAP4 Access Control List (ACL) Extension", 1095 RFC 4314, December 2005. 1097 [RFC5257] Daboo, C. and R. Gellens, "Internet Message Access 1098 Protocol - ANNOTATE Extension", RFC 5257, June 2008. 1100 Appendix A. Changes since RFC 4551 1102 Fixed errata 3401, 3506 and 3509. 1104 Updated references. 1106 Author's Address 1108 Alexey Melnikov 1109 Isode Ltd. 1110 5 Castle Business Village 1111 36 Station Road 1112 Hampton, Middlesex TW12 2BX 1113 UK 1115 Email: Alexey.Melnikov@isode.com