rfc6237.IMAP4_Multimailbox_SEARCH_extension.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. Internet Engineering Task Force (IETF) B. Leiba
  2. Request for Comments: 6237 Huawei Technologies
  3. Updates: 4466 A. Melnikov
  4. Category: Experimental Isode Limited
  5. ISSN: 2070-1721 May 2011
  6. IMAP4 Multimailbox SEARCH Extension
  7. Abstract
  8. The IMAP4 specification allows the searching of only the selected
  9. mailbox. A user often wants to search multiple mailboxes, and a
  10. client that wishes to support this must issue a series of SELECT and
  11. SEARCH commands, waiting for each to complete before moving on to the
  12. next. This extension allows a client to search multiple mailboxes
  13. with one command, limiting the round trips and waiting for various
  14. searches to complete, and not requiring disruption of the currently
  15. selected mailbox. This extension also uses MAILBOX and TAG fields in
  16. ESEARCH responses, allowing a client to pipeline the searches if it
  17. chooses. This document updates RFC 4466.
  18. Status of This Memo
  19. This document is not an Internet Standards Track specification; it is
  20. published for examination, experimental implementation, and
  21. evaluation.
  22. This document defines an Experimental Protocol for the Internet
  23. community. This document is a product of the Internet Engineering
  24. Task Force (IETF). It represents the consensus of the IETF
  25. community. It has received public review and has been approved for
  26. publication by the Internet Engineering Steering Group (IESG). Not
  27. all documents approved by the IESG are a candidate for any level of
  28. Internet Standard; see Section 2 of RFC 5741.
  29. Information about the current status of this document, any errata,
  30. and how to provide feedback on it may be obtained at
  31. http://www.rfc-editor.org/info/rfc6237.
  32. Leiba & Melnikov Experimental [Page 1]
  33. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  34. Copyright Notice
  35. Copyright (c) 2011 IETF Trust and the persons identified as the
  36. document authors. All rights reserved.
  37. This document is subject to BCP 78 and the IETF Trust's Legal
  38. Provisions Relating to IETF Documents
  39. (http://trustee.ietf.org/license-info) in effect on the date of
  40. publication of this document. Please review these documents
  41. carefully, as they describe your rights and restrictions with respect
  42. to this document. Code Components extracted from this document must
  43. include Simplified BSD License text as described in Section 4.e of
  44. the Trust Legal Provisions and are provided without warranty as
  45. described in the Simplified BSD License.
  46. Table of Contents
  47. 1. Introduction ....................................................2
  48. 1.1. Conventions Used in This Document ..........................3
  49. 2. New ESEARCH Command .............................................3
  50. 2.1. The ESEARCH Response .......................................4
  51. 2.2. Source Options: Specifying Mailboxes to Search .............5
  52. 3. Examples ........................................................6
  53. 4. Formal Syntax ...................................................7
  54. 5. Security Considerations .........................................8
  55. 6. IANA Considerations .............................................9
  56. 7. Acknowledgements ................................................9
  57. 8. Normative References ............................................9
  58. 1. Introduction
  59. The IMAP4 specification allows the searching of only the selected
  60. mailbox. A user often wants to search multiple mailboxes, and a
  61. client that wishes to support this must issue a series of SELECT and
  62. SEARCH commands, waiting for each to complete before moving on to the
  63. next. The commands can't be pipelined, because the server might run
  64. them in parallel, and the untagged SEARCH responses could not then be
  65. distinguished from each other.
  66. This extension allows a client to search multiple mailboxes with one
  67. command, and includes MAILBOX and TAG fields in the ESEARCH response,
  68. yielding the following advantages:
  69. o A single command limits the number of round trips needed to search
  70. a set of mailboxes.
  71. o A single command eliminates the need to wait for one search to
  72. complete before starting the next.
  73. Leiba & Melnikov Experimental [Page 2]
  74. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  75. o A single command allows the server to optimize the search, if it
  76. can.
  77. o A command that is not dependent upon the selected mailbox
  78. eliminates the need to disrupt the selection state or to open
  79. another IMAP connection.
  80. o The MAILBOX, UIDVALIDITY, and TAG fields in the responses allow a
  81. client to distinguish which responses go with which search (and
  82. which mailbox). A client can safely pipeline these search
  83. commands without danger of confusion. The addition of the MAILBOX
  84. and UIDVALIDITY fields updates the search-correlator item defined
  85. in [RFC4466].
  86. 1.1. Conventions Used in This Document
  87. In examples, "C:" indicates lines sent by a client that is connected
  88. to a server. "S:" indicates lines sent by the server to the client.
  89. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
  90. "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
  91. document are to be interpreted as described in RFC 2119 [RFC2119].
  92. 2. New ESEARCH Command
  93. Arguments: OPTIONAL source options
  94. OPTIONAL result options
  95. OPTIONAL charset specification (see [RFC2978])
  96. searching criteria (one or more)
  97. Responses: REQUIRED untagged response: ESEARCH
  98. Result: OK -- search completed
  99. NO -- error: cannot search that charset or criteria
  100. BAD -- command unknown or arguments invalid
  101. This section defines a new ESEARCH command, which works similarly to
  102. the UID SEARCH command described in Section 2.6.1 of [RFC4466]
  103. (initially described in Section 6.4.4 of [RFC3501] and extended by
  104. [RFC4731]).
  105. The ESEARCH command further extends searching by allowing for
  106. optional source and result options. This document does not define
  107. any new result options (see Section 3.1 of [RFC4731]). A server that
  108. supports this extension includes "MULTISEARCH" in its IMAP capability
  109. string.
  110. Leiba & Melnikov Experimental [Page 3]
  111. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  112. Because there has been confusion about this, it is worth pointing out
  113. that with ESEARCH, as with *any* SEARCH or UID SEARCH command, it
  114. MUST NOT be considered an error if the search terms include a range
  115. of message numbers that extends (or, in fact, starts) beyond the end
  116. of the mailbox. For example, a client might want to establish a
  117. rolling window through the search results this way:
  118. C: tag1 UID ESEARCH FROM "frobozz" 1:100
  119. ...followed later by this:
  120. C: tag1 UID ESEARCH FROM "frobozz" 101:200
  121. ...and so on. This tells the server to match only the first hundred
  122. messages in the mailbox the first time, the second hundred the second
  123. time, etc. In fact, it might likely allow the server to optimize the
  124. search significantly. In the above example, whether the mailbox
  125. contains 50 or 150 or 250 messages, neither of the search commands
  126. shown will result in an error. It is up to the client to know when
  127. to stop moving its search window.
  128. 2.1. The ESEARCH Response
  129. In response to an ESEARCH command, the server MUST return ESEARCH
  130. responses [RFC4731] (that is, not SEARCH responses). Because message
  131. numbers are not useful for mailboxes that are not selected, the
  132. responses MUST contain information about UIDs, not message numbers.
  133. This is true even if the source options specify that only the
  134. selected mailbox be searched.
  135. Presence of a source option in the absence of a result option implies
  136. the "ALL" result option (see Section 3.1 of [RFC4731]). Note that
  137. this is not the same as the result from the SEARCH command described
  138. in the IMAP base protocol [RFC3501].
  139. Source options describe which mailboxes must be searched for
  140. messages. An ESEARCH command with source options does not affect
  141. which mailbox, if any, is currently selected, regardless of which
  142. mailboxes are searched.
  143. For each mailbox satisfying the source options, a single ESEARCH
  144. response MUST be returned if any messages in that mailbox match the
  145. search criteria. An ESEARCH response MUST NOT be returned for
  146. mailboxes that contain no matching messages. This is true even when
  147. result options such as MIN, MAX, and COUNT are specified (see
  148. Section 3.1 of [RFC4731]), and the values returned (lowest UID
  149. matched, highest UID matched, and number of messages matched,
  150. respectively) apply to the mailbox reported in that ESEARCH response.
  151. Leiba & Melnikov Experimental [Page 4]
  152. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  153. Note that it is possible for an ESEARCH command to return *no*
  154. untagged responses (no ESEARCH responses at all), in the case that
  155. there are no matches to the search in any of the mailboxes that
  156. satisfy the source options. Clients can detect this situation by
  157. finding the tagged OK response without having received any matching
  158. untagged ESEARCH responses.
  159. Each ESEARCH response MUST contain the MAILBOX, TAG, and UIDVALIDITY
  160. correlators. Correlators allow clients to issue several ESEARCH
  161. commands at once (pipelined). If the SEARCHRES [RFC5182] extension
  162. is used in an ESEARCH command, that ESEARCH command MUST be executed
  163. by the server after all previous SEARCH/ESEARCH commands have
  164. completed and before any subsequent SEARCH/ESEARCH commands are
  165. executed. The server MAY perform consecutive ESEARCH commands in
  166. parallel as long as none of them use the SEARCHRES extension.
  167. 2.2. Source Options: Specifying Mailboxes to Search
  168. The source options, if present, MUST contain a mailbox specifier as
  169. defined in the IMAP NOTIFY extension [RFC5465], Section 6 (using the
  170. "filter-mailboxes" ABNF item), with the following differences:
  171. 1. The "selected-delayed" specifier is not valid here.
  172. 2. A "subtree-one" specifier is added. The "subtree" specifier
  173. results in a search of the specified mailbox and all selectable
  174. mailboxes that are subordinate to it, through an indefinitely
  175. deep hierarchy. The "subtree-one" specifier results in a search
  176. of the specified mailbox and all selectable child mailboxes, one
  177. hierarchy level down.
  178. If "subtree" is specified, the server MUST defend against loops in
  179. the hierarchy (for example, those caused by recursive file-system
  180. links within the message store). The server SHOULD do this by
  181. keeping track of the mailboxes that have been searched, and
  182. terminating the hierarchy traversal when a repeat is found. If it
  183. cannot do that, it MAY do it by limiting the hierarchy depth.
  184. If the source options are not present, the value "selected" is
  185. assumed -- that is, only the currently selected mailbox is searched.
  186. The "personal" source option is a particularly convenient way to
  187. search all of the current user's mailboxes. Note that there is no
  188. way to use wildcard characters to search all mailboxes; the
  189. "mailboxes" source option does not do wildcard expansion.
  190. Leiba & Melnikov Experimental [Page 5]
  191. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  192. If the source options include (or default to) "selected", the IMAP
  193. session MUST be in "selected" state. If the source options specify
  194. other mailboxes and NOT "selected", then the IMAP session MUST be in
  195. either "selected" or "authenticated" state. If the session is not in
  196. a correct state, the ESEARCH command MUST return a "BAD" result.
  197. If the server supports the SEARCHRES [RFC5182] extension, then the
  198. "SAVE" result option is valid *only* if "selected" is specified or
  199. defaulted as the sole mailbox to be searched. If any source option
  200. other than "selected" is specified, the ESEARCH command MUST return a
  201. "BAD" result.
  202. If the server supports the CONTEXT=SEARCH and/or CONTEXT=SORT
  203. extension [RFC5267], then the following additional rules apply:
  204. o The CONTEXT return option (Section 4.2 of [RFC5267]) can be used
  205. with an ESEARCH command.
  206. o If the UPDATE return option is used (Section 4.3 of [RFC5267]), it
  207. MUST apply ONLY to the currently selected mailbox. If UPDATE is
  208. used and there is no mailbox currently selected, the ESEARCH
  209. command MUST return a "BAD" result.
  210. o The PARTIAL search return option (Section 4.4 of [RFC5267]) can be
  211. used and applies to each mailbox searched by the ESEARCH command.
  212. If the server supports the Access Control List (ACL) [RFC4314]
  213. extension, then the logged-in user is required to have the "r" right
  214. for each mailbox she wants to search. In addition, any mailboxes
  215. that are not explicitly named (accessed through "personal" or
  216. "subtree", for example) are required to have the "l" right.
  217. Mailboxes matching the source options for which the logged-in user
  218. lacks sufficient rights MUST be ignored by the ESEARCH command
  219. processing. In particular, ESEARCH responses MUST NOT be returned
  220. for those mailboxes.
  221. 3. Examples
  222. In the following example, note that two ESEARCH commands are
  223. pipelined, and that the server is running them in parallel,
  224. interleaving a response to the second search amid the responses to
  225. the first (watch the tags).
  226. C: tag1 ESEARCH IN (mailboxes "folder1" subtree "folder2") unseen
  227. C: tag2 ESEARCH IN (mailboxes "folder1" subtree-one "folder2")
  228. subject "chad"
  229. S: * ESEARCH (TAG "tag1" MAILBOX "folder1" UIDVALIDITY 1) UID ALL
  230. 4001,4003,4005,4007,4009
  231. Leiba & Melnikov Experimental [Page 6]
  232. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  233. S: * ESEARCH (TAG "tag2" MAILBOX "folder1" UIDVALIDITY 1) UID ALL
  234. 3001:3004,3788
  235. S: * ESEARCH (TAG "tag1" MAILBOX "folder2/banana" UIDVALIDITY 503)
  236. UID ALL 3002,4004
  237. S: * ESEARCH (TAG "tag1" MAILBOX "folder2/peach" UIDVALIDITY 3) UID
  238. ALL 921691
  239. S: tag1 OK done
  240. S: * ESEARCH (TAG "tag2" MAILBOX "folder2/salmon" UIDVALIDITY
  241. 1111111) UID ALL 50003,50006,50009,50012
  242. S: tag2 OK done
  243. 4. Formal Syntax
  244. The following syntax specification uses the Augmented Backus-Naur
  245. Form (ABNF) as described in [RFC5234]. Terms not defined here are
  246. taken from [RFC3501], [RFC5465], or [RFC4466].
  247. command-auth =/ esearch
  248. ; Update definition from IMAP base [RFC3501].
  249. ; Add new "esearch" command.
  250. command-select =/ esearch
  251. ; Update definition from IMAP base [RFC3501].
  252. ; Add new "esearch" command.
  253. filter-mailboxes-other =/ ("subtree-one" SP one-or-more-mailbox)
  254. ; Update definition from IMAP Notify [RFC5465].
  255. ; Add new "subtree-one" selector.
  256. filter-mailboxes-selected = "selected"
  257. ; Update definition from IMAP Notify [RFC5465].
  258. ; We forbid the use of "selected-delayed".
  259. one-correlator = ("TAG" SP tag-string) / ("MAILBOX" SP astring) /
  260. ("UIDVALIDITY" SP nz-number)
  261. ; Each correlator MUST appear exactly once.
  262. scope-option = scope-option-name [SP scope-option-value]
  263. ; No options defined here. Syntax for future extensions.
  264. scope-option-name = tagged-ext-label
  265. ; No options defined here. Syntax for future extensions.
  266. scope-option-value = tagged-ext-val
  267. ; No options defined here. Syntax for future extensions.
  268. Leiba & Melnikov Experimental [Page 7]
  269. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  270. scope-options = scope-option *(SP scope-option)
  271. ; A given option may only appear once.
  272. ; No options defined here. Syntax for future extensions.
  273. esearch = "ESEARCH" [SP esearch-source-opts]
  274. [SP search-return-opts] SP search-program
  275. search-correlator = SP "(" one-correlator *(SP one-correlator) ")"
  276. ; Updates definition in IMAP4 ABNF [RFC4466].
  277. esearch-source-opts = "IN" SP "(" source-mbox [SP
  278. "(" scope-options ")"] ")"
  279. source-mbox = filter-mailboxes *(SP filter-mailboxes)
  280. ; "filter-mailboxes" is defined in IMAP Notify [RFC5465].
  281. ; See updated definition of filter-mailboxes-other, above.
  282. ; See updated definition of filter-mailboxes-selected, above.
  283. 5. Security Considerations
  284. This new IMAP ESEARCH command allows a single command to search many
  285. mailboxes at once. On the one hand, a client could do that by
  286. sending many IMAP SEARCH commands. On the other hand, this makes it
  287. easier for a client to overwork a server, by sending a single command
  288. that results in an expensive search of tens of thousands of
  289. mailboxes. Server implementations need to be aware of that, and
  290. provide mechanisms that prevent a client from adversely affecting
  291. other users. Limitations on the number of mailboxes that may be
  292. searched in one command, and/or on the server resources that will be
  293. devoted to responding to a single client, are reasonable limitations
  294. for an implementation to impose.
  295. Implementations MUST, of course, apply access controls appropriately,
  296. limiting a user's access to ESEARCH in the same way its access is
  297. limited for any other IMAP commands. This extension has no data-
  298. access risks beyond what may be there in the unextended IMAP
  299. implementation.
  300. Mailboxes matching the source options for which the logged-in user
  301. lacks sufficient rights MUST be ignored by the ESEARCH command
  302. processing (see the paragraph about this in Section 2.2). In
  303. particular, any attempt to distinguish insufficient access from
  304. non-existent mailboxes may expose information about the mailbox
  305. hierarchy that isn't otherwise available to the client.
  306. If "subtree" is specified, the server MUST defend against loops in
  307. the hierarchy (see the paragraph about this in Section 2.2).
  308. Leiba & Melnikov Experimental [Page 8]
  309. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  310. 6. IANA Considerations
  311. IMAP4 capabilities are registered by publishing a Standards Track or
  312. IESG-approved Experimental RFC. The "IMAP 4 Capabilities" registry
  313. is currently located here:
  314. http://www.iana.org/
  315. This document defines the IMAP capability "MULTISEARCH", and IANA has
  316. added it to the registry.
  317. 7. Acknowledgements
  318. The authors gratefully acknowledge feedback provided by Timo
  319. Sirainen, Peter Coates, and Arnt Gulbrandsen.
  320. 8. Normative References
  321. [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
  322. Requirement Levels", BCP 14, RFC 2119, March 1997.
  323. [RFC2978] Freed, N. and J. Postel, "IANA Charset Registration
  324. Procedures", BCP 19, RFC 2978, October 2000.
  325. [RFC3501] Crispin, M., "INTERNET MESSAGE ACCESS PROTOCOL - VERSION
  326. 4rev1", RFC 3501, March 2003.
  327. [RFC4314] Melnikov, A., "IMAP4 Access Control List (ACL) Extension",
  328. RFC 4314, December 2005.
  329. [RFC4466] Melnikov, A. and C. Daboo, "Collected Extensions to IMAP4
  330. ABNF", RFC 4466, April 2006.
  331. [RFC4731] Melnikov, A. and D. Cridland, "IMAP4 Extension to SEARCH
  332. Command for Controlling What Kind of Information Is
  333. Returned", RFC 4731, November 2006.
  334. [RFC5182] Melnikov, A., "IMAP Extension for Referencing the Last
  335. SEARCH Result", RFC 5182, March 2008.
  336. [RFC5234] Crocker, D., Ed., and P. Overell, "Augmented BNF for
  337. Syntax Specifications: ABNF", STD 68, RFC 5234,
  338. January 2008.
  339. [RFC5267] Cridland, D. and C. King, "Contexts for IMAP4", RFC 5267,
  340. July 2008.
  341. Leiba & Melnikov Experimental [Page 9]
  342. RFC 6237 IMAP4 Multimailbox SEARCH Extension May 2011
  343. [RFC5465] Gulbrandsen, A., King, C., and A. Melnikov, "The IMAP
  344. NOTIFY Extension", RFC 5465, February 2009.
  345. Authors' Addresses
  346. Barry Leiba
  347. Huawei Technologies
  348. Phone: +1 646 827 0648
  349. EMail: barryleiba@computer.org
  350. URI: http://internetmessagingtechnology.org/
  351. Alexey Melnikov
  352. Isode Limited
  353. 5 Castle Business Village
  354. 36 Station Road
  355. Hampton, Middlesex TW12 2BX
  356. UK
  357. EMail: Alexey.Melnikov@isode.com
  358. URI: http://www.melnikov.ca/
  359. Leiba & Melnikov Experimental [Page 10]