The IMAP Protocol (Part 2):
This command set is more complex than the one used by POP because IMAP does more. The protocol is designed to remotely maintain mailboxes that are stored on the server, and the protocol commands clearly illustrate the "mailbox" orientation of IMAP. Despite the increased complexity of the protocol, it is still possible to run a simple test of your IMAP server using telnet and a small number of the IMAP commands. The following listing shows this.
$ telnet localhost imap
Trying 127.0.0.1...
Connected to ani.foobirds.org.
Escape character is '^]'.
* OK [CAPABILITY IMAP4 IMAP4REV1 STARTTLS LOGIN-REFERRALS
ÄAUTH=LOGIN] ani.foobirds.org IMAP4rev1 2000.287rh
Äat Mon, 6 May 2002 17:36:57 -0400 (EDT)
a0001 login craig Wats?Watt?
a0001 OK LOGIN completed
a0002 select inbox
* 3 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 965125671] UID validity status
* OK [UIDNEXT 5] Predicted next UID
* FLAGS (\Answered \Flagged \Deleted \Draft \Seen)
* OK [PERMANENTFLAGS (\* \Answered \Flagged \Deleted
Ä\Draft \Seen)] Permanent flags
* OK [UNSEEN 1] first unseen message in /var/spool/mail/craig
a0002 OK [READ-WRITE] SELECT completed
a0003 fetch 1 body[text]
* 1 FETCH (BODY[TEXT] {1440}
... an e-mail message that is 1440 bytes long ...
* 1 FETCH (FLAGS (\Seen))
a0003 OK FETCH completed
a0004 store 1 +flags \deleted
* 1 FETCH (FLAGS (\Seen \Deleted))
a0004 OK STORE completed
a0005 close
a0005 OK CLOSE completed
a0006 logout
* BYE ani.foobirds.org IMAP4rev1 server terminating connection
a0006 OK LOGOUT completed
Connection closed by foreign host.
Again, the first three lines and the last line come from telnet; all other messages come from IMAP.
The first IMAP command entered by the user is LOGIN, which provides the username and
password from /etc/passwd
used to authenticate this user. Notice that the command is preceded by
the string a0001. This is a tag, which is a unique identifier generated by the client for each
command. Every command must start with a tag. When you manually type in commands for a test,
you are the source of the tags.