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

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: