Package org.bluezoo.gumdrop.imap.client
package org.bluezoo.gumdrop.imap.client
Non-blocking IMAP client for accessing remote mailboxes.
This package provides an asynchronous, event-driven IMAP client for accessing email messages, with support for STARTTLS (explicit TLS), implicit TLS (IMAPS), SASL authentication, tagged command tracking, FETCH with literal streaming, APPEND, IDLE, and unsolicited mailbox event delivery.
Key Components
IMAPClient- High-level facade for connecting to IMAP serversIMAPClientProtocolHandler- Handles IMAP protocol exchanges with tagged command tracking and literal byte-countingServerGreeting- Entry point callback interface for receiving the initial greetingClientNotAuthenticatedState- State interface for NOT AUTHENTICATED commandsClientAuthenticatedState- State interface for AUTHENTICATED commandsClientSelectedState- State interface for SELECTED commandsMailboxInfo- Selected mailbox metadata from SELECT/EXAMINEFetchData- Structured FETCH response data per message
Features
- Non-blocking I/O using the shared SelectorLoop
- STARTTLS support for upgrading to encrypted connections (RFC 9051 section 6.2.1)
- Implicit TLS (IMAPS, port 993, RFC 8314 section 3.3)
- SASL authentication with initial response (RFC 9051 section 6.2.2, RFC 4959)
- LOGIN authentication
- Tagged command tracking with auto-generated tags
- Streaming FETCH body literal data via ByteBuffer chunks
- APPEND with continuation and content streaming
- IDLE for server-push mailbox notifications
- Unsolicited mailbox event delivery via MailboxEventListener
- Type-safe stateful handler pattern enforcing correct command sequences
- Async DNS resolution via the gumdrop DNSResolver
Stateful Handler Pattern
The IMAP client uses a stateful handler pattern where different interfaces are provided at each stage of the protocol, ensuring that only valid commands can be issued at each point. This provides compile-time safety against protocol violations.
Usage Example
IMAPClient client = new IMAPClient(selectorLoop, "imap.example.com", 143);
client.setSSLContext(sslContext);
client.connect(new ServerGreeting() {
public void handleGreeting(ClientNotAuthenticatedState auth,
String greeting,
List<String> preAuthCapabilities) {
auth.login("alice", "secret", new ServerLoginReplyHandler() {
public void handleAuthenticated(ClientAuthenticatedState session,
List<String> capabilities) {
session.select("INBOX", selectHandler);
}
public void handleAuthFailed(ClientNotAuthenticatedState auth,
String message) {
auth.logout();
}
public void handleServiceClosing(String message) { }
});
}
public void handlePreAuthenticated(ClientAuthenticatedState auth,
String greeting) {
auth.select("INBOX", selectHandler);
}
public void handleServiceUnavailable(String message) { }
public void onConnected(Endpoint endpoint) { }
public void onSecurityEstablished(SecurityInfo info) { }
public void onError(Exception cause) { cause.printStackTrace(); }
public void onDisconnected() { }
});
- Author:
- Chris Burdess
- See Also:
-
ClassesClassDescriptionStructured data from an IMAP FETCH response (RFC 9051 section 7.4.2), representing the non-literal data items for a single message.IMAP ENVELOPE structure from a FETCH response.High-level IMAP4rev2 client facade (RFC 9051).IMAP4rev2 client protocol handler (RFC 9051).Information about a selected IMAP mailbox, populated from SELECT/EXAMINE response data (RFC 9051 section 7.3.1).