IMAP

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Introduction

IMAP is a protocol that allows you to browse your email online. Unlike POP, it isn't geared towards downloading your email to a local client. However, it can be used that way.

Specifications

See http://www.imap.org/ for the latest and history of IMAP.

RFC 3501: Internet Message Access Protocol - Version 4rev1 is the current specification.

Overview

IMAP, unlike HTTP, is stateful. That means that each request you make to the server is in the context of the history of requests you have made so far. Previous requests may change the nature of the current request.

IMAP is also asynchronous. That means that you can make several requests at once, and receive a response for them in any order.

These are the reasons why IMAP is so interesting to me.

Connection States

There are only 4 states the connection can be in.

  • Not Authenticated. The client has not yet presented authentication credentials.
  • Authenticated. The client is authenticated, but hasn't selected a mailbox.
  • Selected: The client has selected a mailbox.
  • Logout: The client is disconnecting.

The state transitions are as follows:

  • Upon connection, the state can go to the Not Authenticated, Authenticated, or Logout states.
  • From any other state, the state can go to the Logout state.
  • From the Not Authenticated state, the state can go to the Authenticated state.
  • From the Authenticated state, the state can go to Selected, and vice-versa.

Client Commands

The client issues commands to the server. The client prefixes each command with a unique identifier. This is how the server will reference the command later on. Usually, commands are contained on a single line. Some commands may require further interaction to complete. The client usually has to wait for a response from the server before continuing the command in these cases.

The commands are organized by the state they are allowed in.

Any State

  • CAPABILITY - Ask what the system can do.
  • NOOP - Don't do anything. This is used to keep the connection alive.
  • LOGOUT - Go to the logout state.

Not Authenticated State

  • STARTTLS - Change to communication over TLS.
  • AUTHENTICATE - Authenticate using some other method than login.
  • LOGIN - login using cleartext username and password. (If the connection is TLS, then it won't be cleartext, obviously.)

Authenticated State

  • SELECT mailbox - Select a mailbox (go to the selected state)
  • EXAMINE mailbox - Select a mailbox in read only mode.
  • CREATE name - Create a new mailbox.
  • DELETE mailbox - Delete a mailbox.
  • RENAME 'mailbox name - Rename a mailbox.
  • SUBSCRIBE mailbox - Get notified of changes to the mailbox.
  • UNSUBSCRIBE mailbox - Stop getting notified of changes to the mailbox.
  • LIST reference wildcard - Get the mailboxes that match wildcard under reference.
  • LSUB reference wildcard - Returns a subset of the mailboxes that the client has subscribed to already.
  • STATUS mailbox attributes - Asks for the attributes of the mailbox.
  • APPEND - Adds a message to a mailbox.

Selected State

  • CHECK -

Logout State

Server Responses

Server responses to command are always prefixed with '+'. Other responses are prefixed with a '*'.