Labels: list, get, create, update, delete, find by name, and
ensure-label. System labels (INBOX, UNREAD, STARRED,
IMPORTANT, SPAM, TRASH, SENT, DRAFT, CATEGORY_*) have ids
equal to their names; user labels have generated ids (Label_12).
Nested labels use / in the name ("Clients/Acme").
Scopes. Reads use gmail.readonly; create, update and delete
gmail.labels (gmail.modify also works).
Values
LABEL_FIELDS
LABEL_FIELDS: Vec [
"labelListVisibility",
"messageListVisibility",
"color"
]
Functions
build-label
fn (name: Str, opts: Map): Map
The label body for create-label (pure): {name} plus any of
labelListVisibility (labelShow, labelShowIfUnread, labelHide),
messageListVisibility (show, hide) and color ({textColor, backgroundColor} from Gmail's palette) found in opts.
Example
::google::gmail::labels/build-label("Clients/Acme", {labelListVisibility: "labelHide"}) // {name: "Clients/Acme", labelListVisibility: "labelHide"}
create-label
fn (name: Str): Map
fn (name: Str, opts: Map): Map
POST /users/me/labels - create a user label. Options: see build-label.
Gmail rejects a duplicate name with 409; use ensure-label to reuse an
existing one. Scope: gmail.labels.
Example
label ::google::gmail::labels/create-label("Clients/Acme", {
labelListVisibility: "labelShow",
color: {textColor: "#ffffff", backgroundColor: "#16a766"}
})
label.id
delete-label
fn (id: Str): Bool
fn (id: Str, opts: Map): Bool
DELETE /users/me/labels/{id} - delete a user label (it is removed from
every message; the messages stay). Returns true. Scope: gmail.labels.
Example
::google::gmail::labels/delete-label("Label_12")
ensure-label
fn (name: Str): Map
fn (name: Str, opts: Map): Map
The label named name, created when missing. Scopes: gmail.readonly
and gmail.labels.
Example
label ::google::gmail::labels/ensure-label("Clients/Acme")
::google::gmail::messages/modify-message("18f2a", [label.id], [])
find-label
fn (name: Str): Map?
fn (name: Str, opts: Map): Map?
The label whose name equals name (case-insensitive), or null. Scope:
gmail.readonly.
Example
label ::google::gmail::labels/find-label("clients/acme")
if(is-some(label), label.id, "no such label")
get-label
fn (id: Str): Map
fn (id: Str, opts: Map): Map
GET /users/me/labels/{id} - one label with its message and thread
counts. Scope: gmail.readonly.
Example
label ::google::gmail::labels/get-label("INBOX")
label.messagesUnread
list-labels
fn (): Map
fn (opts: Map): Map
GET /users/me/labels - every label in the mailbox: {labels: [{id, name, type, ...}]} (not paginated). Scope: gmail.readonly.
Example
result ::google::gmail::labels/list-labels()
map(result.labels, %.name)
update-label
fn (id: Str, changes: Map): Map
fn (id: Str, changes: Map, opts: Map): Map
PATCH /users/me/labels/{id} - change the given fields of a user label
(name, labelListVisibility, messageListVisibility, color).
Scope: gmail.labels.
Example
::google::gmail::labels/update-label("Label_12", {name: "Clients/Acme Corp", messageListVisibility: "hide"})