idnits 2.17.00 (12 Aug 2021) /tmp/idnits13896/draft-ietf-qresync-rfc4551bis-00.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 9 instances of too long lines in the document, the longest one being 4 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 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 RFC3501, updated by this document, for RFC5378 checks: 1997-09-12) -- 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 (May 30, 2013) is 3277 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 813, but not defined == Missing Reference: 'UIDVALIDITY 3857529045' is mentioned on line 814, but not defined == Missing Reference: 'UIDNEXT 4392' is mentioned on line 815, but not defined == Missing Reference: 'HIGHESTMODSEQ 715194045007' is mentioned on line 818, but not defined == Missing Reference: 'HIGHESTMODSEQ 12111230047' is mentioned on line 368, but not defined == Missing Reference: 'MODIFIED 7' is mentioned on line 396, but not defined -- Looks like a reference, but probably isn't: '9' on line 396 == Missing Reference: 'MODIFIED 12' is mentioned on line 406, but not defined == Missing Reference: 'MODIFIED 101' is mentioned on line 498, but not defined == Missing Reference: 'MODIFIED 2' is mentioned on line 534, 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 (==), 6 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) May 30, 2013 5 Updates: 3501 (if approved) 6 Intended status: Standards Track 7 Expires: December 01, 2013 9 IMAP Extension for Conditional STORE Operation or Quick Flag Changes 10 Resynchronization 11 draft-ietf-qresync-rfc4551bis-00.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 01, 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.3.3. MODSEQ Search Criterion in SEARCH . . . . . . . . . . 16 78 3.3.4. Modified SEARCH Untagged Response . . . . . . . . . . 17 79 3.3.5. HIGHESTMODSEQ Status Data Items . . . . . . . . . . . 17 80 3.3.6. CONDSTORE Parameter to SELECT and EXAMINE . . . . . . 17 81 3.3.7. Additional Quality-of-Implementation Issues . . . . . 18 82 4. Formal Syntax . . . . . . . . . . . . . . . . . . . . . . . . 18 83 5. Server Implementation Considerations . . . . . . . . . . . . 21 84 6. Security Considerations . . . . . . . . . . . . . . . . . . . 22 85 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 22 86 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 22 87 9. References . . . . . . . . . . . . . . . . . . . . . . . . . 23 88 9.1. Normative References . . . . . . . . . . . . . . . . . . 23 89 9.2. Informative References . . . . . . . . . . . . . . . . . 23 90 Appendix A. Changes since RFC 4551 . . . . . . . . . . . . . . . 23 91 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 24 93 1. Introduction and Overview 94 The Conditional STORE extension is present in any IMAP4 95 implementation that returns "CONDSTORE" as one of the supported 96 capabilities in the CAPABILITY command response. 98 An IMAP server that supports this extension MUST associate a positive 99 unsigned 64-bit value called a modification sequence (mod-sequence) 100 with every IMAP message. This is an opaque value updated by the 101 server whenever a metadata item is modified. The server MUST 102 guarantee that each STORE command performed on the same mailbox 103 (including simultaneous stores to different metadata items from 104 different connections) will get a different mod-sequence value. 105 Also, for any two successful STORE operations performed in the same 106 session on the same mailbox, the mod-sequence of the second completed 107 operation MUST be greater than the mod-sequence of the first 108 completed. Note that the latter rule disallows the use of the system 109 clock as a mod-sequence, because if system time changes (e.g., an NTP 110 [RFC1305] client adjusting the time), the next generated value might 111 be less than the previous one. 113 Mod-sequences allow a client that supports the CONDSTORE extension to 114 determine if a message metadata has changed since some known moment. 115 Whenever the state of a flag changes (i.e., the flag is added where 116 previously it wasn't set, or the flag is removed and before it was 117 set) the value of the modification sequence for the message MUST be 118 updated. Adding the flag when it is already present or removing when 119 it is not present SHOULD NOT change the mod-sequence. 121 When a message is appended to a mailbox (via the IMAP APPEND command, 122 COPY to the mailbox, or using an external mechanism) the server 123 generates a new modification sequence that is higher than the highest 124 modification sequence of all messages in the mailbox and assigns it 125 to the appended message. 127 The server MAY store separate (per-message) modification sequence 128 values for different metadata items. If the server does so, per- 129 message mod-sequence is the highest mod-sequence of all metadata 130 items for the specified message. 132 The server that supports this extension is not required to be able to 133 store mod-sequences for every available mailbox. Section 3.1.2 134 describes how the server may act if a particular mailbox doesn't 135 support the persistent storage of mod-sequences. 137 This extension makes the following changes to the IMAP4 protocol: 139 a. adds UNCHANGEDSINCE STORE modifier. 141 b. adds the MODIFIED response code which should be used with an OK 142 response to the STORE command. (It can also be used in a NO 143 response.) 145 c. adds a new MODSEQ message data item for use with the FETCH 146 command. 148 d. adds CHANGEDSINCE FETCH modifier. 150 e. adds a new MODSEQ search criterion. 152 f. extends the syntax of untagged SEARCH responses to include mod- 153 sequence. 155 g. adds new OK untagged responses for the SELECT and EXAMINE 156 commands. 158 h. defines an additional parameter to SELECT/EXAMINE commands. 160 i. adds the HIGHESTMODSEQ status data item to the STATUS command. 162 A client supporting CONDSTORE extension indicates its willingness to 163 receive mod-sequence updates in all untagged FETCH responses by 164 issuing: 166 o a SELECT or EXAMINE command with the CONDSTORE parameter, 168 o a STATUS (HIGHESTMODSEQ) command, 170 o a FETCH or SEARCH command that includes the MODSEQ message data 171 item, 173 o a FETCH command with the CHANGEDSINCE modifier, or 175 o a STORE command with the UNCHANGEDSINCE modifier. 177 The server MUST include mod-sequence data in all subsequent untagged 178 FETCH responses (until the connection is closed), whether they were 179 caused by a regular STORE, a STORE with UNCHANGEDSINCE modifier, or 180 an external agent. 182 This document uses the term "CONDSTORE-aware client" to refer to a 183 client that announces its willingness to receive mod-sequence updates 184 as described above. The term "CONDSTORE enabling command" will refer 185 any of the commands listed above. A future extension to this 186 document may extend the list of CONDSTORE enabling commands. A first 187 CONDSTORE enabling command executed in the session MUST cause the 188 server to return HIGHESTMODSEQ (Section 3.1.1) unless the server has 189 sent NOMODSEQ (Section 3.1.2) response code when the currently 190 selected mailbox was selected. 192 The rest of this document describes the protocol changes more 193 rigorously. 195 2. Conventions Used in This Document 197 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 198 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 199 document are to be interpreted as described in RFC 2119 [RFC2119]. 201 In examples, lines beginning with "S:" are sent by the IMAP server, 202 and lines beginning with "C:" are sent by the client. Line breaks 203 may appear in example commands solely for editorial clarity; when 204 present in the actual message, they are represented by "CRLF". 206 Formal syntax is defined using ABNF [RFC5234]. 208 The term "metadata" or "metadata item" is used throughout this 209 document. It refers to any system or user-defined keyword. Future 210 documents may extend "metadata" to include other dynamic message 211 data. 213 Some IMAP mailboxes are private, accessible only to the owning user. 214 Other mailboxes are not, either because the owner has set an Access 215 Control List [RFC4314] that permits access by other users, or because 216 it is a shared mailbox. Let's call a metadata item "shared" for the 217 mailbox if any changes to the metadata items are persistent and 218 visible to all other users accessing the mailbox. Otherwise, the 219 metadata item is called "private". Note that private metadata items 220 are still visible to all sessions accessing the mailbox as the same 221 user. Also note that different mailboxes may have different metadata 222 items as shared. 224 See Section 1 for the definition of a "CONDSTORE-aware client" and a 225 "CONDSTORE enabling command". 227 3. IMAP Protocol Changes 229 3.1. New OK Untagged Responses for SELECT and EXAMINE 231 This document adds two new response codes, HIGHESTMODSEQ and 232 NOMODSEQ. One of those response codes MUST be returned in the OK 233 untagged response for a successful SELECT/EXAMINE command. 235 When opening a mailbox, the server must check if the mailbox supports 236 the persistent storage of mod-sequences. If the mailbox supports the 237 persistent storage of mod-sequences and the mailbox open operation 238 succeeds, the server MUST send the OK untagged response including 239 HIGHESTMODSEQ response code. If the persistent storage for the 240 mailbox is not supported, the server MUST send the OK untagged 241 response including NOMODSEQ response code instead. 243 3.1.1. HIGHESTMODSEQ Response Code 245 This document adds a new response code that is returned in the OK 246 untagged response for the SELECT and EXAMINE commands. A server 247 supporting the persistent storage of mod-sequences for the mailbox 248 MUST send the OK untagged response including HIGHESTMODSEQ response 249 code with every successful SELECT or EXAMINE command: 251 OK [HIGHESTMODSEQ ] 253 where is the highest mod-sequence value of 254 all messages in the mailbox. When the server changes UIDVALIDITY 255 for a mailbox, it doesn't have to keep the same HIGHESTMODSEQ for 256 the mailbox. 258 A disconnected client can use the value of HIGHESTMODSEQ to check if 259 it has to refetch metadata from the server. If the UIDVALIDITY value 260 has changed for the selected mailbox, the client MUST delete the 261 cached value of HIGHESTMODSEQ. If UIDVALIDITY for the mailbox is the 262 same, and if the HIGHESTMODSEQ value stored in the client's cache is 263 less than the value returned by the server, then some metadata items 264 on the server have changed since the last synchronization, and the 265 client needs to update its cache. The client MAY use SEARCH MODSEQ 266 (Section 3.4) to find out exactly which metadata items have changed. 267 Alternatively, the client MAY issue FETCH with the CHANGEDSINCE 268 modifier (Section 3.3.1) in order to fetch data for all messages that 269 have metadata items changed since some known modification sequence. 271 C: A142 SELECT INBOX 272 S: * 172 EXISTS 273 S: * 1 RECENT 274 S: * OK [UNSEEN 12] Message 12 is first unseen 275 S: * OK [UIDVALIDITY 3857529045] UIDs valid 276 S: * OK [UIDNEXT 4392] Predicted next UID 277 S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) 278 S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited 279 S: * OK [HIGHESTMODSEQ 715194045007] 280 S: A142 OK [READ-WRITE] SELECT completed 282 Example 1 284 3.1.2. NOMODSEQ Response Code 286 A server that doesn't support the persistent storage of mod-sequences 287 for the mailbox MUST send the OK untagged response including NOMODSEQ 288 response code with every successful SELECT or EXAMINE command. A 289 server that returned NOMODSEQ response code for a mailbox, which 290 subsequently receives one of the following commands while the mailbox 291 is selected: 293 o a FETCH command with the CHANGEDSINCE modifier, 295 o a FETCH or SEARCH command that includes the MODSEQ message data 296 item, or 298 o a STORE command with the UNCHANGEDSINCE modifier 300 MUST reject any such command with the tagged BAD response. 302 C: A142 SELECT INBOX 303 S: * 172 EXISTS 304 S: * 1 RECENT 305 S: * OK [UNSEEN 12] Message 12 is first unseen 306 S: * OK [UIDVALIDITY 3857529045] UIDs valid 307 S: * OK [UIDNEXT 4392] Predicted next UID 308 S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) 309 S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited 310 S: * OK [NOMODSEQ] Sorry, this mailbox format doesn't support 311 modsequences 312 S: A142 OK [READ-WRITE] SELECT completed 314 Example 2 316 3.2. STORE and UID STORE Commands 318 This document defines the following STORE modifier (see Section 2.5 319 of [RFC4466]): 321 UNCHANGEDSINCE For each message specified in the 322 message set, the server performs the following. If the mod- 323 sequence of any metadata item of the message is equal or less than 324 the specified UNCHANGEDSINCE value, then the requested operation 325 (as described by the message data item) is performed. If the 326 operation is successful, the server MUST update the mod-sequence 327 attribute of the message. An untagged FETCH response MUST be 328 sent, even if the .SILENT suffix is specified, and the response 329 MUST include the MODSEQ message data item. This is required to 330 update the client's cache with the correct mod-sequence values. 331 See Section 3.3.2 for more details. 333 However, if the mod-sequence of any metadata item of the message is 334 greater than the specified UNCHANGEDSINCE value, then the requested 335 operation MUST NOT be performed. In this case, the mod-sequence 336 attribute of the message is not updated, and the message number (or 337 unique identifier in the case of the UID STORE command) is added to 338 the list of messages that failed the UNCHANGEDSINCE test. 340 When the server finished performing the operation on all the messages 341 in the message set, it checks for a non-empty list of messages that 342 failed the UNCHANGEDSINCE test. If this list is non-empty, the 343 server MUST return in the tagged response a MODIFIED response code. 344 The MODIFIED response code includes the message set (for STORE) or 345 set of UIDs (for UID STORE) of all messages that failed the 346 UNCHANGEDSINCE test. 348 All messages pass the UNCHANGEDSINCE test. 350 C: a103 UID STORE 6,4,8 (UNCHANGEDSINCE 12121230045) 351 +FLAGS.SILENT (\Deleted) 352 S: * 1 FETCH (UID 4 MODSEQ (12121231000)) 353 S: * 2 FETCH (UID 6 MODSEQ (12121230852)) 354 S: * 4 FETCH (UID 8 MODSEQ (12121130956)) 355 S: a103 OK Conditional Store completed 357 Example 3 359 C: a104 STORE * (UNCHANGEDSINCE 12121230045) +FLAGS.SILENT 360 (\Deleted $Processed) 361 S: * 50 FETCH (MODSEQ (12111230047)) 362 S: a104 OK Store (conditional) completed 364 Example 4 366 C: c101 STORE 50 (UNCHANGEDSINCE 12121230045) -FLAGS.SILENT 367 (\Deleted) 368 S: * OK [HIGHESTMODSEQ 12111230047] 369 S: * 50 FETCH (MODSEQ (12111230048)) 370 S: c101 OK Store (conditional) completed 372 HIGHESTMODSEQ response code was sent by the server presumably because 373 this was the first CONDSTORE enabling command. 375 Example 5 377 In spite of the failure of the conditional STORE operation for 378 message 7, the server continues to process the conditional STORE in 379 order to find all messages that fail the test. 381 C: d105 STORE 7,5,9 (UNCHANGEDSINCE 320162338) 382 +FLAGS.SILENT (\Deleted) 383 S: * 5 FETCH (MODSEQ (320162350)) 384 S: d105 OK [MODIFIED 7,9] Conditional STORE failed 386 Example 6 388 Same as above, but the server follows the SHOULD recommendation in 389 Section 6.4.6 of [RFC3501]. 391 C: d105 STORE 7,5,9 (UNCHANGEDSINCE 320162338) 392 +FLAGS.SILENT (\Deleted) 393 S: * 7 FETCH (MODSEQ (320162342) FLAGS (\Seen \Deleted)) 394 S: * 5 FETCH (MODSEQ (320162350)) 395 S: * 9 FETCH (MODSEQ (320162349) FLAGS (\Answered)) 396 S: d105 OK [MODIFIED 7,9] Conditional STORE failed 398 Use of UNCHANGEDSINCE with a modification sequence of 0 always fails 399 if the metadata item exists. A system flag MUST always be considered 400 existent, whether it was set or not. 402 Example 7 404 C: a102 STORE 12 (UNCHANGEDSINCE 0) 405 +FLAGS.SILENT ($MDNSent) 406 S: a102 OK [MODIFIED 12] Conditional STORE failed 408 The client has tested the presence of the $MDNSent user-defined 409 keyword. 411 Example 8 413 Note: A client trying to make an atomic change to the state of a 414 particular metadata item (or a set of metadata items) should be 415 prepared to deal with the case when the server returns the MODIFIED 416 response code if the state of the metadata item being watched hasn't 417 changed (but the state of some other metadata item has). This is 418 necessary, because some servers don't store separate mod-sequences 419 for different metadata items. However, a server implementation 420 SHOULD avoid generating spurious MODIFIED responses for +FLAGS/-FLAGS 421 STORE operations, even when the server stores a single mod-sequence 422 per message. Section 5 describes how this can be achieved. 424 Unless the server has included an unsolicited FETCH to update 425 client's knowledge about messages that have failed the UNCHANGEDSINCE 426 test, upon receipt of the MODIFIED response code, the client SHOULD 427 try to figure out if the required metadata items have indeed changed 428 by issuing FETCH or NOOP command. It is RECOMMENDED that the server 429 avoids the need for the client to do that by sending an unsolicited 430 FETCH response (Examples 9 and 10). 432 If the required metadata items haven't changed, the client SHOULD 433 retry the command with the new mod-sequence. The client SHOULD allow 434 for a configurable but reasonable number of retries (at least 2). 436 In the example below, the server returns the MODIFIED response code 437 without sending information describing why the STORE UNCHANGEDSINCE 438 operation has failed. 440 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 441 +FLAGS.SILENT ($Processed) 442 S: * 100 FETCH (MODSEQ (303181230852)) 443 S: * 102 FETCH (MODSEQ (303181230852)) 444 ... 445 S: * 150 FETCH (MODSEQ (303181230852)) 446 S: a106 OK [MODIFIED 101] Conditional STORE failed 448 The flag $Processed was set on the message 101... 450 C: a107 NOOP 451 S: * 101 FETCH (MODSEQ (303011130956) FLAGS ($Processed)) 452 S: a107 OK 454 Or the flag hasn't changed, but another has (note that this server 455 behaviour is discouraged. Server implementers should also see 456 Section 5)... 458 C: b107 NOOP 459 S: * 101 FETCH (MODSEQ (303011130956) FLAGS (\Deleted \Answered)) 460 S: b107 OK 462 ...and the client retries the operation for the message 101 with 463 the updated UNCHANGEDSINCE value 465 C: b108 STORE 101 (UNCHANGEDSINCE 303011130956) 466 +FLAGS.SILENT ($Processed) 467 S: * 101 FETCH (MODSEQ (303181230852)) 468 S: b108 OK Conditional Store completed 470 Example 9 472 Same as above, but the server avoids the need for the client to poll 473 for changes. 475 The flag $Processed was set on the message 101 by another 476 client... 478 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 479 +FLAGS.SILENT ($Processed) 480 S: * 100 FETCH (MODSEQ (303181230852)) 481 S: * 101 FETCH (MODSEQ (303011130956) FLAGS ($Processed)) 482 S: * 102 FETCH (MODSEQ (303181230852)) 483 ... 484 S: * 150 FETCH (MODSEQ (303181230852)) 485 S: a106 OK [MODIFIED 101] Conditional STORE failed 487 Or the flag hasn't changed, but another has (note that this server 488 behaviour is discouraged. Server implementers should also see 489 Section 5)... 491 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 492 +FLAGS.SILENT ($Processed) 493 S: * 100 FETCH (MODSEQ (303181230852)) 494 S: * 101 FETCH (MODSEQ (303011130956) FLAGS (\Deleted \Answered)) 495 S: * 102 FETCH (MODSEQ (303181230852)) 496 ... 497 S: * 150 FETCH (MODSEQ (303181230852)) 498 S: a106 OK [MODIFIED 101] Conditional STORE failed 500 ...and the client retries the operation for the message 101 with 501 the updated UNCHANGEDSINCE value 503 C: b108 STORE 101 (UNCHANGEDSINCE 303011130956) 504 +FLAGS.SILENT ($Processed) 505 S: * 101 FETCH (MODSEQ (303181230852)) 506 S: b108 OK Conditional Store completed 508 Or the flag hasn't changed, but another has (nice server 509 behaviour. Server implementers should also see Section 5)... 511 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 512 +FLAGS.SILENT ($Processed) 513 S: * 100 FETCH (MODSEQ (303181230852)) 514 S: * 101 FETCH (MODSEQ (303011130956) FLAGS ($Processed \Deleted 515 \Answered)) 516 S: * 102 FETCH (MODSEQ (303181230852)) 517 ... 518 S: * 150 FETCH (MODSEQ (303181230852)) 519 S: a106 OK Conditional STORE completed 521 Example 10 523 The following example is based on the example from the Section 4.2.3 524 of [RFC2180] and demonstrates that the MODIFIED response code may be 525 also returned in the tagged NO response. 527 Client tries to conditionally STORE flags on a mixture of expunged 528 and non-expunged messages; one message fails the UNCHANGEDSINCE 529 test. 531 C: B001 STORE 1:7 (UNCHANGEDSINCE 320172338) +FLAGS (\SEEN) 532 S: * 1 FETCH (MODSEQ (320172342) FLAGS (\SEEN)) 533 S: * 3 FETCH (MODSEQ (320172342) FLAGS (\SEEN)) 534 S: B001 NO [MODIFIED 2] Some of the messages no longer exist. 536 C: B002 NOOP 537 S: * 4 EXPUNGE 538 S: * 4 EXPUNGE 539 S: * 4 EXPUNGE 540 S: * 4 EXPUNGE 541 S: * 2 FETCH (MODSEQ (320172340) FLAGS (\Deleted \Answered)) 542 S: B002 OK NOOP Completed. 544 By receiving FETCH responses for messages 1 and 3, and EXPUNGE 545 responses that indicate that messages 4 through 7 have been 546 expunged, the client retries the operation only for the message 2. 547 The updated UNCHANGEDSINCE value is used. 549 C: b003 STORE 2 (UNCHANGEDSINCE 320172340) +FLAGS (\Seen) 550 S: * 2 FETCH (MODSEQ (320180050)) 551 S: b003 OK Conditional Store completed 553 Example 11 555 Note: If a message is specified multiple times in the message set, 556 and the server doesn't internally eliminate duplicates from the 557 message set, it MUST NOT fail the conditional STORE operation for the 558 second (or subsequent) occurrence of the message if the operation 559 completed successfully for the first occurrence. For example, if the 560 client specifies: 562 e105 STORE 7,3:9 (UNCHANGEDSINCE 12121230045) +FLAGS.SILENT 563 (\Deleted) 565 the server must not fail the operation for message 7 as part of 566 processing "3:9" if it succeeded when message 7 was processed the 567 first time. 569 Once the client specified the UNCHANGEDSINCE modifier in a STORE 570 command, the server MUST include the MODSEQ fetch response data items 571 in all subsequent unsolicited FETCH responses. 573 This document also changes the behaviour of the server when it has 574 performed a STORE or UID STORE command and the UNCHANGEDSINCE 575 modifier is not specified. If the operation is successful for a 576 message, the server MUST update the mod-sequence attribute of the 577 message. The server is REQUIRED to include the mod-sequence value 578 whenever it decides to send the unsolicited FETCH response to all 579 CONDSTORE-aware clients that have opened the mailbox containing the 580 message. 582 Server implementers should also see Section 3.8 for additional 583 quality of implementation issues related to the STORE command. 585 3.3. FETCH and UID FETCH Commands 587 3.3.1. CHANGEDSINCE FETCH Modifier 589 This document defines the following FETCH modifier (see Section 2.4 590 of [RFC4466]): 592 CHANGEDSINCE CHANGEDSINCE FETCH modifier allows to 593 create a further subset of the list of messages described by 594 sequence set. The information described by message data items is 595 only returned for messages that have mod-sequence bigger than 596 . 598 When CHANGEDSINCE FETCH modifier is specified, it implicitly adds 599 MODSEQ FETCH message data item (Section 3.3.2). 601 C: s100 UID FETCH 1:* (FLAGS) (CHANGEDSINCE 12345) 602 S: * 1 FETCH (UID 4 MODSEQ (65402) FLAGS (\Seen)) 603 S: * 2 FETCH (UID 6 MODSEQ (75403) FLAGS (\Deleted)) 604 S: * 4 FETCH (UID 8 MODSEQ (29738) FLAGS ($NoJunk $AutoJunk 605 $MDNSent)) 606 S: s100 OK FETCH completed 608 Example 12 610 3.3.2. MODSEQ Message Data Item in FETCH Command 612 This extension adds a MODSEQ message data item to the FETCH command. 613 The MODSEQ message data item allows clients to retrieve mod-sequence 614 values for a range of messages in the currently selected mailbox. 616 Once the client specified the MODSEQ message data item in a FETCH 617 request, the server MUST include the MODSEQ fetch response data items 618 in all subsequent unsolicited FETCH responses. 620 Syntax: MODSEQ The MODSEQ message data item causes the server to 621 return MODSEQ fetch response data items. 623 Syntax: MODSEQ ( ) MODSEQ response data items 624 contain per-message mod-sequences. 626 The MODSEQ response data item is returned if the client issued 627 FETCH with MODSEQ message data item. It also allows the server to 628 notify the client about mod-sequence changes caused by conditional 629 STOREs (Section 3.2) and/or changes caused by external sources. 631 C: a FETCH 1:3 (MODSEQ) 632 S: * 1 FETCH (MODSEQ (624140003)) 633 S: * 2 FETCH (MODSEQ (624140007)) 634 S: * 3 FETCH (MODSEQ (624140005)) 635 S: a OK Fetch complete 637 In this example, the client requests per-message mod-sequences for a 638 set of messages. 640 Example 13 642 When a flag for a message is modified in a different session, the 643 server sends an unsolicited FETCH response containing the mod- 644 sequence for the message. 646 (Session 1, authenticated as a user "alex"). The user adds a 647 shared flag \Deleted: 649 C: A142 SELECT INBOX 650 ... 651 S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) 652 S: * OK [PERMANENTFLAGS (\Answered \Deleted \Seen \*)] Limited 653 ... 654 C: A160 STORE 7 +FLAGS.SILENT (\Deleted) 655 S: * 7 FETCH (MODSEQ (2121231000)) 656 S: A160 OK Store completed 658 (Session 2, also authenticated as the user "alex"). Any changes 659 to flags are always reported to all sessions authenticated as the 660 same user as in the session 1. 662 C: C180 NOOP 663 S: * 7 FETCH (FLAGS (\Deleted \Answered) MODSEQ (12121231000)) 664 S: C180 OK Noop completed 666 (Session 3, authenticated as a user "andrew"). As \Deleted is a 667 shared flag, changes in session 1 are also reported in session 3: 669 C: D210 NOOP 670 S: * 7 FETCH (FLAGS (\Deleted \Answered) MODSEQ (12121231000)) 671 S: D210 OK Noop completed 673 The user modifies a private flag \Seen in session 1... 675 C: A240 STORE 7 +FLAGS.SILENT (\Seen) 676 S: * 7 FETCH (MODSEQ (12121231777)) 677 S: A240 OK Store completed 679 ...which is only reported in session 2... 681 C: C270 NOOP 682 S: * 7 FETCH (FLAGS (\Deleted \Answered \Seen) MODSEQ 683 (12121231777)) 684 S: C270 OK Noop completed 686 ...but not in session 3. 688 C: D300 NOOP 689 S: D300 OK Noop completed 691 And finally, the user removes flags \Answered (shared) and \Seen 692 (private) in session 1. 694 C: A330 STORE 7 -FLAGS.SILENT (\Answered \Seen) 695 S: * 7 FETCH (MODSEQ (12121245160)) 696 S: A330 OK Store completed 698 Both changes are reported in the session 2... 700 C: C360 NOOP 701 S: * 7 FETCH (FLAGS (\Deleted) MODSEQ (12121245160)) 702 S: C360 OK Noop completed 704 ...and only changes to shared flags are reported in session 3. 706 C: D390 NOOP 707 S: * 7 FETCH (FLAGS (\Deleted) MODSEQ (12121245160)) 708 S: D390 OK Noop completed 710 Example 14 712 Server implementers should also see Section 3.8 for additional 713 quality of implementation issues related to the FETCH command. 715 3.3.3. MODSEQ Search Criterion in SEARCH 717 The MODSEQ criterion for the SEARCH command allows a client to search 718 for the metadata items that were modified since a specified moment. 720 Syntax: MODSEQ [ ] 722 Messages that have modification values that are equal to or 723 greater than . This allows a client, for 724 example, to find out which messages contain metadata items that 725 have changed since the last time it updated its disconnected 726 cache. The client may also specify (name of metadata 727 item) and (type of metadata item) before . can be one of "shared", "priv" 729 (private), or "all". The latter means that the server should use 730 the biggest value among "priv" and "shared" mod- sequences for the 731 metadata item. If the server doesn't store internally separate 732 mod-sequences for different metadata items, it MUST ignore and . Otherwise, the server should use them 734 to narrow down the search. 736 For a flag , the corresponding has a form " 737 /flags/" as defined in [RFC4466]. Note that the leading 738 "\" character that denotes a system flag has to be escaped as per 739 Section 4.3 of [RFC3501], as the uses syntax for 740 quoted strings. 742 If client specifies a MODSEQ criterion in a SEARCH command and the 743 server returns a non-empty SEARCH result, the server MUST also append 744 (to the end of the untagged SEARCH response) the highest mod-sequence 745 for all messages being returned. See also Section 3.5. 747 C: a SEARCH MODSEQ "/flags/\\draft" all 620162338 748 S: * SEARCH 2 5 6 7 11 12 18 19 20 23 (MODSEQ 917162500) 749 S: a OK Search complete 751 In the above example, the message numbers of any messages containing 752 the string "IMAP4" in the "value" attribute of the "/comment" entry 753 and having a mod-sequence equal to or greater than 620162338 for the 754 "\Draft" flag are returned in the search results. 756 Example 15 758 C: t SEARCH OR NOT MODSEQ 720162338 LARGER 50000 759 S: * SEARCH 760 S: t OK Search complete, nothing found 762 Example 16 764 3.3.4. Modified SEARCH Untagged Response 766 Data: zero or more numbers 767 mod-sequence value (omitted if no match) 769 This document extends syntax of the untagged SEARCH response to 770 include the highest mod-sequence for all messages being returned. 772 If a client specifies a MODSEQ criterion in a SEARCH (or UID SEARCH) 773 command and the server returns a non-empty SEARCH result, the server 774 MUST also append (to the end of the untagged SEARCH response) the 775 highest mod-sequence for all messages being returned. See 776 Section 3.4 for examples. 778 3.3.5. HIGHESTMODSEQ Status Data Items 780 This document defines a new status data item: 782 HIGHESTMODSEQ The highest mod-sequence value of all messages in the 783 mailbox. This is the same value that is returned by the server in 784 the HIGHESTMODSEQ response code in an OK untagged response (see 785 Section 3.1.1). If the server doesn't support the persistent 786 storage of mod-sequences for the mailbox (see Section 3.1.2), the 787 server MUST return 0 as the value of HIGHESTMODSEQ status data 788 item. 790 C: A042 STATUS blurdybloop (UIDNEXT MESSAGES HIGHESTMODSEQ) 791 S: * STATUS blurdybloop (MESSAGES 231 UIDNEXT 44292 792 HIGHESTMODSEQ 7011231777) 793 S: A042 OK STATUS completed 795 Example 17 797 3.3.6. CONDSTORE Parameter to SELECT and EXAMINE 799 The CONDSTORE extension defines a single optional select parameter, 800 "CONDSTORE", which tells the server that it MUST include the MODSEQ 801 fetch response data items in all subsequent unsolicited FETCH 802 responses. 804 The CONDSTORE parameter to SELECT/EXAMINE helps avoid a race 805 condition that might arise when one or more metadata items are 806 modified in another session after the server has sent the 807 HIGHESTMODSEQ response code and before the client was able to issue a 808 CONDSTORE enabling command. 810 C: A142 SELECT INBOX (CONDSTORE) 811 S: * 172 EXISTS 812 S: * 1 RECENT 813 S: * OK [UNSEEN 12] Message 12 is first unseen 814 S: * OK [UIDVALIDITY 3857529045] UIDs valid 815 S: * OK [UIDNEXT 4392] Predicted next UID 816 S: * FLAGS (\Answered \Flagged \Deleted \Seen \Draft) 817 S: * OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited 818 S: * OK [HIGHESTMODSEQ 715194045007] 819 S: A142 OK [READ-WRITE] SELECT completed, CONDSTORE is now enabled 821 Example 18 823 3.3.7. Additional Quality-of-Implementation Issues 825 Server implementations should follow the following rule, which 826 applies to any successfully completed STORE/UID STORE (with and 827 without UNCHANGEDSINCE modifier), as well as to a FETCH command that 828 implicitly sets \Seen flag: 830 Adding the flag when it is already present or removing when it is 831 not present SHOULD NOT change the mod-sequence. 833 This will prevent spurious client synchronization requests. 835 However, note that client implementers MUST NOT rely on this server 836 behavior. A client can't distinguish between the case when a server 837 has violated the SHOULD mentioned above, and that when one or more 838 clients set and unset (or unset and set) the flag in another session. 840 4. Formal Syntax 842 The following syntax specification uses the Augmented Backus-Naur 843 Form (ABNF) [RFC5234] notation. Elements not defined here can be 844 found in the formal syntax of the ABNF [RFC5234], IMAP [RFC3501], and 845 IMAP ABNF extensions [RFC4466] specifications. 847 Except as noted otherwise, all alphabetic characters are case- 848 insensitive. The use of upper- or lowercase characters to define 849 token strings is for editorial clarity only. Implementations MUST 850 accept these strings in a case-insensitive fashion. 852 capability =/ "CONDSTORE" 854 status-att =/ "HIGHESTMODSEQ" 855 ;; extends non-terminal defined in RFC 3501. 857 status-att-val =/ "HIGHESTMODSEQ" SP mod-sequence-valzer 858 ;; extends non-terminal defined in [RFC4466]. 859 ;; Value 0 denotes that the mailbox doesn't 860 ;; support persistent mod-sequences 861 ;; as described in Section 3.1.2 863 store-modifier =/ "UNCHANGEDSINCE" SP mod-sequence-valzer 864 ;; Only a single "UNCHANGEDSINCE" may be 865 ;; specified in a STORE operation 867 fetch-modifier =/ chgsince-fetch-mod 868 ;; conforms to the generic "fetch-modifier" 869 ;; syntax defined in [RFC4466]. 871 chgsince-fetch-mod = "CHANGEDSINCE" SP mod-sequence-value 872 ;; CHANGEDSINCE FETCH modifier conforms to 873 ;; the fetch-modifier syntax 875 fetch-att =/ fetch-mod-sequence 876 ;; modifies original IMAP4 fetch-att 878 fetch-mod-sequence = "MODSEQ" 880 fetch-mod-resp = "MODSEQ" SP "(" permsg-modsequence ")" 882 msg-att-dynamic =/ fetch-mod-resp 884 search-key =/ search-modsequence 885 ;; modifies original IMAP4 search-key 886 ;; 887 ;; This change applies to all commands 888 ;; referencing this non-terminal, in 889 ;; particular SEARCH. 891 search-modsequence = "MODSEQ" [search-modseq-ext] SP 892 mod-sequence-valzer 894 search-modseq-ext = SP entry-name SP entry-type-req 896 resp-text-code =/ "HIGHESTMODSEQ" SP mod-sequence-value / 897 "NOMODSEQ" / 898 "MODIFIED" SP sequence-set 900 entry-name = entry-flag-name 902 entry-flag-name = DQUOTE "/flags/" attr-flag DQUOTE 903 ;; each system or user defined flag 904 ;; is mapped to "/flags/". 905 ;; 906 ;; follows the escape rules 907 ;; used by "quoted" string as described in 908 ;; Section 4.3 of [RFC3501], e.g., for the flag 909 ;; \Seen the corresponding is 910 ;; "/flags/\\seen", and for the flag 911 ;; $MDNSent, the corresponding 912 ;; is "/flags/$mdnsent". 914 entry-type-resp = "priv" / "shared" 915 ;; metadata item type 917 entry-type-req = entry-type-resp / "all" 918 ;; perform SEARCH operation on private 919 ;; metadata item, shared metadata item or both 921 permsg-modsequence = mod-sequence-value 922 ;; per message mod-sequence 924 mod-sequence-value = 1*DIGIT 925 ;; Positive unsigned 64-bit integer 926 ;; (mod-sequence) 927 ;; (1 <= n < 18,446,744,073,709,551,615) 929 mod-sequence-valzer = "0" / mod-sequence-value 931 search-sort-mod-seq = "(" "MODSEQ" SP mod-sequence-value ")" 933 select-param =/ condstore-param 934 ;; conforms to the generic "select-param" 935 ;; non-terminal syntax defined in [RFC4466]. 937 condstore-param = "CONDSTORE" 939 mailbox-data =/ "SEARCH" [1*(SP nz-number) SP 940 search-sort-mod-seq] 942 attr-flag = "\\Answered" / "\\Flagged" / "\\Deleted" / 943 "\\Seen" / "\\Draft" / attr-flag-keyword / 944 attr-flag-extension 945 ;; Does not include "\\Recent" 947 attr-flag-extension = "\\" atom 948 ;; Future expansion. Client implementations 949 ;; MUST accept flag-extension flags. Server 950 ;; implementations MUST NOT generate 951 ;; flag-extension flags except as defined by 952 ;; future standard or standards-track 953 ;; revisions of [RFC3501]. 955 attr-flag-keyword = atom 957 5. Server Implementation Considerations 959 This section describes how a server implementation that doesn't store 960 separate per-metadata mod-sequences for different metadata items can 961 avoid sending the MODIFIED response to any of the following 962 conditional STORE operations: 964 +FLAGS 966 -FLAGS 968 +FLAGS.SILENT 970 -FLAGS.SILENT 972 Note that the optimization described in this section can't be 973 performed in case of a conditional STORE FLAGS operation. 975 Let's use the following example. The client has issued 977 C: a106 STORE 100:150 (UNCHANGEDSINCE 212030000000) 978 +FLAGS.SILENT ($Processed) 980 When the server receives the command and parses it successfully, it 981 iterates through the message set and tries to execute the conditional 982 STORE command for each message. 984 Each server internally works as a client, i.e., it has to cache the 985 current state of all IMAP flags as it is known to the client. In 986 order to report flag changes to the client, the server compares the 987 cached values with the values in its database for IMAP flags. 989 Imagine that another client has changed the state of a flag \Deleted 990 on the message 101 and that the change updated the mod-sequence for 991 the message. The server knows that the mod-sequence for the mailbox 992 has changed; however, it also knows that: 994 a. the client is not interested in \Deleted flag, as it hasn't 995 included it in +FLAGS.SILENT operation; and 997 b. the state of the flag $Processed hasn't changed (the server can 998 determine this by comparing cached flag state with the state of 999 the flag in the database). 1001 Therefore, the server doesn't have to report MODIFIED to the client. 1002 Instead, the server may set $Processed flag, update the mod-sequence 1003 for the message 101 once again and send an untagged FETCH response 1004 with new mod-sequence and flags: 1006 S: * 101 FETCH (MODSEQ (303011130956) 1007 FLAGS ($Processed \Deleted \Answered)) 1009 See also Section 3.8 for additional quality-of-implementation issues. 1011 6. Security Considerations 1013 It is believed that the Conditional STORE extension doesn't raise any 1014 new security concerns that are not already discussed in [RFC3501]. 1015 However, the availability of this extension may make it possible for 1016 IMAP4 to be used in critical applications it could not be used for 1017 previously, making correct IMAP server implementation and operation 1018 even more important. 1020 7. IANA Considerations 1022 IMAP4 capabilities are registered by publishing a standards track or 1023 IESG approved experimental RFC. The registry is currently located 1024 at: 1026 http://www.iana.org/assignments/imap4-capabilities 1028 This document defines the CONDSTORE IMAP capability. IANA has added 1029 it to the registry accordingly. 1031 8. Acknowledgements 1033 Thank you to Steve Hole for co-editing RFC 4551. 1035 Thank you to Dave Cridland for helping to convert the original text 1036 RFC to xml2rfc format. 1038 Some text was borrowed from "IMAP ANNOTATE Extension" [RFC5257] by 1039 Randall Gellens and Cyrus Daboo and from "ACAP -- Application 1040 Configuration Access Protocol" [RFC2244] by Chris Newman and John 1041 Myers. 1043 Many thanks to Randall Gellens for his thorough review of the 1044 document. 1046 The authors also acknowledge the feedback provided by Cyrus Daboo, 1047 Larry Greenfield, Chris Newman, Harrie Hazewinkel, Arnt Gulbrandsen, 1048 Timo Sirainen, Mark Crispin, Ned Freed, Ken Murchison, and Dave 1049 Cridland. 1051 9. References 1053 9.1. Normative References 1055 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1056 Requirement Levels", BCP 14, RFC 2119, March 1997. 1058 [RFC3501] Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION 1059 4rev1", RFC 3501, March 2003. 1061 [RFC4466] Melnikov, A. and C. Daboo, "Collected Extensions to IMAP4 1062 ABNF", RFC 4466, April 2006. 1064 [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax 1065 Specifications: ABNF", STD 68, RFC 5234, January 2008. 1067 9.2. Informative References 1069 [RFC1305] Mills, D., "Network Time Protocol (Version 3) 1070 Specification, Implementation", RFC 1305, March 1992. 1072 [RFC2180] Gahrns, M., "IMAP4 Multi-Accessed Mailbox Practice", RFC 1073 2180, July 1997. 1075 [RFC2244] Newman, C. and J.G. Myers, "ACAP -- Application 1076 Configuration Access Protocol", RFC 2244, November 1997. 1078 [RFC4314] Melnikov, A., "IMAP4 Access Control List (ACL) Extension", 1079 RFC 4314, December 2005. 1081 [RFC5257] Daboo, C. and R. Gellens, "Internet Message Access 1082 Protocol - ANNOTATE Extension", RFC 5257, June 2008. 1084 Appendix A. Changes since RFC 4551 1086 Fixed errata 3401, 3506 and 3509. 1088 Updated references. 1090 Author's Address 1092 Alexey Melnikov 1093 Isode Ltd. 1094 5 Castle Business Village 1095 36 Station Road 1096 Hampton, Middlesex TW12 2BX 1097 UK 1099 Email: Alexey.Melnikov@isode.com