AbstractAbstractconnectOpens a connection to an IMAP server and authenticates.
Server address, port, TLS setting, and credentials
An opaque session handle for subsequent operations
AbstractlistLists all mailboxes (folders) on the server.
Session handle from connect()
Array of mailbox descriptors
AbstractselectSelects a mailbox for subsequent search/fetch/flag operations.
Session handle from connect()
Mailbox name (e.g. "INBOX")
Mailbox status including message count and UID validity
AbstractsearchSearches for messages matching the given criteria in the selected mailbox.
All criteria fields are ANDed together. Returns UIDs (not sequence numbers).
Session handle from connect()
Search criteria (all optional, ANDed)
Array of matching message UIDs
AbstractfetchFetches message data for the given UIDs.
By default fetches headers only. Set body: true in options to include
message body content. The implementation handles MIME decoding internally.
Session handle from connect()
Array of message UIDs to fetch
Optionaloptions: ImapFetchOptionsWhat to fetch (headers, body, body type)
Array of message objects with requested fields populated
AbstractsetModifies flags on messages.
Common flags: "\Seen" (read), "\Flagged" (starred), "\Deleted" (marked for deletion).
Session handle from connect()
Array of message UIDs to modify
Flags to add/remove/set (e.g. ["\Seen"])
"add", "remove", or "set" (replace all flags)
AbstractdisconnectCloses the IMAP connection.
Always call this when done, preferably in a finally block.
Session handle from connect()
AbstractwatchStarts (or updates) a server-maintained IMAP IDLE push watch on a
mailbox. The platform holds the connection open and invokes callback
whenever the mailbox changes (new mail, flag changes), so the connector
can run an incremental sync within seconds instead of waiting for its
next poll.
Idempotent upsert per key: re-calling with the same options while the
watch is healthy is a cheap no-op, so connectors should re-arm the watch
from their recurring poll — that both restarts a watch the platform may
have dropped and refreshes rotated credentials. Calling with changed
options reconnects with the new configuration.
The callback is invoked with no additional arguments — bind what you
need (e.g. the channel id) when creating it. Expect bursts: route the
callback through scheduleDrain rather than syncing inline. Push can be
lossy across reconnects (the platform catches up on reconnect, but keep
a recurring poll as the outer safety net).
Stable watch identity within this connector instance (e.g. the channel id). One live watch per key.
Server, credentials, and mailbox to watch. The host must be in the declared hosts list.
Token from this.callback(...) to invoke on changes
AbstractunwatchStops the push watch for key and discards its stored configuration.
Call from onChannelDisabled (and any other teardown path). No-op if
no watch exists.
The key the watch was created with
AbstractfetchFetches the raw, decoded bytes of one MIME part of a message — typically
an attachment discovered via fetchMessages()'s attachments field.
Issues a separate FETCH for just that part (attachment bytes are not
included by fetchMessages(), which only reports part metadata), and
decodes the part's content per its own Content-Transfer-Encoding
(base64 or quoted-printable) to raw bytes.
Session handle from connect()
Message UID (from fetchMessages())
IMAP part number, e.g. attachments[i].partNumber
from fetchMessages() (like "2" or "2.1")
The part's raw decoded bytes
Built-in tool for IMAP email access.
Provides high-level IMAP operations for reading email and managing flags. Handles TCP/TLS connections, IMAP protocol details, and MIME decoding internally.
Permission model: Connectors declare which IMAP hosts they need access to. Connections to undeclared hosts are rejected.
Example