7.4 The IMAP Protocol for Retrieving Mail


The HTTP protocol is only one of many client/server application protocols used on the Internet. Another common protocol is used so that a mail application running on your computer can retrieve mail from a central server. Since your personal computer might not be turned on at all times, when mail is sent to you it is sent to a server and stored on that server until you turn on your computer and retrieve any new email.

Like many application standards, the Internet Message Access Protocol (IMAP) is described in a series of Request For Comment (RFC) documents starting with this RFC:


IMAP is a more complicated protocol than the web protocol, so we won’t be able to use the telnet command to fake the protocol.

But if you were going to develop a mail reading application, you could carefully read this document and develop code to have a successful conversation with a standards-compliant IMAP server.

Here is a simple example from section 6.3.1 of the above document showing what the client (C:) sends and how the server (S:) responds:

S:* 172 EXISTS
S:* OK [UNSEEN 12] Message 12 is first unseen
S:* OK [UIDVALIDITY 3857529045] UIDs valid
S:* OK [UIDNEXT 4392] Predicted next UID
S:* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
S:* OK [PERMANENTFLAGS (\Deleted \Seen \*)] Limited
S: A142 OK [READ-WRITE] SELECT completed

The messages that are sent by the client and server are not designed to be viewed by an end user so they are not particularly descriptive. These messages are precisely formatted and are sent in a precise order so that they can be generated and read by networked computer applications on each end of the connection.

Back to Book’s Main Index