idnits 2.17.1 draft-leiba-imap-implement-guide-05.txt: ** The Abstract section seems to be numbered Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Cannot find the required boilerplate sections (Copyright, IPR, etc.) in this document. Expected boilerplate is as follows today (2024-04-26) according to https://trustee.ietf.org/license-info : IETF Trust Legal Provisions of 28-dec-2009, Section 6.a: This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 2: Copyright (c) 2024 IETF Trust and the persons identified as the document authors. All rights reserved. IETF Trust Legal Provisions of 28-dec-2009, Section 6.b(i), paragraph 3: This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing expiration date. The document expiration date should appear on the first and last page. ** The document seems to lack a 1id_guidelines paragraph about Internet-Drafts being working documents. ** The document seems to lack a 1id_guidelines paragraph about 6 months document validity. ** The document seems to lack a 1id_guidelines paragraph about the list of current Internet-Drafts. ** The document seems to lack a 1id_guidelines paragraph about the list of Shadow Directories. ** The document is more than 15 pages and seems to lack a Table of Contents. == No 'Intended status' indicated for this document; assuming Proposed Standard Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an Introduction section. ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. ** The abstract seems to contain references ([RFC-2060]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- -- 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 (September 1998) is 9355 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: 'UIDVALIDITY 824708485' is mentioned on line 247, but not defined == Missing Reference: 'UNSEEN 9921' is mentioned on line 248, but not defined == Missing Reference: 'UNSEEN' is mentioned on line 253, but not defined == Missing Reference: 'TRYCREATE' is mentioned on line 433, but not defined == Missing Reference: 'READ-ONLY' is mentioned on line 435, but not defined == Missing Reference: 'UIDVALIDITY 12345' is mentioned on line 568, but not defined -- Looks like a reference, but probably isn't: '1' on line 621 ** Obsolete normative reference: RFC 2060 (Obsoleted by RFC 3501) ** Downref: Normative reference to an Informational RFC: RFC 2180 -- Possible downref: Non-RFC (?) normative reference: ref. 'NAMESPACE' Summary: 14 errors (**), 0 flaws (~~), 7 warnings (==), 4 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group B. Leiba 3 Internet Draft IBM T.J. Watson Research Center 4 Document: draft-leiba-imap-implement-guide-05.txt April 1998 5 Expires September 1998 7 IMAP4 Implementation Recommendations 9 Status of this Document 11 This document provides information for the Internet community. This 12 document does not specify an Internet standard of any kind. 13 Distribution of this document is unlimited. 15 This document is an Internet Draft. Internet Drafts are working 16 documents of the Internet Engineering Task Force (IETF), its Areas, 17 and its Working Groups. Note that other groups may also distribute 18 working documents as Internet Drafts. 20 Internet Drafts are draft documents valid for a maximum of six 21 months. Internet Drafts may be updated, replaced, or obsoleted by 22 other documents at any time. It is not appropriate to use Internet 23 Drafts as reference material or to cite them other than as a "working 24 draft" or "work in progress". 26 To view the entire list of current Internet-Drafts, please check 27 the "1id-abstracts.txt" listing contained in the Internet-Drafts 28 Shadow Directories on ftp.is.co.za (Africa), ftp.nordu.net 29 (Northern Europe), ftp.nis.garr.it (Southern Europe), munnari.oz.au 30 (Pacific Rim), ftp.ietf.org (US East Coast), or ftp.isi.edu 31 (US West Coast). 33 A revised version of this draft document will be submitted to the RFC 34 editor. Discussion and suggestions for improvement are requested. 35 This document will expire by the end of September 1998. 37 1. Abstract 39 The IMAP4 specification [RFC-2060] describes a rich protocol for use 40 in building clients and servers for storage, retrieval, and 41 manipulation of electronic mail. Because the protocol is so rich and 42 has so many implementation choices, there are often trade-offs that 43 must be made and issues that must be considered when designing such 44 clients and servers. This document attempts to outline these issues 45 and to make recommendations in order to make the end products as 46 interoperable as possible. 48 2. Conventions used in this document 50 In examples, "C:" indicates lines sent by a client that is connected 51 to a server. "S:" indicates lines sent by the server to the client. 53 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 54 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 55 document are to be interpreted as described in [RFC-2119]. 57 3. Interoperability Issues and Recommendations 59 3.1. Accessibility 61 This section describes the issues related to access to servers and 62 server resources. Concerns here include data sharing and maintenance 63 of client/server connections. 65 3.1.1. Multiple Accesses of the Same Mailbox 67 One strong point of IMAP4 is that, unlike POP3, it allows for 68 multiple simultaneous access to a single mailbox. A user can, thus, 69 read mail from a client at home while the client in the office is 70 still connected; or the help desk staff can all work out of the same 71 inbox, all seeing the same pool of questions. An important point 72 about this capability, though is that NO SERVER IS GUARANTEED TO 73 SUPPORT THIS. If you are selecting an IMAP server and this facility 74 is important to you, be sure that the server you choose to install, 75 in the configuration you choose to use, supports it. 77 If you are designing a client, you MUST NOT assume that you can 78 access the same mailbox more than once at a time. That means 79 1. you must handle gracefully the failure of a SELECT command if 80 the server refuses the second SELECT, 81 2. you must handle reasonably the severing of your connection (see 82 "Severed Connections", below) if the server chooses to allow the 83 second SELECT by forcing the first off, 84 3. you must avoid making multiple connections to the same mailbox 85 in your own client (for load balancing or other such reasons), 86 and 87 4. you must avoid using the STATUS command on a mailbox that you 88 have selected (with some server implementations the STATUS 89 command has the same problems with multiple access as do the 90 SELECT and EXAMINE commands). 92 A further note about STATUS: The STATUS command is sometimes used to 93 check a non-selected mailbox for new mail. This mechanism MUST NOT 94 be used to check for new mail in the selected mailbox; section 5.2 of 96 [RFC-2060] specifically forbids this in its last paragraph. Further, 97 since STATUS takes a mailbox name it is an independent operation, not 98 operating on the selected mailbox. Because of this, the information 99 it returns is not necessarily in synchronization with the selected 100 mailbox state. 102 3.1.2. Severed Connections 104 The client/server connection may be severed for one of three reasons: 105 the client severs the connection, the server severs the connection, 106 or the connection is severed by outside forces beyond the control of 107 the client and the server (a telephone line drops, for example). 108 Clients and servers must both deal with these situations. 110 When the client wants to sever a connection, it's usually because it 111 has finished the work it needed to do on that connection. The client 112 SHOULD send a LOGOUT command, wait for the tagged response, and then 113 close the socket. But note that, while this is what's intended in 114 the protocol design, there isn't universal agreement here. Some 115 contend that sending the LOGOUT and waiting for the two responses 116 (untagged BYE and tagged OK) is wasteful and unnecessary, and that 117 the client can simply close the socket. The server should interpret 118 the closed socket as a log out by the client. The counterargument is 119 that it's useful from the standpoint of cleanup, problem 120 determination, and the like, to have an explicit client log out, 121 because otherwise there is no way for the server to tell the 122 difference between "closed socket because of log out" and "closed 123 socket because communication was disrupted". If there is a 124 client/server interaction problem, a client which routinely 125 terminates a session by breaking the connection without a LOGOUT will 126 make it much more difficult to determine the problem. 128 Because of this disagreement, server designers must be aware that 129 some clients might close the socket without sending a LOGOUT. In any 130 case, whether or not a LOGOUT was sent, the server SHOULD NOT 131 implicitly expunge any messages from the selected mailbox. If a 132 client wants the server to do so, it MUST send a CLOSE or EXPUNGE 133 command explicitly. 135 When the server wants to sever a connection it's usually due to an 136 inactivity timeout or is because a situation has arisen that has 137 changed the state of the mail store in a way that the server can not 138 communicate to the client. The server SHOULD send an untagged BYE 139 response to the client and then close the socket. Sending an 140 untagged BYE response before severing allows the server to send a 141 human-readable explanation of the problem to the client, which the 142 client may then log, display to the user, or both (see section 7.1.5 143 of [RFC-2060]). 145 3.2. Scaling 147 IMAP4 has many features that allow for scalability, as mail stores 148 become larger and more numerous. Large numbers of users, mailboxes, 149 and messages, and very large messages require thought to handle 150 efficiently. This document will not address the administrative 151 issues involved in large numbers of users, but we will look at the 152 other items. 154 3.2.1. Flood Control 156 There are three situations when a client can make a request that will 157 result in a very large response - too large for the client reasonably 158 to deal with: there are a great many mailboxes available, there are a 159 great many messages in the selected mailbox, or there is a very large 160 message part. The danger here is that the end user will be stuck 161 waiting while the server sends (and the client processes) an enormous 162 response. In all of these cases there are things a client can do to 163 reduce that danger. 165 There is also the case where a client can flood a server, by sending 166 an arbitratily long command. We'll discuss that issue, too, in this 167 section. 169 3.2.1.1. Listing Mailboxes 171 Some servers present Usenet newsgroups to IMAP users. Newsgroups, 172 and other such hierarchical mailbox structures, can be very numerous 173 but may have only a few entries at the top level of hierarchy. Also, 174 some servers are built against mail stores that can, unbeknownst to 175 the server, have circular hierarchies - that is, it's possible for 176 "a/b/c/d" to resolve to the same file structure as "a", which would 177 then mean that "a/b/c/d/b" is the same as "a/b", and the hierarchy 178 will never end. The LIST response in this case will be unlimited. 180 Clients that will have trouble with this are those that use 181 C: 001 LIST "" * 182 to determine the mailbox list. Because of this, clients SHOULD NOT 183 use an unqualified "*" that way in the LIST command. A safer 184 approach is to list each level of hierarchy individually, allowing 185 the user to traverse the tree one limb at a time, thus: 187 C: 001 LIST "" % 188 S: * LIST () "/" Banana 189 S: * LIST ...etc... 190 S: 001 OK done 192 and then 193 C: 002 LIST "" Banana/% 194 S: * LIST () "/" Banana/Apple 195 S: * LIST ...etc... 196 S: 002 OK done 198 Using this technique the client's user interface can give the user 199 full flexibility without choking on the voluminous reply to "LIST *". 200 Of course, it is still possible that the reply to 201 C: 005 LIST "" alt.fan.celebrity.% 202 may be thousands of entries long, and there is, unfortunately, 203 nothing the client can do to protect itself from that. This has not 204 yet been a notable problem. 206 Servers that may export circular hierarchies (any server that 207 directly presents a UNIX file system, for instance) SHOULD limit the 208 hierarchy depth to prevent unlimited LIST responses. A suggested 209 depth limit is 20 hierarchy levels. 211 3.2.1.2. Fetching the List of Messages 213 When a client selects a mailbox, it is given a count, in the untagged 214 EXISTS response, of the messages in the mailbox. This number can be 215 very large. In such a case it might be unwise to use 216 C: 004 FETCH 1:* ALL 217 to populate the user's view of the mailbox. One good method to avoid 218 problems with this is to batch the requests, thus: 220 C: 004 FETCH 1:50 ALL 221 S: * 1 FETCH ...etc... 222 S: 004 OK done 223 C: 005 FETCH 51:100 ALL 224 S: * 51 FETCH ...etc... 225 S: 005 OK done 226 C: 006 FETCH 101:150 ALL 227 ...etc... 229 Using this method, another command, such as "FETCH 6 BODY[1]" can be 230 inserted as necessary, and the client will not have its access to the 231 server blocked by a storm of FETCH replies. (Such a method could be 232 reversed to fetch the LAST 50 messages first, then the 50 prior to 233 that, and so on.) 235 As a smart extension of this, a well designed client, prepared for 236 very large mailboxes, will not automatically fetch data for all 237 messages AT ALL. Rather, the client will populate the user's view 238 only as the user sees it, possibly pre-fetching selected information, 239 and only fetching other information as the user scrolls to it. For 240 example, to select only those messages beginning with the first 241 unseen one: 243 C: 003 SELECT INBOX 244 S: * 10000 EXISTS 245 S: * 80 RECENT 246 S: * FLAGS (\Answered \Flagged \Deleted \Draft \Seen) 247 S: * OK [UIDVALIDITY 824708485] UID validity status 248 S: * OK [UNSEEN 9921] First unseen message 249 S: 003 OK [READ-WRITE] SELECT completed 250 C: 004 FETCH 9921:* ALL 251 ... etc... 253 If the server does not return an OK [UNSEEN] response, the client may 254 use SEARCH UNSEEN to obtain that value. 256 This mechanism is good as a default presentation method, but only 257 works well if the default message order is acceptable. A client may 258 want to present various sort orders to the user (by subject, by date 259 sent, by sender, and so on) and in that case (lacking a SORT 260 extension on the server side) the client WILL have to retrieve all 261 message descriptors. A client that provides this service SHOULD NOT 262 do it by default and SHOULD inform the user of the costs of choosing 263 this option for large mailboxes. 265 3.2.1.3. Fetching a Large Body Part 267 The issue here is similar to the one for a list of messages. In the 268 BODYSTRUCTURE response the client knows the size, in bytes, of the 269 body part it plans to fetch. Suppose this is a 70 MB video clip. 270 The client can use partial fetches to retrieve the body part in 271 pieces, avoiding the problem of an uninterruptible 70 MB literal 272 coming back from the server: 274 C: 022 FETCH 3 BODY[1]<0.20000> 275 S: * 3 FETCH (FLAGS(\Seen) BODY[1]<0> {20000} 276 S: ...data...) 277 S: 022 OK done 278 C: 023 FETCH 3 BODY[1]<20001.20000> 279 S: * 3 FETCH (BODY[1]<20001> {20000} 280 S: ...data...) 281 S: 023 OK done 282 C: 024 FETCH 3 BODY[1]<40001.20000> 283 ...etc... 285 3.2.1.4. BODYSTRUCTURE vs. Entire Messages 287 Because FETCH BODYSTRUCTURE is necessary in order to determine the 288 number of body parts, and, thus, whether a message has "attachments", 289 clients often use FETCH FULL as their normal method of populating the 290 user's view of a mailbox. The benefit is that the client can display 291 a paperclip icon or some such indication along with the normal 292 message summary. However, this comes at a significant cost with some 293 server configurations. The parsing needed to generate the FETCH 294 BODYSTRUCTURE response may be time-consuming compared with that 295 needed for FETCH ENVELOPE. The client developer should consider this 296 issue when deciding whether the ability to add a paperclip icon is 297 worth the tradeoff in performance, especially with large mailboxes. 299 Some clients, rather than using FETCH BODYSTRUCTURE, use FETCH BODY[] 300 (or the equivalent FETCH RFC822) to retrieve the entire message. 301 They then do the MIME parsing in the client. This may give the 302 client slightly more flexibility in some areas (access, for instance, 303 to header fields that aren't returned in the BODYSTRUCTURE and 304 ENVELOPE responses), but it can cause severe performance problems by 305 forcing the transfer of all body parts when the user might only want 306 to see some of them - a user logged on by modem and reading a small 307 text message with a large ZIP file attached may prefer to read the 308 text only and save the ZIP file for later. Therefore, a client 309 SHOULD NOT normally retrieve entire messages and SHOULD retrieve 310 message body parts selectively. 312 3.2.1.5. Long Command Lines 314 A client can wind up building a very long command line in an effort 315 to try to be efficient about requesting information from a server. 316 This can typically happen when a client builds a message set from 317 selected messages and doesn't recognise that contiguous blocks of 318 messages may be group in a range. Suppose a user selects all 10,000 319 messages in a large mailbox and then unselects message 287. The 320 client could build that message set as "1:286,288:10000", but a 321 client that doesn't handle that might try to enumerate each message 322 individually and build "1,2,3,4, [and so on] ,9999,10000". Adding 323 that to the fetch command results in a command line that's almost 324 49,000 octets long, and, clearly, one can construct a command line 325 that's even longer. 327 A client SHOULD limit the length of the command lines it generates to 328 approximately 1000 octets (including all quoted strings but not 329 including literals). If the client is unable to group things into 330 ranges so that the command line is within that length, it SHOULD 331 split the request into multiple commands. The client SHOULD use 332 literals instead of long quoted strings, in order to keep the command 333 length down. 335 For its part, a server SHOULD allow for a command line of at least 336 8000 octets. This provides plenty of leeway for accepting reasonable 337 length commands from clients. The server SHOULD send a BAD response 338 to a command that does not end within the server's maximum accepted 339 command length. 341 3.2.2. Subscriptions 343 The client isn't the only entity that can get flooded: the end user, 344 too, may need some flood control. The IMAP4 protocol provides such 345 control in the form of subscriptions. Most servers support the 346 SUBSCRIBE, UNSUBSCRIBE, and LSUB commands, and many users choose to 347 narrow down a large list of available mailboxes by subscribing to the 348 ones that they usually want to see. Clients, with this in mind, 349 SHOULD give the user a way to see only subscribed mailboxes. A 350 client that never uses the LSUB command takes a significant usability 351 feature away from the user. Of course, the client would not want to 352 hide the LIST command completely; the user needs to be able to go 353 both ways. 355 3.2.3. Searching 357 IMAP SEARCH commands can become particularly troublesome (that is, 358 slow) on mailboxes containing a large number of messages. So let's 359 put a few things in perspective in that regard. 361 The flag searches SHOULD be fast. The flag searches (ALL, [UN]SEEN, 362 [UN]ANSWERED, [UN]DELETED, [UN]DRAFT, [UN]FLAGGED, NEW, OLD, RECENT) 363 are known to be used by clients for the client's own use (for 364 instance, some clients use "SEARCH UNSEEN" to find unseen mail and 365 "SEARCH DELETED" to warn the user before expunging messages). 367 Other searches, particularly the text searches (HEADER, TEXT, BODY) 368 are initiated by the user, rather than by the client itself, and 369 somewhat slower performance can be tolerated, since the user is aware 370 that the search is being done (and is probably aware that it might be 371 time-consuming). 373 The client MAY allow other commands to be sent to the server while a 374 SEARCH is in progress, but at the time of this writing there is 375 little or no server support for parallel processing of multiple 376 commands in the same session (and see "Multiple Accesses of the Same 377 Mailbox" above for a description of the dangers of trying to work 378 around this by doing your SEARCH in another session). 380 Another word about text searches: some servers, built on database 381 back-ends with indexed search capabilities, may return search results 382 that do not match the IMAP spec's "case-insensitive substring" 383 requirements. While these servers are in violation of the protocol, 384 there is little harm in the violation as long as the search results 385 are used only to response to a user's request. Still, developers of 386 such servers should be aware that they ARE violating the protocol, 387 should think carefully about that behaviour, and MUST be certain that 388 their servers respond accurately to the flag searches for the reasons 389 outlined above. 391 In addition, servers SHOULD support CHARSET UTF-8 in searches. 393 3.3 Avoiding Invalid Requests 395 IMAP4 provides ways for a server to tell a client in advance what is 396 and isn't permitted in some circumstances. Clients SHOULD use these 397 features to avoid sending requests that a well designed client would 398 know to be invalid. This section explains this in more detail. 400 3.3.1. The CAPABILITY Command 402 All IMAP4 clients SHOULD use the CAPABILITY command to determine what 403 version of IMAP and what optional features a server supports. The 404 client SHOULD NOT send IMAP4rev1 commands and arguments to a server 405 that does not advertize IMAP4rev1 in its CAPABILITY response. 406 Similarly, the client SHOULD NOT send IMAP4 commands that no longer 407 exist in IMAP4rev1 to a server that does not advertize IMAP4 in its 408 CAPABILITY response. An IMAP4rev1 server is NOT required to support 409 obsolete IMAP4 or IMAP2bis commands (though some do; do not let this 410 fact lull you into thinking that it's valid to send such commands to 411 an IMAP4rev1 server). 413 A client SHOULD NOT send commands to probe for the existance of 414 certain extensions. All standard and standards-track extensions 415 include CAPABILITY tokens indicating their presense. All private and 416 experimental extensions SHOULD do the same, and clients that take 417 advantage of them SHOULD use the CAPABILITY response to determine 418 whether they may be used or not. 420 3.3.2. Don't Do What the Server Says You Can't 422 In many cases, the server, in response to a command, will tell the 423 client something about what can and can't be done with a particular 424 mailbox. The client SHOULD pay attention to this information and 425 SHOULD NOT try to do things that it's been told it can't do. 427 Examples: 428 * Do not try to SELECT a mailbox that has the \Noselect flag set. 429 * Do not try to CREATE a sub-mailbox in a mailbox that has the 430 \Noinferiors flag set. 431 * Do not respond to a failing COPY or APPEND command by trying to 432 CREATE the target mailbox if the server does not respond with a 433 [TRYCREATE] response code. 434 * Do not try to expunge a mailbox that has been selected with the 435 [READ-ONLY] response code. 437 3.4. Miscellaneous Protocol Considerations 439 We describe here a number of important protocol-related issues, the 440 misunderstanding of which has caused significant interoperability 441 problems in IMAP4 implementations. One general item is that every 442 implementer should be certain to take note of and to understand 443 section 2.2.2 and the preamble to section 7 of the IMAP4rev1 spec 444 [RFC-2060]. 446 3.4.1. Well Formed Protocol 448 We cannot stress enough the importance of adhering strictly to the 449 protocol grammar. The specification of the protocol is quite rigid; 450 do not assume that you can insert blank space for "readability" if 451 none is called for. Keep in mind that there are parsers out there 452 that will crash if there are protocol errors. There are clients that 453 will report every parser burp to the user. And in any case, 454 information that cannot be parsed is information that is lost. Be 455 careful in your protocol generation. And see "A Word About Testing", 456 below. 458 In particular, note that the string in the INTERNALDATE response is 459 NOT an RFC-822 date string - that is, it is not in the same format as 460 the first string in the ENVELOPE response. Since most clients will, 461 in fact, accept an RFC-822 date string in the INTERNALDATE response, 462 it's easy to miss this in your interoperability testing. But it will 463 cause a problem with some client, so be sure to generate the correct 464 string for this field. 466 3.4.2. Special Characters 468 Certain characters, currently the double-quote and the backslash, may 469 not be sent as-is inside a quoted string. These characters MUST be 470 preceded by the escape character if they are in a quoted string, or 471 else the string must be sent as a literal. Both clients and servers 472 MUST handle this, both on output (they must send these characters 473 properly) and on input (they must be able to receive escaped 474 characters in quoted strings). Example: 476 C: 001 LIST "" % 477 S: * LIST () "" INBOX 478 S: * LIST () "\\" TEST 479 S: * LIST () "\\" {12} 480 S: "My" mailbox 481 S: 001 OK done 482 C: 002 LIST "" "\"My\" mailbox\\%" 483 S: * LIST () "\\" {17} 484 S: "My" mailbox\Junk 485 S: 002 OK done 487 Note that in the example the server sent the hierarchy delimiter as 488 an escaped character in the quoted string and sent the mailbox name 489 containing imbedded double-quotes as a literal. The client used only 490 quoted strings, escaping both the backslash and the double-quote 491 characters. 493 The CR and LF characters may be sent ONLY in literals; they are not 494 allowed, even if escaped, inside quoted strings. 496 And while we're talking about special characters: the IMAP spec, in 497 the section titled "Mailbox International Naming Convention", 498 describes how to encode mailbox names in modified UTF-7. 499 Implementations MUST adhere to this in order to be interoperable in 500 the international market, and servers SHOULD validate mailbox names 501 sent by client and reject names that do not conform. 503 3.4.3. UIDs and UIDVALIDITY 505 Servers that support existing back-end mail stores often have no good 506 place to save UIDs for messages. Often the existing mail store will 507 not have the concept of UIDs in the sense that IMAP has: strictly 508 increasing, never re-issued, 32-bit integers. Some servers solve 509 this by storing the UIDs in a place that's accessible to end users, 510 allowing for the possibility that the users will delete them. Others 511 solve it by re-assigning UIDs every time a mailbox is selected. 513 The server SHOULD maintain UIDs permanently for all messages if it 514 can. If that's not possible, the server MUST change the UIDVALIDITY 515 value for the mailbox whenever any of the UIDs may have become 516 invalid. Clients MUST recognize that the UIDVALIDITY has changed and 517 MUST respond to that condition by throwing away any information that 518 they have saved about UIDs in that mailbox. There have been many 519 problems in this area when clients have failed to do this; in the 520 worst case it will result in loss of mail when a client deletes the 521 wrong piece of mail by using a stale UID. 523 It seems to be a common myth that "the UIDVALIDITY and the UID, taken 524 together, form a 64-bit identifier that uniquely identifies a message 525 on a server". This is absolutely NOT TRUE. There is no assurance 526 that the UIDVALIDITY values of two mailboxes be different, so the 527 UIDVALIDITY in no way identifies a mailbox. The ONLY purpose of 528 UIDVALIDITY is, as its name indicates, to give the client a way to 529 check the validity of the UIDs it has cached. While it is a valid 530 implementation choice to put these values together to make a 64-bit 531 identifier for the message, the important concept here is that UIDs 532 are not unique between mailboxes; they are only unique WITHIN a given 533 mailbox. 535 Some server implementations have toyed with making UIDs unique across 536 the entire server. This is inadvisable, in that it limits the life 537 of UIDs unnecessarily. The UID is a 32-bit number and will run out 538 in reasonably finite time if it's global across the server. If you 539 assign UIDs sequentially in one mailbox, you will not have to start 540 re-using them until you have had, at one time or another, 2**32 541 different messages in that mailbox. In the global case, you will 542 have to reuse them once you have had, at one time or another, 2**32 543 different messages in the entire mail store. Suppose your server has 544 around 8000 users registered (2**13). That gives an average of 2**19 545 UIDs per user. Suppose each user gets 32 messages (2**5) per day. 546 That gives you 2**14 days (16000+ days = about 45 years) before you 547 run out. That may seem like enough, but multiply the usage just a 548 little (a lot of spam, a lot of mailing list subscriptions, more 549 users) and you limit yourself too much. 551 What's worse is that if you have to wrap the UIDs, and, thus, you 552 have to change UIDVALIDITY and invalidate the UIDs in the mailbox, 553 you have to do it for EVERY mailbox in the system, since they all 554 share the same UID pool. If you assign UIDs per mailbox and you have 555 a problem, you only have to kill the UIDs for that one mailbox. 557 Under extreme circumstances (and this is extreme, indeed), the server 558 may have to invalidate UIDs while a mailbox is in use by a client - 559 that is, the UIDs that the client knows about in its active mailbox 560 are no longer valid. In that case, the server MUST immediately 561 change the UIDVALIDITY and MUST communicate this to the client. The 562 server MAY do this by sending an unsolicited UIDVALIDITY message, in 563 the same form as in response to the SELECT command. Clients MUST be 564 prepared to handle such a message and the possibly coincident failure 565 of the command in process. For example: 567 C: 032 UID STORE 382 +Flags.silent \Deleted 568 S: * OK [UIDVALIDITY 12345] New UIDVALIDITY value! 569 S: 032 NO UID command rejeced because UIDVALIDITY changed! 570 C: ...invalidates local information and re-fetches... 571 C: 033 FETCH 1:* UID 572 ...etc... 574 At the time of the writing of this document, the only server known to 575 do this does so only under the following condition: the client 576 selects INBOX, but there is not yet a physical INBOX file created. 577 Nonetheless, the SELECT succeeds, exporting an empty INBOX with a 578 temporary UIDVALIDITY of 1. While the INBOX remains selected, mail 579 is delivered to the user, which creates the real INBOX file and 580 assigns a permanent UIDVALIDITY (that is likely not to be 1). The 581 server reports the change of UIDVALIDITY, but as there were no 582 messages before, so no UIDs have actually changed, all the client 583 must do is accept the change in UIDVALIDITY. 585 Alternatively, a server may force the client to re-select the 586 mailbox, at which time it will obtain a new UIDVALIDITY value. To do 587 this, the server closes this client session (see "Severed 588 Connections" above) and the client then reconnects and gets back in 589 synch. Clients MUST be prepared for either of these behaviours. 591 We do not know of, nor do we anticipate the future existance of, a 592 server that changes UIDVALIDITY while there are existing messages, 593 but clients MUST be prepared to handle this eventuality. 595 3.4.4. FETCH Responses 597 When a client asks for certain information in a FETCH command, the 598 server MAY return the requested information in any order, not 599 necessarily in the order that it was requested. Further, the server 600 MAY return the information in separate FETCH responses and MAY also 601 return information that was not explicitly requested (to reflect to 602 the client changes in the state of the subject message). Some 603 examples: 605 C: 001 FETCH 1 UID FLAGS INTERNALDATE 606 S: * 5 FETCH (FLAGS (\Deleted)) 607 S: * 1 FETCH (FLAGS (\Seen) INTERNALDATE "..." UID 345) 608 S: 001 OK done 609 (In this case, the responses are in a different order. Also, the 610 server returned a flag update for message 5, which wasn't part of the 611 client's request.) 612 C: 002 FETCH 2 UID FLAGS INTERNALDATE 613 S: * 2 FETCH (INTERNALDATE "...") 614 S: * 2 FETCH (UID 399) 615 S: * 2 FETCH (FLAGS ()) 616 S: 002 OK done 617 (In this case, the responses are in a different order and were 618 returned in separate responses.) 620 C: 003 FETCH 2 BODY[1] 621 S: * 2 FETCH (FLAGS (\Seen) BODY[1] {14} 622 S: Hello world! 623 S: ) 624 S: 003 OK done 625 (In this case, the FLAGS response was added by the server, since 626 fetching the body part caused the server to set the \Seen flag.) 628 Because of this characteristic a client MUST be ready to receive any 629 FETCH response at any time and should use that information to update 630 its local information about the message to which the FETCH response 631 refers. A client MUST NOT assume that any FETCH responses will come 632 in any particular order, or even that any will come at all. If after 633 receiving the tagged response for a FETCH command the client finds 634 that it did not get all of the information requested, the client 635 SHOULD send a NOOP command to the server to ensure that the server 636 has an opportunity to send any pending EXPUNGE responses to the 637 client (see [RFC-2180]). 639 3.4.5. RFC822.SIZE 641 Some back-end mail stores keep the mail in a canonical form, rather 642 than retaining the original MIME format of the messages. This means 643 that the server must reassemble the message to produce a MIME stream 644 when a client does a fetch such as RFC822 or BODY[], requesting the 645 entire message. It also may mean that the server has no convenient 646 way to know the RFC822.SIZE of the message. Often, such a server 647 will actually have to build the MIME stream to compute the size, only 648 to throw the stream away and report the size to the client. 650 When this is the case, some servers have chosen to estimate the size, 651 rather than to compute it precisely. Such an estimate allows the 652 client to display an approximate size to the user and to use the 653 estimate in flood control considerations (q.v.), but requires that 654 the client not use the size for things such as allocation of buffers, 655 because those buffers might then be too small to hold the actual MIME 656 stream. Instead, a client SHOULD use the size that's returned in the 657 literal when you fetch the data. 659 The protocol requires that the RFC822.SIZE value returned by the 660 server be EXACT. Estimating the size is a protocol violation, and 661 server designers must be aware that, despite the performance savings 662 they might realize in using an estimate, this practice will cause 663 some clients to fail in various ways. If possible, the server SHOULD 664 compute the RFC822.SIZE for a particular message once, and then save 665 it for later retrieval. If that's not possible, the server MUST 666 compute the value exactly every time. Incorrect estimates do cause 667 severe interoperability problems with some clients. 669 3.4.6. Expunged Messages 671 If the server allows multiple connections to the same mailbox, it is 672 often possible for messages to be expunged in one client unbeknownst 673 to another client. Since the server is not allowed to tell the 674 client about these expunged messages in response to a FETCH command, 675 the server may have to deal with the issue of how to return 676 information about an expunged message. There was extensive 677 discussion about this issue, and the results of that discussion are 678 summarized in [RFC-2180]. See that reference for a detailed 679 explanation and for recommendations. 681 3.4.7. The Namespace Issue 683 Namespaces are a very muddy area in IMAP4 implementation right now 684 (see [NAMESPACE] for a proposal to clear the water a bit). Until the 685 issue is resolved, the important thing for client developers to 686 understand is that some servers provide access through IMAP to more 687 than just the user's personal mailboxes, and, in fact, the user's 688 personal mailboxes may be "hidden" somewhere in the user's default 689 hierarchy. The client, therefore, SHOULD provide a setting wherein 690 the user can specify a prefix to be used when accessing mailboxes. 691 If the user's mailboxes are all in "~/mail/", for instance, then the 692 user can put that string in the prefix. The client would then put 693 the prefix in front of any name pattern in the LIST and LSUB 694 commands: 695 C: 001 LIST "" ~/mail/% 696 (See also "Reference Names in the LIST Command" below.) 698 3.4.8. Creating Special-Use Mailboxes 700 It may seem at first that this is part of the namespace issue; it is 701 not, and is only indirectly related to it. A number of clients like 702 to create special-use mailboxes with particular names. Most 703 commonly, clients with a "trash folder" model of message deletion 704 want to create a mailbox with the name "Trash" or "Deleted". Some 705 clients want to create a "Drafts" mailbox, an "Outbox" mailbox, or a 706 "Sent Mail" mailbox. And so on. There are two major 707 interoperability problems with this practice: 708 1. different clients may use different names for mailboxes with 709 similar functions (such as "Trash" and "Deleted"), or may manage the 710 same mailboxes in different ways, causing problems if a user switches 711 between clients and 712 2. there is no guarantee that the server will allow the creation of 713 the desired mailbox. 715 The client developer is, therefore, well advised to consider 716 carefully the creation of any special-use mailboxes on the server, 717 and, further, the client MUST NOT require such mailbox creation - 718 that is, if you do decide to do this, you MUST handle gracefully the 719 failure of the CREATE command and behave reasonably when your 720 special-use mailboxes do not exist and can not be created. 722 In addition, the client developer SHOULD provide a convenient way for 723 the user to select the names for any special-use mailboxes, allowing 724 the user to make these names the same in all clients s/he uses and to 725 put them where s/he wants them. 727 3.4.9. Reference Names in the LIST Command 729 Many implementers of both clients and servers are confused by the 730 "reference name" on the LIST command. The reference name is intended 731 to be used in much the way a "cd" (change directory) command is used 732 on Unix, PC DOS, Windows, and OS/2 systems. That is, the mailbox 733 name is interpreted in much the same way as a file of that name would 734 be found if one had done a "cd" command into the directory specified 735 by the reference name. For example, in Unix we have the following: 737 > cd /u/jones/junk 738 > vi banana [file is "/u/jones/junk/banana"] 739 > vi stuff/banana [file is "/u/jones/junk/stuff/banana"] 740 > vi /etc/hosts [file is "/etc/hosts"] 742 The interoperability problems with this, in practice, are several. 743 First, while some IMAP servers are built on Unix or PC file systems, 744 many others are not, and the file system semantics do not make sense 745 in those configurations. Second, while some IMAP servers expose the 746 underlying file system to the clients, others allow access only to 747 the user's personal mailboxes, or to some other limited set of files, 748 making such file-system-like semantics less meaningful. Third, 749 because the IMAP spec leaves the interpretation of the reference name 750 as "implementation-dependent", the various server implementations 751 handle it in vastly differing ways, and fourth, many implementers 752 simply do not understand it and misuse it, do not use it, or ignore 753 it as a result. 755 The following statement gets somewhat into the religious issues that 756 we've tried to avoid scrupulously here; so be it: because of the 757 confusion around the reference name, its use by a client is a 758 dangerous thing, prone to result in interoperability problems. There 759 are servers that interpret it as originally intended; there are 760 servers that ignore it completely; there are servers that simply 761 prepend it to the mailbox name (with or without inserting a hierarchy 762 delimiter in between). Because a client can't know which of these 763 four behaviours to expect, a client SHOULD NOT use a reference name 764 itself, expecting a particular server behavior. However, a client 765 SHOULD permit a USER, by configuration, to use a reference name. 767 There is in no way universal agreement about the use or non-use of 768 the reference name. The last words here are, "Be aware." 770 3.4.12. Mailbox Hierarchy Delimiters 772 The server's selection of what to use as a mailbox hierarchy 773 delimiter is a difficult one, involving several issues: What 774 characters do users expect to see here? What characters can they 775 enter in cases where they want to or must type them in? What 776 characters can be used for delimiters, which characters will then not 777 be allowed in the mailbox names themselves? 779 Because some interfaces show users the hierarchy delimiters or allow 780 users to enter qualified mailbox names containing them, server 781 implementations SHOULD use delimiter characters that users generally 782 expect to see as name separators. The most common characters used 783 for this are "/" (as in Unix file names), "\" (as in OS/2, and 784 Windows file names), and "." (as in news groups). There is little to 785 choose among these apart from what users may be used to or what is 786 dictated by the underlying file system, if any. One consideration 787 about using "\" is that it's also a special character in the IMAP 788 protocol. While the use of other hierarchy delimiter characters is 789 permissible, A DESIGNER IS WELL ADVISED TO STAY WITH ONE FROM THIS 790 SET unless the server is intended for special purposes only. 791 Characters such as "-", "_", ";", "&", "#", "@", and "!" may be 792 considered, but the implementer should be aware of the surprise to 793 the user as well as of the affect on URLs and other external 794 specifications (since some of these characters have special meanings 795 there). Also, a server that uses "\" (and clients of such a server) 796 must remember to escape that character in quoted strings or to send 797 literals instead: 799 001 LIST "" "this\\%\\%\\%\\h*" 800 * LIST () "\\" {27} 801 this\is\a\mailbox\hierarchy 802 001 OK LIST complete 804 In any case, a server SHOULD NOT use normal alpha-numeric characters 805 (such as "X" or "0") as delimiters; a user would be very surprised to 806 find that "EXPENDITURES" actually represented a two-level hierarchy. 807 And a server SHOULD NOT use characters that are non-printable or 808 difficult or impossible to enter on a standard US keyboard. Control 809 characters, box-drawing characters, and characters from non-US 810 alphabets fit into this category. Their use presents 811 interoperability problems that are best avoided. 813 The UTF-7 encoding of mailbox names also raises questions about what 814 to do with the hierarchy delimiters in encoded names: do we encode 815 each hierarchy level and separate them with delimiters, or do we 816 encode the fully qualified name, delimiters and all? The answer for 817 IMAP is the former: encode each hierarchy level separately, and 818 insert delimiters between. This makes it particularly important not 819 to use as a hierarchy delimiter a character that might cause 820 confusion with IMAP's modified UTF-7 encoding. 822 To repeat: a server SHOULD use "/", "\", or "." as its hierarchy 823 delimiter. The use of any other character is likely to cause 824 problems and is STRONGLY DISCOURAGED. 826 3.4.11. ALERT Response Codes 828 The protocol spec is very clear on the matter of what to do with 829 ALERT response codes, and yet there are many clients that violate it 830 so it needs to be said anyway: "The human-readable text contains a 831 special alert that MUST be presented to the user in a fashion that 832 calls the user's attention to the message." Enough said. Do it. 834 3.4.12. Deleting Mailboxes 836 The protocol does not guarantee that a client may delete a mailbox 837 that is not empty, though on some servers it is permissible and is, 838 in fact, much faster than the alternative or deleting all the 839 messages from the client. If the client chooses to try to take 840 advantage of this possibility it MUST be prepared to use the other 841 method in the even that the more convenient one fails. Further, a 842 client SHOULD NOT try to delete the mailbox that it has selected, but 843 should first close that mailbox; some servers do not permit the 844 deletion of the selected mailbox. 846 That said, a server SHOULD permit the deletion of a non-empty 847 mailbox; there's little reason to pass this work on to the client. 848 Moreover, forbidding this prevents the deletion of a mailbox that for 849 some reason can not be opened or expunged, leading to possible 850 denial-of-service problems. 852 Example: 853 [User tells the client to delete mailbox BANANA, which is 854 currently selected...] 855 C: 008 CLOSE 856 S: 008 OK done 857 C: 009 DELETE BANANA 858 S: 009 NO Delete failed; mailbox is not empty. 859 C: 010 SELECT BANANA 860 S: * ... untagged SELECT responses 861 S: 010 OK done 862 C: 011 STORE 1:* +FLAGS.SILENT \DELETED 863 S: 011 OK done 864 C: 012 CLOSE 865 S: 012 OK done 866 C: 013 DELETE BANANA 867 S: 013 OK done 869 3.5. A Word About Testing 871 Since the whole point of IMAP is interoperability, and since 872 interoperability can not be tested in a vacuum, the final 873 recommendation of this treatise is, "Test against EVERYTHING." Test 874 your client against every server you can get an account on. Test 875 your server with every client you can get your hands on. Many 876 clients make limited test versions available on the Web for the 877 downloading. Many server owners will give serious client developers 878 guest accounts for testing. Contact them and ask. NEVER assume that 879 because your client works with one or two servers, or because your 880 server does fine with one or two clients, you will interoperate well 881 in general. 883 In particular, in addition to everything else, be sure to test 884 against the reference implementations: the PINE client, the 885 University of Washington server, and the Cyrus server. 887 See the following URLs on the web for more information here: 888 IMAP Products and Sources: http://www.imap.org/products.html 889 IMC MailConnect: http://www.imc.org/imc-mailconnect 891 4. Security Considerations 893 This document describes behaviour of clients and servers that use the 894 IMAP4 protocol, and as such, has the same security considerations as 895 described in [RFC-2060]. 897 5. References 899 [RFC-2060], Crispin, M., "Internet Message Access Protocol - Version 900 4rev1", RFC 2060, University of Washington, December 1996. 902 [RFC-2119], Bradner, S., "Key words for use in RFCs to Indicate 903 Requirement Levels", RFC 2119, Harvard University, March 1997. 905 [RFC-2180], Gahrns, M., "IMAP4 Multi-Accessed Mailbox Practice", RFC 906 2180, Microsoft, July 1997. 908 [NAMESPACE], Gahrns, M. & Newman, C., "IMAP4 Namespace", draft 909 document , June 1997. 911 6. Author's Address 913 Barry Leiba 914 IBM T.J. Watson Research Center 915 30 Saw Mill River Road 916 Hawthorne, NY 10532 918 Phone: 1-914-784-7941 919 Email: leiba@watson.ibm.com