Drafts: create (including a threaded reply draft for a human to
review), update, send, list, get, delete. Messages are built with
::google::gmail::mime and switch to the media-upload endpoint above
5 MiB, as for sending.
Scopes. gmail.compose for everything except reads, which use
gmail.readonly. create-reply-draft also reads the original
(gmail.readonly).
Functions
create-draft
fn (message: Map): Map
fn (message: Map, opts: Map): Map
POST /users/me/drafts - save a draft from a message Map (same fields
as ::google::gmail::messages/send). Options: thread-id, upload.
Returns {id, message: {id, threadId, labelIds}}. Scope:
gmail.compose.
Example
draft ::google::gmail::drafts/create-draft({to: "ada@example.com", subject: "Q3 plan", text: "First pass."})
draft.id
// In an existing thread
::google::gmail::drafts/create-draft({to: "ada@example.com", subject: "Re: Q3 plan", text: "Second pass."}, {thread-id: "18f2a"})
create-reply-draft
fn (message-id: Str, reply: Map): Map
fn (message-id: Str, reply: Map, opts: Map): Map
Draft a reply to a message, threaded and addressed like
::google::gmail::messages/reply, for a person to review and send.
all: true in opts drafts a reply-all. Scopes: gmail.readonly and
gmail.compose.
draft ::google::gmail::drafts/create-reply-draft("18f2a", {text: "Proposed answer..."})
delete-draft
fn (draft-id: Str): Bool
fn (draft-id: Str, opts: Map): Bool
DELETE /users/me/drafts/{id} - discard a draft (immediately and
permanently; it does not go to the trash). Returns true. Scope:
gmail.compose.
Example
::google::gmail::drafts/delete-draft("r-123")
draft-body
fn (raw: Bytes, thread-id: Str?, draft-id: Str?): Map
The JSON body for drafts.create / drafts.update (pure): {id?, message: {raw, threadId?}}.
Example
::google::gmail::drafts/draft-body(Bytes("Hi"), "t1", "d1") // {id: "d1", message: {raw: "SGk", threadId: "t1"}}
get-draft
fn (draft-id: Str): Map
fn (draft-id: Str, opts: Map): Map
GET /users/me/drafts/{id} - a draft with its message. Options: format
(full default, metadata, minimal, raw). Scope: gmail.readonly.
Example
draft ::google::gmail::drafts/get-draft("r-123")
::google::gmail::parse/to-email(draft.message).subject
list-all-drafts
fn (opts: Map): Vec
fn (opts: Map, limit: Int?): Vec
Every draft (all pages), or at most limit. Scope: gmail.readonly.
Example
drafts ::google::gmail::drafts/list-all-drafts({}, 100)
length(drafts)
list-drafts
fn (): Map
fn (opts: Map): Map
GET /users/me/drafts - one page of drafts: {drafts: [{id, message: {id, threadId}}], nextPageToken?}. Options: q, maxResults (max 500),
pageToken, includeSpamTrash. Scope: gmail.readonly.
Example
page ::google::gmail::drafts/list-drafts({maxResults: 20})
map(or(page.drafts, []), %.id)
send-draft
fn (draft-id: Str): Map
fn (draft-id: Str, opts: Map): Map
POST /users/me/drafts/send - send an existing draft as is. Returns the
sent message; the draft is removed. Scope: gmail.compose.
Example
sent ::google::gmail::drafts/send-draft("r-123")
sent.threadId
update-draft
fn (draft-id: Str, message: Map): Map
fn (draft-id: Str, message: Map, opts: Map): Map
PUT /users/me/drafts/{id} - replace a draft's message (all fields; Gmail
keeps nothing from the old one). Options: thread-id, upload. Scope:
gmail.compose.
Example
::google::gmail::drafts/update-draft("r-123", {to: "ada@example.com", subject: "Q3 plan", text: "Revised."})