Threads (conversations): list and search, get with every message, label changes, trash and untrash.
Scopes. Listing and get-thread use gmail.readonly; label
changes, trash and untrash gmail.modify.
Functions
get-thread
fn (id: Str): Map
fn (id: Str, opts: Map): Map
GET /users/me/threads/{id} - a thread with its messages (oldest
first). Options: format (full default, metadata with
metadataHeaders, minimal). Scope: gmail.readonly.
Example
thread ::google::gmail::threads/get-thread("18f2a")
length(thread.messages)
// Only the headers you need
::google::gmail::threads/get-thread("18f2a", {format: "metadata", metadataHeaders: ["From", "Subject"]})
list-all-threads
fn (opts: Any): Vec
fn (opts: Any, limit: Int?): Vec
Every matching thread (all pages), or at most limit. Same opts as
list-threads (a Str is a search). Scope: gmail.readonly.
Example
threads ::google::gmail::threads/list-all-threads("is:starred", 100)
length(threads)
list-threads
fn (): Map
fn (query: Str): Map
fn (opts: Map): Map
GET /users/me/threads - one page of threads: {threads: [{id, snippet, historyId}], nextPageToken?, resultSizeEstimate}. A Str
argument is a Gmail search. Options: q, maxResults (max 500),
pageToken, labelIds (Vec), includeSpamTrash. Scope:
gmail.readonly.
Example
page ::google::gmail::threads/list-threads("label:inbox newer_than:7d")
map(or(page.threads, []), %.id)
// Gmail's own parameters
::google::gmail::threads/list-threads({labelIds: ["STARRED"], maxResults: 50})
modify-thread
fn (id: Str, add-label-ids: Vec, remove-label-ids: Vec): Map
fn (id: Str, add-label-ids: Vec, remove-label-ids: Vec, opts: Map): Map
POST /users/me/threads/{id}/modify - add and remove label ids on every
message in a thread. Returns the thread. Scope: gmail.modify.
Example
::google::gmail::threads/modify-thread("18f2a", ["STARRED"], ["UNREAD"])
thread-emails
fn (id: Str): Vec
fn (id: Str, opts: Map): Vec
A thread's messages as Email records, oldest first (get-thread +
::google::gmail::parse/to-email). Scope: gmail.readonly.
Example
emails ::google::gmail::threads/thread-emails("18f2a")
map(emails, %.subject)
trash-thread
fn (id: Str): Map
fn (id: Str, opts: Map): Map
POST /users/me/threads/{id}/trash - move a whole thread to the trash
(recoverable for 30 days). Scope: gmail.modify.
Example
::google::gmail::threads/trash-thread("18f2a")
untrash-thread
fn (id: Str): Map
fn (id: Str, opts: Map): Map
POST /users/me/threads/{id}/untrash - restore a thread from the trash.
Scope: gmail.modify.
Example
::google::gmail::threads/untrash-thread("18f2a")