Class IMAP.

Inherits SaslConnection. Inherited by IMAPS.

This class implements the IMAP server as seen by clients.

This class is responsible for interacting with IMAP clients, and for overseeing the operation of individual command handlers. It looks at client input to decide which Command to defer the real work to, and ensures that the handler is called at the appropriate times.

Each IMAP object has a state() (RFC 3501 section 3), and may possess other state information, such as the user() logged in or a session(). The Idle state (RFC 2177) is also kept here.

The IMAP class parses incoming commands as soon as possible and may keep several commands executing at a time, if the client issues that. It depends on Command::group() to decide whether each parsed Command can be executed concurrently with the already running Command objects.

IMAP::IMAP( int s )

Creates an IMAP server on file descriptor s, and sends an initial OK[CAPABILITY...] response to the client.

void IMAP::addCommand()

This function parses enough of the command line to create a Command, and then uses it to parse the rest of the input.

void IMAP::addMailboxGroup( MailboxGroup * m )

Records that m is a (possibly) active mailbox group.

void IMAP::beginSession( ImapSession * s )

Switches to Selected state and operates on the mailbox session s. If the object already had a session, ends the previous session.

bool IMAP::clientSupports( ClientCapability capability ) const

Returns true if the client has shown that it supports a given capability, and false if this is still unknown.

List<Command> * IMAP::commands() const

Returns a list of all Command objects currently known by this IMAP server. First received command first. Commands in all states may be in the list, except Retired.

void IMAP::defeatNat()

Called regularly to ensure that we send an untagged OK every minute or so, in order to ensure a steady stream of packets. Some NAT gateways will kill the connection after as little as two minutes if no traffic is seen.

void IMAP::emitResponses()

Emits those responses which can be emitted at this time.

void IMAP::endSession()

This function deletes any existing ImapSession associated with this server, whose state changes to Authenticated. It does nothing unless the server has a session().

EventMap * IMAP::eventMap() const

Returns a pointer to the event map currently in force. This is never a null pointer; IMAP sets up a suitable map when it starts.

bool IMAP::idle() const

Returns true if the server has no particular work to do to server the peer(), and false if it's currently working on behalf of peer().

If there are no commands, a connection is idle(). If the command currently being executed is Idle, the connection is also idle.

MailboxGroup * IMAP::mostLikelyGroup( Mailbox * m, uint l )

Returns the MailboxGroup most likely to be the one the client is working on, assuming that the client performs an operation on m.

Returns a null pointer if the client doesn't seem to be working on any easily defined group, or if it is working on one, but MailboxGroup::hits() returns a value less than l.

void IMAP::parse()

Reads input from the client, and feeds it to the appropriate Command handlers.

bool IMAP::prefersAbsoluteMailboxes() const

Returns whatever setPrefersAbsoluteMailboxes() set.

void IMAP::react( Event e )

Handles the incoming event e as appropriate for its type.

Reimplements Connection::react().

void IMAP::recordSyntaxError()

Reimplemented in order to record the time, so we can rate-limit bad IMAP commands in runCommands();

Reimplements SaslConnection::recordSyntaxError().

void IMAP::removeMailboxGroup( MailboxGroup * m )

Records that m is no longer active. MailboxGroup calls this, noone else needs to.

void IMAP::reserve( Command * command )

Reserves input from the connection for command.

When more input is available, Command::read() is called. Command::finish() releases control.

void IMAP::respond( ImapResponse * response )

Records that response needs to be sent at the earliest possible date. When is the earliest possible date? Well, it depends on response, on the commands active and so on.

void IMAP::restartNatDefeater()

Restarts the timing logic we use to send little OK response in order to defeat too-quick NAT timeouts.

void IMAP::run( Command * c )

Executes c once, provided it's in the right state, and emits its responses.

void IMAP::runCommands()

Calls Command::execute() on all currently operating commands, and if possible calls Command::emitResponses() and retires those which can be retired.

ImapSession * IMAP::session() const

Returns a pointer to the ImapSession object associated with this IMAP server, or 0 if there is none (which can happen only if the server is not in the Selected state).

void IMAP::setClientSupports( ClientCapability capability )

Records that the client supports capability. The initial value is valse for all capabilities, and there is no way to disable a capability once enabled.

void IMAP::setEventMap( EventMap * map )

Records that IMAP should base its notification decisions on map henceforth. map must not be null.

void IMAP::setPrefersAbsoluteMailboxes( bool b )

Records that the IMAP client likes to see its mailbox names in absolute form (ie. /users/kiki/lists/mja instead of lists/mja) if b is true, and that it prefers relative names otherwise. The initial value is false.

void IMAP::setState( State s )

Sets this IMAP connection to be in state s. The initial value is NotAuthenticated.

void IMAP::setUser( User * user, const EString & mechanism )

Notifies the IMAP object that user was successfully authenticated by way of mechanism. This changes the state() of the IMAP object to Authenticated.

Reimplements SaslConnection::setUser().

static void IMAP::setup()

This setup function expects to be called from ::main().

It reads and validates any relevant configuration variables, and logs a disaster if it encounters an error.

State IMAP::state() const

Returns the current state of this IMAP session, which is one of NotAuthenticated, Authenticated, Selected and Logout.

Reimplements Connection::state().

void IMAP::unblockCommands()

Causes any blocked commands to be executed if possible.

This web page based on source code belonging to The Archiveopteryx Developers. All rights reserved.