1
2
3
4
5
6
7Network Working Group D. Cridland
8Request for Comments: 5267 C. King
9Category: Standards Track Isode Limited
10 July 2008
11
12
13 Contexts for IMAP4
14
15Status of This Memo
16
17 This document specifies an Internet standards track protocol for the
18 Internet community, and requests discussion and suggestions for
19 improvements. Please refer to the current edition of the "Internet
20 Official Protocol Standards" (STD 1) for the standardization state
21 and status of this protocol. Distribution of this memo is unlimited.
22
23Abstract
24
25 The IMAP4rev1 protocol has powerful search facilities as part of the
26 core protocol, but lacks the ability to create live, updated results
27 that can be easily handled. This memo provides such an extension,
28 and shows how it can be used to provide a facility similar to virtual
29 mailboxes.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58Cridland & King Standards Track [Page 1]
59
60RFC 5267 IMAP CONTEXT July 2008
61
62
63Table of Contents
64
65 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 3
66 2. Conventions Used in This Document . . . . . . . . . . . . . . 3
67 3. Extended Sort Syntax . . . . . . . . . . . . . . . . . . . . . 3
68 3.1. ESORT Extension . . . . . . . . . . . . . . . . . . . . . 4
69 3.2. Ranges in Extended Sort Results . . . . . . . . . . . . . 4
70 3.3. Extended SORT Example . . . . . . . . . . . . . . . . . . 4
71 4. Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
72 4.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . 5
73 4.2. Context Hint . . . . . . . . . . . . . . . . . . . . . . . 5
74 4.3. Notifications of Changes . . . . . . . . . . . . . . . . . 6
75 4.3.1. Refusing to Update Contexts . . . . . . . . . . . . . 7
76 4.3.2. Common Features of ADDTO and REMOVEFROM . . . . . . . 8
77 4.3.3. ADDTO Return Data Item . . . . . . . . . . . . . . . . 8
78 4.3.4. REMOVEFROM Return Data Item . . . . . . . . . . . . . 9
79 4.3.5. The CANCELUPDATE Command . . . . . . . . . . . . . . . 10
80 4.4. Partial Results . . . . . . . . . . . . . . . . . . . . . 10
81 4.5. Caching Results . . . . . . . . . . . . . . . . . . . . . 11
82 5. Formal Syntax . . . . . . . . . . . . . . . . . . . . . . . . 12
83 6. Security Considerations . . . . . . . . . . . . . . . . . . . 13
84 7. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13
85 8. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 13
86 9. References . . . . . . . . . . . . . . . . . . . . . . . . . . 14
87 9.1. Normative References . . . . . . . . . . . . . . . . . . . 14
88 9.2. Informative References . . . . . . . . . . . . . . . . . . 14
89 Appendix A. Cookbook . . . . . . . . . . . . . . . . . . . . . . 15
90 A.1. Virtual Mailboxes . . . . . . . . . . . . . . . . . . . . 15
91 A.2. Trash Mailboxes . . . . . . . . . . . . . . . . . . . . . 15
92 A.3. Immediate EXPUNGE Notifications . . . . . . . . . . . . . 15
93 A.4. Monitoring Counts . . . . . . . . . . . . . . . . . . . . 15
94 A.5. Resynchronizing Contexts . . . . . . . . . . . . . . . . . 16
95 Appendix B. Server Implementation Notes . . . . . . . . . . . . . 16
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114Cridland & King Standards Track [Page 2]
115
116RFC 5267 IMAP CONTEXT July 2008
117
118
1191. Introduction
120
121 Although the basic SEARCH command defined in [IMAP], and as enhanced
122 by [ESEARCH], is relatively compact in its representation, this
123 reduction saves only a certain amount of data, and huge mailboxes
124 might overwhelm the storage available for results on even relatively
125 high-end desktop machines.
126
127 The SORT command defined in [SORT] provides useful features, but is
128 hard to use effectively on changing mailboxes over low-bandwidth
129 connections.
130
131 This memo borrows concepts from [ACAP], such as providing a windowed
132 view onto search or sort results, and making updates that are
133 bandwidth and round-trip efficient. These are provided by two
134 extensions: "ESORT" and "CONTEXT".
135
1362. Conventions Used in This Document
137
138 In examples, "C:" and "S:" indicate lines sent by the client
139 messaging user agent and IMAP4rev1 ([IMAP]) server, respectively.
140 "//" indicates inline comments not part of the protocol exchange.
141 Line breaks are liberally inserted for clarity. Examples are
142 intended to be read in order, such that the state remains from one
143 example to the next.
144
145 Although the examples show a server that supports [ESEARCH], this is
146 not a strict requirement of this specification.
147
148 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
149 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
150 document are to be interpreted as described in [KEYWORDS].
151
152 Other capitalized words are typically names of IMAP extensions or
153 commands -- these are uppercased for clarity only, and are case-
154 insensitive.
155
1563. Extended Sort Syntax
157
158 Servers implementing the extended SORT provide a suite of extensions
159 to the SORT and UID SORT commands defined in [SORT]. This allows for
160 return options, as used with SEARCH and specified in [IMAP-ABNF], to
161 be used with SORT in a similar manner.
162
163 The SORT and UID SORT commands are extended by the addition of an
164 optional list of return options that follow a RETURN atom immediately
165 after the command. If this is missing, the server will return
166 results as specified in [SORT].
167
168
169
170Cridland & King Standards Track [Page 3]
171
172RFC 5267 IMAP CONTEXT July 2008
173
174
175 The extended SORT command always returns results in the requested
176 sort order, but is otherwise identical in its behaviour to the
177 extended SEARCH command defined in [IMAP-ABNF], as extended by
178 [ESEARCH]. In particular, the extended SORT command returns results
179 in an ESEARCH response.
180
1813.1. ESORT Extension
182
183 Servers advertising the capability "ESORT" support the return options
184 specified in [ESEARCH] in the SORT command. These return options are
185 adapted as follows:
186
187 MIN
188 Return the message number/UID of the lowest sorted message
189 satisfying the search criteria.
190
191 MAX
192 Return the message number/UID of the highest sorted message
193 satisfying the search criteria.
194
195 ALL
196 Return all message numbers/UIDs which match the search criteria,
197 in the requested sort order, using a sequence-set. Note the use
198 of ranges described below in Section 3.2.
199
200 COUNT
201 As in [ESEARCH].
202
2033.2. Ranges in Extended Sort Results
204
205 Any ranges given by the server, including those given as part of the
206 sequence-set, in an ESEARCH response resulting from an extended SORT
207 or UID SORT command, MUST be ordered in increasing numerical order
208 after expansion, as per usual [IMAP] rules.
209
210 In particular this means that 10:12 is equivalent to 12:10, and
211 10,11,12. To avoid confusion, servers SHOULD present ranges only
212 when the first seq-number is lower than the second; that is, either
213 of the forms 10:12 or 10,11,12 is acceptable, but 12:10 SHOULD be
214 avoided.
215
2163.3. Extended SORT Example
217
218 If the list of return options is present but empty, then the server
219 provides the ALL return data item in an ESEARCH response. This is
220 functionally equivalent to an unextended UID SORT command, but can
221 use a smaller representation:
222
223
224
225
226Cridland & King Standards Track [Page 4]
227
228RFC 5267 IMAP CONTEXT July 2008
229
230
231 C: E01 UID SORT RETURN () (REVERSE DATE) UTF-8 UNDELETED
232 UNKEYWORD $Junk
233 S: * ESEARCH (TAG "E01") UID ALL 23765,23764,23763,23761,[...]
234 S: E01 OK Sort completed
235
236 Note that the initial three results are not represented as the range
237 23765:23763 as mandated in Section 3.2.
238
2394. Contexts
240
2414.1. Overview
242
243 The Contexts extension is present in any IMAP4rev1 server that
244 includes the string "CONTEXT=SEARCH", and/or "CONTEXT=SORT", within
245 its advertised capabilities.
246
247 In the case of CONTEXT=SEARCH, the server supports the extended
248 SEARCH command syntax described in [IMAP-ABNF], and accepts three
249 additional return options.
250
251 Servers advertising CONTEXT=SORT also advertise the SORT capability,
252 as described in [SORT], support the extended SORT command syntax
253 described in Section 3, and accept three additional return options
254 for this extended SORT.
255
256 These additional return options allow for notifications of changes to
257 the results of SEARCH or SORT commands, and also allow for access to
258 partial results.
259
260 A server advertising the CONTEXT=SEARCH extension will order all
261 SEARCH results, whether from a UID SEARCH or SEARCH command, in
262 mailbox order -- that is, by message number and UID. Therefore, the
263 UID SEARCH, SEARCH, UID SORT, or SORT command used -- collectively
264 known as the searching command -- will always have an order, the
265 requested order, which will be the mailbox order for UID SEARCH and
266 SEARCH commands.
267
268 All of the return specifiers have no interaction with either each
269 other or any return specifiers defined in [ESEARCH] or Section 3.1;
270 however, it is believed that implementations supporting CONTEXT will
271 also support ESEARCH and ESORT.
272
2734.2. Context Hint
274
275 The return option CONTEXT SHOULD be used by a client to indicate that
276 subsequent use of the search criteria are likely. Servers MAY ignore
277 this return option or use it as a hint to maintain a full result
278 cache, or index.
279
280
281
282Cridland & King Standards Track [Page 5]
283
284RFC 5267 IMAP CONTEXT July 2008
285
286
287 A client might choose to obtain a count of matching messages prior to
288 obtaining actual results. Here, the client signals its intention to
289 fetch the results themselves:
290
291 C: A01 SEARCH RETURN (CONTEXT COUNT) UNDELETED
292 UNKEYWORD $Junk
293 S: * ESEARCH (TAG "A01") COUNT 23765
294 S: A01 OK Search completed.
295
2964.3. Notifications of Changes
297
298 The search return option UPDATE, if used by a client, causes the
299 server to issue unsolicited notifications containing updates to the
300 results that would be returned by an unmodified searching command.
301 These update sets are carried in ADDTO and REMOVEFROM data items in
302 ESEARCH responses.
303
304 These ESEARCH responses carry a search correlator of the searching
305 command, hence clients MUST NOT reuse tags, as already specified in
306 Section 2.2.1 of [IMAP]. An attempt to use UPDATE where a tag is
307 already in use with a previous searching command that itself used
308 UPDATE SHALL result in the server rejecting the searching command
309 with a BAD response.
310
311 Both ADDTO and REMOVEFROM data items SHOULD be delivered to clients
312 in a timely manner, as and when results change, whether by new
313 messages arriving in the mailbox, metadata such as flags being
314 changed, or messages being expunged.
315
316 Typically, this would occur at the same time as the FETCH, EXISTS, or
317 EXPUNGE responses carrying the source of the change.
318
319 Updates will cease when the mailbox is no longer selected, or when
320 the CANCELUPDATE command, defined in Section 4.3.5, is issued by the
321 client, whichever is sooner.
322
323 Unlike [ACAP], there is no requirement that a context need be created
324 with CONTEXT to use UPDATE, and in addition, the lack of UPDATE with
325 a CONTEXT does not affect the results caused by later searching
326 commands -- there is no snapshot facility.
327
328 There is no interaction between UPDATE and any other return options;
329 therefore, use of RETURN (UPDATE MIN), for example, does not notify
330 about the minimum UID or sequence number, but notifies instead about
331 all changes to the set of matching messages. In particular, this
332 means that a client using UPDATE and PARTIAL on the same search
333 program could receive notifications about messages that do not
334 currently interest it.
335
336
337
338Cridland & King Standards Track [Page 6]
339
340RFC 5267 IMAP CONTEXT July 2008
341
342
343 Finally, as specified in the errata to [IMAP], any message sequence
344 numbers used in the search program are evaluated at the time the
345 command is received; therefore, if the messages referred to by such
346 message sequence numbers change, no notifications will be emitted.
347
348 This time, the client will require notifications of updates and
349 chooses to obtain a count:
350
351 C: B01 UID SEARCH RETURN (UPDATE COUNT) DELETED
352 KEYWORD $Junk
353 S: * ESEARCH (TAG "B01") COUNT 74
354 S: B01 OK Search completed, will notify.
355 // Note that the following is rejected, and has no effect:
356 C: B01 SORT RETURN (UPDATE) FLAGGED
357 S: B01 BAD Tag reuse
358
3594.3.1. Refusing to Update Contexts
360
361 In some cases, the server MAY refuse to provide updates, such as if
362 an internal limit on the number of update contexts is reached. In
363 such a case, an untagged NO is generated during processing of the
364 command with a response-code of NOUPDATE. The response-code
365 contains, as argument, the tag of the search command for which the
366 server is refusing to honour the UPDATE request.
367
368 Other return options specified SHALL still be honoured.
369
370 Servers MUST provide at least one updating context per client, and
371 SHOULD provide more -- see Appendix B for strategies on reducing the
372 impact of additional updating contexts. Since sorted contexts
373 require a higher implementation cost than unsorted contexts, refusal
374 to provide updates for a SORT command does not imply that SEARCH
375 contexts will also be refused.
376
377 This time, the client will require notifications of updates, and
378 chooses to obtain a count:
379
380 C: B02 UID SORT RETURN (UPDATE COUNT) UTF-8
381 KEYWORD $Junk
382 S: * ESEARCH (TAG "B02") COUNT 74
383 S: * NO [NOUPDATE "B02"] Too many contexts
384 S: B02 OK Search completed, will not notify.
385
386 Client handling might be to retry with a UID SEARCH command, or else
387 cancel an existing context; see Section 4.3.5.
388
389
390
391
392
393
394Cridland & King Standards Track [Page 7]
395
396RFC 5267 IMAP CONTEXT July 2008
397
398
3994.3.2. Common Features of ADDTO and REMOVEFROM
400
401 The result update set included in the return data item is specified
402 as UIDs or message numbers, depending on how the UPDATE was
403 specified. If the UPDATE was present in a SEARCH or SORT command,
404 the results will be message numbers; in a UID SEARCH or UID SORT
405 command, they will be UIDs.
406
407 The client MUST process ADDTO and REMOVEFROM return data items in the
408 order they appear, including those within a single ESEARCH response.
409 Correspondingly, servers MUST generate ADDTO and REMOVEFROM responses
410 such that the results are maintained in the requested order.
411
412 As with any response aside from EXPUNGE, ESEARCH responses carrying
413 ADDTO and/or REMOVEFROM return data items MAY be sent at any time.
414 In particular, servers MAY send such responses when no command is in
415 progress, during the processing of any command, or when the client is
416 using the IDLE facility described in [IDLE]. Implementors are
417 recommended to read [NOTIFY] as a mechanism for clients to signal
418 servers that they are willing to process responses at any time, and
419 are also recommended to pay close attention to Section 5.3 of [IMAP].
420
421 It is anticipated that typical server implementations will emit ADDTO
422 when they normally emit the causal FETCH or EXISTS, and similarly
423 emit REMOVEFROM when they normally emit the causal FETCH or EXPUNGE.
424
4254.3.3. ADDTO Return Data Item
426
427 The ADDTO return data item contains, as payload, a list containing
428 pairs of a context position and a set of result updates in the
429 requested order to be inserted at the context position. Where the
430 searching command is a SEARCH or UID SEARCH command, the context
431 position MAY be zero. Each pair is processed in the order that it
432 appears.
433
434 Note that an ADDTO containing message sequence numbers added as a
435 result of those messages being delivered or appended MUST be sent
436 after the EXISTS notification itself, in order that those sequence
437 numbers are valid.
438
439 If the context position is non-zero, the result update is inserted at
440 the given context position, meaning that the first result in the set
441 will occupy the new context position after insertion, and any prior
442 existing result at that context position will be shifted to a later
443 context position.
444
445
446
447
448
449
450Cridland & King Standards Track [Page 8]
451
452RFC 5267 IMAP CONTEXT July 2008
453
454
455 Where the context position is zero, the client MAY insert the message
456 numbers or UIDs in the result list such that the result list is
457 maintained in mailbox order. In this case, servers are RECOMMENDED
458 to order the result update into mailbox order to produce the shortest
459 representation in set-syntax.
460
461 [...]
462 S: * 23762 FETCH (FLAGS (\Deleted \Seen))
463 S: * 23763 FETCH (FLAGS ($Junk \Seen))
464 S: * ESEARCH (TAG "B01") UID ADDTO (0 32768:32769)
465
466 Note that this example assumes messages 23762 and 23763 with UIDs
467 32768 and 32769 (respectively) previously had neither \Deleted nor
468 $Junk set. Also note that only the ADDTO is included, and not the
469 (now changed) COUNT.
470
471 If the searching command "C01" initially generated a result list of
472 2734:2735, then the following three responses are equivalent, and
473 yield a result list of 2731:2735:
474
475 [...]
476 S: * ESEARCH (TAG "C01") UID ADDTO (1 2733 1 2732 1 2731)
477 S: * ESEARCH (TAG "C01") UID ADDTO (1 2733) ADDTO (1 2731:2732)
478 S: * ESEARCH (TAG "C01") UID ADDTO (1 2731:2733)
479
480 The last is the preferred representation.
481
4824.3.4. REMOVEFROM Return Data Item
483
484 The REMOVEFROM return data item contains, as payload, a list
485 containing pairs of a context position and a set of result updates in
486 the requested order to be removed starting from the context position.
487 Where the searching command is a SEARCH or UID SEARCH command, the
488 context position MAY be zero. Each pair is processed in the order
489 that it appears.
490
491 If the context position is non-zero, the results are removed at the
492 given context position, meaning that the first result in the set will
493 occupy the given context position before removal, and any prior
494 existing result at that context position will be shifted to an
495 earlier context position.
496
497 Where the context position is zero, the client removes the message
498 numbers or UIDs in the result list wherever they occur, and servers
499 are RECOMMENDED to order the result list in mailbox order to obtain
500 the best benefit from the set-syntax.
501
502
503
504
505
506Cridland & King Standards Track [Page 9]
507
508RFC 5267 IMAP CONTEXT July 2008
509
510
511 Note that a REMOVEFROM containing message sequence numbers removed as
512 a result of those messages being expunged MUST be sent prior to the
513 expunge notification itself, in order that those sequence numbers
514 remain valid.
515
516 Here, a message in the result list is expunged. The REMOVEFROM is
517 shown to happen without any command in progress; see Section 4.3.2.
518 Note that EXPUNGE responses do not have this property.
519
520 [...]
521 S: * ESEARCH (TAG "B01") UID REMOVEFROM (0 32768)
522 C: B03 NOOP
523 S: * 23762 EXPUNGE
524 S: B03 OK Nothing done.
525
5264.3.5. The CANCELUPDATE Command
527
528 When a client no longer wishes to receive updates, it may issue the
529 CANCELUPDATE command, which will prevent all updates to the contexts
530 named in the arguments from being transmitted by the server. The
531 command takes, as arguments, one or more tags of the commands used to
532 request updates.
533
534 The server MAY free any resource associated with a context so
535 disabled -- however, the client is free to issue further searching
536 commands with the same criteria and requested order, including
537 PARTIAL requests.
538
539 C: B04 CANCELUPDATE "B01"
540 S: B04 OK No further updates.
541
5424.4. Partial Results
543
544 The PARTIAL search return option causes the server to provide in an
545 ESEARCH response a subset of the results denoted by the sequence
546 range given as the mandatory argument. The first result is 1; thus,
547 the first 500 results would be obtained by a return option of
548 "PARTIAL 1:500", and the second 500 by "PARTIAL 501:1000". This
549 intentionally mirrors message sequence numbers.
550
551 A single command MUST NOT contain more than one PARTIAL or ALL search
552 return option -- that is, either one PARTIAL, one ALL, or neither
553 PARTIAL nor ALL is allowed.
554
555 For SEARCH results, the entire result list MUST be ordered in mailbox
556 order, that is, in UID or message sequence number order.
557
558
559
560
561
562Cridland & King Standards Track [Page 10]
563
564RFC 5267 IMAP CONTEXT July 2008
565
566
567 Where a PARTIAL search return option references results that do not
568 exist, by using a range which starts or ends higher than the current
569 number of results, then the server returns the results that are in
570 the set. This yields a PARTIAL return data item that has, as
571 payload, the original range and a potentially missing set of results
572 that may be shorter than the extent of the range.
573
574 Clients need not request PARTIAL results in any particular order.
575 Because mailboxes may change, clients will often wish to use PARTIAL
576 in combination with UPDATE, especially if the intent is to walk a
577 large set of results; however, these return options do not interact
578 -- the UPDATE will provide notifications for all matching results.
579
580 // Recall from A01 that there are 23764 results.
581 C: A02 UID SEARCH RETURN (PARTIAL 23500:24000) UNDELETED
582 UNKEYWORD $Junk
583 C: A03 UID SEARCH RETURN (PARTIAL 1:500) UNDELETED
584 UNKEYWORD $Junk
585 C: A04 UID SEARCH RETURN (PARTIAL 24000:24500) UNDELETED
586 UNKEYWORD $Junk
587 S: * ESEARCH (TAG "A02") UID PARTIAL (23500:24000 ...)
588 // 264 results in set syntax elided,
589 // this spans the end of the results.
590 S: A02 OK Completed.
591 S: * ESEARCH (TAG "A03") UID PARTIAL (1:500 ...)
592 // 500 results in set syntax elided.
593 S: A03 OK Completed.
594 S: * ESEARCH (TAG "A04") UID PARTIAL (24000:24500 NIL)
595 // No results are present, this is beyond the end of the results.
596 S: A04 OK Completed.
597
5984.5. Caching Results
599
600 Server implementations MAY cache results from a SEARCH or SORT,
601 whether or not hinted to by CONTEXT, in order to make subsequent
602 searches more efficient, perhaps by recommencing a subsequent PARTIAL
603 search where a previous search left off. However, servers MUST
604 behave identically whether or not internal caching is taking place;
605 therefore, any such cache is required to be updated as changes to the
606 mailbox occur. An alternate strategy would be to discard results
607 when any change occurs to the mailbox.
608
609
610
611
612
613
614
615
616
617
618Cridland & King Standards Track [Page 11]
619
620RFC 5267 IMAP CONTEXT July 2008
621
622
6235. Formal Syntax
624
625 The collected formal syntax. This uses ABNF as defined in [ABNF].
626 It includes definitions from [IMAP], [IMAP-ABNF], and [SORT].
627
628 capability =/ "CONTEXT=SEARCH" / "CONTEXT=SORT" / "ESORT"
629 ;; <capability> from [IMAP]
630
631 command-select =/ "CANCELUPDATE" 1*(SP quoted)
632 ;; <command-select> from [IMAP]
633
634 context-position = number
635 ;; Context position may be 0 for SEARCH result additions.
636 ;; <number> from [IMAP]
637
638 modifier-context = "CONTEXT"
639
640 modifier-partial = "PARTIAL" SP partial-range
641
642 partial-range = nz-number ":" nz-number
643 ;; A range 500:400 is the same as 400:500.
644 ;; This is similar to <seq-range> from [IMAP],
645 ;; but cannot contain "*".
646
647 modifier-update = "UPDATE"
648
649 search-return-opt =/ modifier-context / modifier-partial /
650 modifier-update
651 ;; All conform to <search-return-opt>, from [IMAP-ABNF]
652
653 resp-text-code =/ "NOUPDATE" SP quoted
654 ;; <resp-text-code> from [IMAP]
655
656 ret-data-addto = "ADDTO"
657 SP "(" context-position SP sequence-set
658 *(SP context-position SP sequence-set)
659 ")"
660 ;; <sequence-set> from [IMAP]
661
662 ret-data-partial = "PARTIAL"
663 SP "(" partial-range SP partial-results ")"
664 ;; <partial-range> is the requested range.
665
666 partial-results = sequence-set / "NIL"
667 ;; <sequence-set> from [IMAP]
668 ;; NIL indicates no results correspond to the requested range.
669
670
671
672
673
674Cridland & King Standards Track [Page 12]
675
676RFC 5267 IMAP CONTEXT July 2008
677
678
679 ret-data-removefrom = "REMOVEFROM"
680 SP "(" context-position SP sequence-set
681 *(SP context-position SP sequence-set)
682 ")"
683 ;; <sequence-set> from [IMAP]
684
685 search-return-data =/ ret-data-partial / ret-data-addto /
686 ret-data-removefrom
687 ;; All conform to <search-return-data>, from [IMAP-ABNF]
688
689 sort =/ extended-sort
690 ;; <sort> from [SORT]
691
692 extended-sort = ["UID" SP] "SORT" search-return-opts
693 SP sort-criteria SP search-criteria
694 ;; <search-return-opts> from [IMAP-ABNF]
695 ;; <sort-criteria> and <search-criteria> from [SORT]
696
6976. Security Considerations
698
699 This document defines additional IMAP4 capabilities. As such, it
700 does not change the underlying security considerations of [IMAP].
701 The authors and reviewers believe that no new security issues are
702 introduced with these additional IMAP4 capabilities.
703
704 Creation of a large number of contexts may provide an avenue for
705 denial-of-service attacks by authorized users. Implementors may
706 reduce this by limiting the number of contexts possible to create,
707 via the protocol features described in Section 4.3.1; by reducing the
708 impact of contexts by the implementation strategies described in
709 Appendix B; and by logging context creation and usage so that
710 administrative remedies may be applied.
711
7127. IANA Considerations
713
714 IMAP4 capabilities are registered by publishing a Standards Track or
715 IESG-approved Experimental RFC.
716
717 This document defines the ESORT, CONTEXT=SEARCH, and CONTEXT=SORT
718 IMAP capabilities. IANA has added them to the registry accordingly.
719
7208. Acknowledgements
721
722 Much of the design of this extension can be found in ACAP. Valuable
723 comments, both in agreement and in dissent, were received from Alexey
724 Melnikov, Arnt Gulbrandsen, Cyrus Daboo, Filip Navara, Mark Crispin,
725 Peter Coates, Philip Van Hoof, Randall Gellens, Timo Sirainen, Zoltan
726
727
728
729
730Cridland & King Standards Track [Page 13]
731
732RFC 5267 IMAP CONTEXT July 2008
733
734
735 Ordogh, and others, and many of these comments have had significant
736 influence on the design or the text. The authors are grateful to all
737 those involved, including those not mentioned here.
738
7399. References
740
7419.1. Normative References
742
743 [ABNF] Crocker, D. and P. Overell, "Augmented BNF for Syntax
744 Specifications: ABNF", STD 68, RFC 5234, January 2008.
745
746 [ESEARCH] Melnikov, A. and D. Cridland, "IMAP4 Extension to SEARCH
747 Command for Controlling What Kind of Information Is
748 Returned", RFC 4731, November 2006.
749
750 [IMAP] Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION
751 4rev1", RFC 3501, March 2003.
752
753 [IMAP-ABNF] Melnikov, A. and C. Daboo, "Collected Extensions to
754 IMAP4 ABNF", RFC 4466, April 2006.
755
756 [KEYWORDS] Bradner, S., "Key words for use in RFCs to Indicate
757 Requirement Levels", BCP 14, RFC 2119, March 1997.
758
759 [SORT] Crispin, M. and K. Murchison, "Internet Message Access
760 Protocol - SORT and THREAD Extensions", RFC 5256,
761 June 2008.
762
7639.2. Informative References
764
765 [ACAP] Newman, C. and J. Myers, "ACAP -- Application
766 Configuration Access Protocol", RFC 2244, November 1997.
767
768 [IDLE] Leiba, B., "IMAP4 IDLE command", RFC 2177, June 1997.
769
770 [NOTIFY] Melnikov, A., Gulbrandsen, A., and C. King, "The IMAP
771 NOTIFY Extension", Work in Progress, March 2008.
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786Cridland & King Standards Track [Page 14]
787
788RFC 5267 IMAP CONTEXT July 2008
789
790
791Appendix A. Cookbook
792
793A.1. Virtual Mailboxes
794
795 It is possible to use the facilities described within this memo to
796 create a facility largely similar to a virtual mailbox, but handled
797 on the client side.
798
799 Initially, the client SELECTs the real "backing" mailbox. Next, it
800 can switch to a filtered view at any time by issuing a RETURN (COUNT
801 UPDATE CONTEXT), and using RETURN (PARTIAL x:y) as the user scrolls,
802 feeding the results into a FETCH as required to populate summary
803 views.
804
805 A typically useful view is "UID SORT (DATE) RETURN (...) UTF-8
806 UNSEEN UNDELETED", which can be used to show the mailbox sorted into
807 INTERNALDATE order, filtered to only show messages which are unread
808 and not yet deleted.
809
810A.2. Trash Mailboxes
811
812 Certain contexts are particularly useful for client developers
813 wishing to present something similar to the common trash mailbox
814 metaphor in limited bandwidth. The simple criteria of UNDELETED only
815 matches undeleted messages, and the corresponding DELETED search key
816 can be used to display a per-mailbox trash-like virtual mailbox.
817
818A.3. Immediate EXPUNGE Notifications
819
820 The command "SEARCH RETURN (UPDATE) ALL" can be used to create a
821 context that notifies immediately about expunged messages, yet will
822 not affect message sequence numbers until the normal EXPUNGE message
823 can be sent. This may be useful for clients wishing to show this
824 behavior without losing the benefit of sequence numbering.
825
826A.4. Monitoring Counts
827
828 A client need not maintain any result cache at all, but instead it
829 can maintain a simple count of messages matching the search criteria.
830 Typically, this would use the SEARCH command, as opposed to UID
831 SEARCH, due to its smaller representation. Such usage might prove
832 useful in monitoring the number of flagged, but unanswered, messages,
833 for example, with "SEARCH RETURN (UPDATE COUNT) FLAGGED UNANSWERED".
834
835
836
837
838
839
840
841
842Cridland & King Standards Track [Page 15]
843
844RFC 5267 IMAP CONTEXT July 2008
845
846
847A.5. Resynchronizing Contexts
848
849 The creation of a context, and immediate access to it, can all be
850 accomplished in a single round-trip. Therefore, whilst it is
851 possible to elide resynchronization if no changes have occurred, it
852 is simpler in most cases to resynchronize by simply recreating the
853 context.
854
855Appendix B. Server Implementation Notes
856
857 Although a server may cache the results, this is neither mandated nor
858 required, especially when the client uses SEARCH or UID SEARCH
859 commands. UPDATE processing, for example, can be achieved
860 efficiently by comparison of the old flag state (if any) and the new,
861 and PARTIAL can be achieved by re-running the search until the
862 suitable window is required. This is a result of there being no
863 snapshot facility.
864
865 For example, on a new message, the server can simply test for matches
866 against all current UPDATE context search programs, and for any that
867 match, send the ADDTO return data.
868
869 Similarly, for a flag change on an existing message, the server can
870 check whether the message matched with its old flags, whether it
871 matches with new flags, and provide ADDTO or REMOVEFROM return data
872 accordingly if these results differ.
873
874 For PARTIAL requests, the server can perform a full search,
875 discarding results until the lower bound is hit, and stopping the
876 search when sufficient results have been obtained.
877
878 With some additional state, it is possible to restart PARTIAL
879 searches, thus avoiding performing the initial discard phase.
880
881 For the best performance, however, caching the full search results is
882 needed, which can allow for faster responses at the expense of
883 memory. One reasonable strategy would be to balance this trade-off
884 at run-time, discarding search results after a suitable timeout, and
885 regenerating them as required.
886
887 This yields state requirements of storing the search program for any
888 UPDATE contexts, and optionally storing both search program and
889 (updated) results for further contexts as required.
890
891
892
893
894
895
896
897
898Cridland & King Standards Track [Page 16]
899
900RFC 5267 IMAP CONTEXT July 2008
901
902
903 Note that in the absence of a server-side results cache, it may be
904 impossible to know if an expunged message previously matched unless
905 the original message is still available. Therefore, some
906 implementations may be forced into using a results cache in many
907 circumstances.
908
909 UPDATE contexts created with SORT or UID SORT will almost certainly
910 require some form of results caching, however.
911
912Authors' Addresses
913
914 Dave Cridland
915 Isode Limited
916 5 Castle Business Village
917 36, Station Road
918 Hampton, Middlesex TW12 2BX
919 GB
920
921 EMail: dave.cridland@isode.com
922
923
924 Curtis King
925 Isode Limited
926 5 Castle Business Village
927 36, Station Road
928 Hampton, Middlesex TW12 2BX
929 GB
930
931 EMail: cking@mumbo.ca
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954Cridland & King Standards Track [Page 17]
955
956RFC 5267 IMAP CONTEXT July 2008
957
958
959Full Copyright Statement
960
961 Copyright (C) The IETF Trust (2008).
962
963 This document is subject to the rights, licenses and restrictions
964 contained in BCP 78, and except as set forth therein, the authors
965 retain all their rights.
966
967 This document and the information contained herein are provided on an
968 "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS
969 OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND
970 THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS
971 OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF
972 THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED
973 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
974
975Intellectual Property
976
977 The IETF takes no position regarding the validity or scope of any
978 Intellectual Property Rights or other rights that might be claimed to
979 pertain to the implementation or use of the technology described in
980 this document or the extent to which any license under such rights
981 might or might not be available; nor does it represent that it has
982 made any independent effort to identify any such rights. Information
983 on the procedures with respect to rights in RFC documents can be
984 found in BCP 78 and BCP 79.
985
986 Copies of IPR disclosures made to the IETF Secretariat and any
987 assurances of licenses to be made available, or the result of an
988 attempt made to obtain a general license or permission for the use of
989 such proprietary rights by implementers or users of this
990 specification can be obtained from the IETF on-line IPR repository at
991 http://www.ietf.org/ipr.
992
993 The IETF invites any interested party to bring to its attention any
994 copyrights, patents or patent applications, or other proprietary
995 rights that may cover technology that may be required to implement
996 this standard. Please address the information to the IETF at
997 ietf-ipr@ietf.org.
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010Cridland & King Standards Track [Page 18]
1011
1012