Skip to Content

List conversation threads.

Returns conversation threads, newest activity first, one row per conversation: participants, message and unread counts, and an exemplar message carrying the subject and snippet a row renders. Grouping is by REPLY CHAIN (In-Reply-To/References), never by subject — two unrelated messages sharing a subject are two conversations, and a renamed reply stays in the one it answers. Filtering by label and by unread/starred flags uses Gmail semantics: a conversation matches when ANY of its live members does, and the counts then span the whole conversation — but the exemplar is the newest member that MATCHED, so a label-filtered row is faced with the message that folder actually holds. See ThreadListItem.exemplar. Trash and Junk are HIDDEN ROLES: outside their own views a conversation is its live members carrying neither label — they do not qualify a row, are not counted, faced or listed in participants/labels. label=Trash lists conversations by their trashed members and label=Junk by their junked ones; a member in both is in the bin (shown in Trash, hidden in Junk). excludeRoles adds to that rule and never lifts it.

openemail.threads.list(
  mailboxId: string,
  options?: ThreadsListOptions,
): PagePromise<ThreadsListResult, ThreadListItem>

It calls GET /mailboxes/{mailboxId}/threads: List conversation threads in the API reference.

Example

for await (const threadListItem of openemail.threads.list(mailboxId)) {
  // every item of every page (await the call instead for one page)
}

Arguments

ArgumentTypeDescription
mailboxIdstringMailbox ULID identifier. The path's {mailboxId}.

Options

The last argument, options, a ThreadsListOptions, takes:

OptionTypeSent asDescription
labelstringquery labelFilter threads containing messages with this label (e.g. INBOX)
excludeRoles('inbox' | 'sent' | 'drafts' | 'trash' | 'archive' | 'junk')[]query excludeRolesSystem label roles to exclude: 'inbox', 'sent', 'drafts', 'trash', 'archive', 'junk' (e.g. 'trash,junk'). Unknown roles return 400 validation_failed.
cursorstringquery cursorPagination cursor from previous page
limitnumberquery limitMaximum threads to return per page (max 100)
order('asc' | 'desc')query orderListing direction: desc (default) = newest first, asc = oldest first. Hold it constant across a cursor crawl — cursors do not encode direction, so switching mid-crawl re-windows the page rather than erroring
sortBy('arrival' | 'date')query sortBySort key: arrival (default) = the order mail reached this mailbox (message id); date = the Date header, falling back to arrival where it is absent or unparseable (RFC 5256 SORT DATE). Cursors follow the key, so hold it constant across a crawl — unlike order, a mismatched cursor is refused with 400 invalid_cursor rather than silently re-windowing. Note that under arrival an imported message (APPEND with ?internaldate=) lists where it was imported, not at its receivedAt; date orders imported mail by its own header
hasFlagsstringquery hasFlagsComma-separated flag names; a message matches only if ALL are set (e.g. flagged)
notFlagsstringquery notFlagsComma-separated flag names; a message matches only if NONE are set (e.g. seen, for unread-only)

Every call also takes signal, timeout, retry and headers, which say how that one call is sent (call options).

Answer

It is a listing, a PagePromise. Awaited, it is one page as the API answers it, ThreadsListResult. Iterated with for await, it is every ThreadListItem of every page, each page fetched as the loop reaches it.

Errors

StatusWhat it means
400validation_failed — invalid query parameters or mismatched cursor
401unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a WWW-Authenticate: Bearer challenge
404Mailbox not found or label not found
503temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description)

A failed call rejects with a RequestError: its status, and its code, the API's error. Decide on the code: one status covers several.

Types

ThreadsListResult

/** What `threads.list` answers. */
type ThreadsListResult = {
  /** Opaque cursor for the next page; absent on the last page */
  nextCursor?: string
  threads: ThreadListItem[]
}

It names these types of the API, each on a page of its own: ThreadListItem.