Implementation Discussion
As of this writing, SUMEX has completed an IMAP2 client for Xerox Lisp machines written in hybrid Interlisp/CommonLisp and is beginning distribution of a client for TI Explorer Lisp machines. SUMEX has also completed a portable IMAP2 client protocol library module written in C. This library, with the addition of a small main program (primarily user interface) and a TCP/IP driver, became a rudimentary remote system mail-reading program under Unix. The first production use of this library is as a part of a MacII client which has now been under daily use (by real users) at Stanford for quite some time.
As of this writing, SUMEX has completed IMAP2 servers for TOPS-20 written in DEC-20 assembly language and 4.2/3 BSD Unix written in C. The TOPS-20 server is fully compatible with MM-20, the standard TOPS-20 mailsystem, and requires no special action or setup on the part of the user. The INBOX under TOPS-20 is the user's MAIL.TXT. The TOPS-20 server also supports multiple simultaneous access to the same mailbox, including simultaneous access between the IMAP3 server and MM-20. The 4.2/3 BSD Unix server requires that the user use either Unix Mail format or mail.txt format which is compatible with SRI MM-32 or Columbia MM-C. The 4.2/3 BSD Unix server allows simultaneous read access; write access must be exclusive. There is also an experimental IMAP3 server running on the TI Explorer class of machine, which uses MM mailbox format and which can communicate over both TCP and Chaos.
The Xerox Lisp client and DEC-20 server have been in production use for over two years; the Unix server was been in production use for over a year. IMAP3 has been used to access mailboxes at remote sites from a local workstation via the Internet. For example, from the Stanford local network one of the authors has read his mailbox at a Milnet site.
A number of IMAP clients have now been developed or are being developed. Amongst these are versions that run on the following machines:
-
Xerox Lisp machines
-
Apple Macintosh
-
NeXT
-
IBM PC
-
TI Explorer Lisp machines
-
"Glass teletype" version that runs under Unix
-
GNU Emacs
-
X Windows
-
NTT ELIS
Each of these client programs is carefully tuned to optimize the performance and user interface in a manner that is consistent with the the user interface model of the native machine. For example, the Macintosh client features a "messy-desk" interface that allows the cutting and pasting of text with the use of the clipboard with a menu driven interface with keyboard accelerators.
This specification does not make any formal definition of size restrictions, but some of the existing servers have the following limitations:
DEC-20
-
length of a mailbox: 7,077,888 characters
-
maximum number of messages: 18,432 messages
-
length of a command line: 10,000 characters
-
length of the local host name: 64 characters
-
length of a "short" argument: 39 characters
-
length of a "long" argument: 491,520 characters
-
maximum amount of data output in a single fetch: 655,360 characters
TI-Explorer
-
length of a mailbox: limited by the Minimum of the size of the virtual address space and the size of the file system
-
maximum number of messages: limited by the the size of the virtual address space
-
length of a command line: limited by the the size of the virtual address space
-
length of the local host name: limited by the the size of the virtual address space
-
length of a "short" argument: limited by the the size of the virtual address space
-
length of a "long" argument: limited by the the size of the virtual address space
-
maximum amount of data output in a single fetch: not limited
Typical values for these limits are 30Mb for file systems and 128Mb for virtual address space.
To date, nobody has run up against any of these limitations, many of which are substantially larger than most current user mail reading programs.
There are several advantages to the scheme of tags and solicited responses and unsolicited data. First, the infamous synchronization problems of SMTP and similar protocols do not happen with tagged commands; a command is not considered satisfied until a completion acknowledgement with the same tag is seen. Tagging allows an arbitrary amount of other responses ("solicited" data) to be sent by the server with no possibility of the client losing synchronization. Compare this with the problems that FTP or SMTP clients have with continuation, partial completion, and commentary reply codes.
Another advantage is that a non-lockstep client implementation is possible. The client could send a command, and entrust the handling of the server responses to a different process which would signal the client when the tagged response comes in. Some clients might be implemented in a thoroughly asynchronous manner, having, perhaps, multiple outstanding commands at any given time. Note: this does not require that the server process these commands in anything other than a lock-step manner. It simply allows clients to take advantage of servers that are able to do such asynchronous operations.
It was observed that synchronization problems can occur with literals if the literal is not recognized as such. Fortunately, the cases in which this can happen are relatively rare; a mechanism (the special "+" tag response) was introduced to handle those few cases which could happen. The proper way to address this problem in all cases is probably to move towards a record-oriented architecture instead of the text stream model provided by TCP.
Unsolicited data needs some discussion. Unlike most protocols, in which the server merely does the client's bidding, an IMAP3 server has a semi-autonomous role. By means of sending "unsolicited data", the server is in effect sending a command to the client -- to update and/or extend its (incomplete) model of the mailbox with new information from the server. In this viewpoint, although a "fetch" command is a request for specific information from the client, the server is always at liberty to include more than the desired data as "unsolicited". A server acknowledgement to the "fetch" is a statement that at least all the requested data has been sent.
In terms of implementation, a simple lock-step client may have a local cache of data from the mailbox. This cache is incomplete in general, and at select time is empty. A listener on the IMAP connection in the client processes all solicited and unsolicited data symmetrically, and updates the cache based on this data, i.e., the client faults on a cache miss and asks the server to fill that cache slot synchronously. If a tagged completion response arrives, the listener unblocks the process which sent the tagged request.
Clearly, given this model it is not strictly necessary to distinguish most solicited from unsolicited data. Doing so, however, apart from being clearer, also allows such simplistic, lock-step client implementations that extract the specific value of the response to command by trapping the tagged response. This allows the client not to have to block on some complex predicate that involves watching to see an update in a cache cell.
For example, perhaps as a result of opening a mailbox, solicited data from the server arrives. The first piece of data is the number of messages. This is used to size the cache; note that, if new mail arrives, by sending a new "number of messages" unsolicited data message server will cause the cache to be re-sized. If the client attempts to access information from the cache, it will encounter empty spots which will trigger "fetch" requests. The request would be sent, some solicited data including the answer to the fetch will flow back, and then the "fetch" response will unblock the client.
People familiar with demand-paged virtual memory design will recognize this model as being very similar to page-fault handling on a demand-paged system.