Skip to contents

Adds and/or removes labels on a thread in one call. Accepts user-defined label names or Gmail system labels (INBOX, STARRED, UNREAD, IMPORTANT, TRASH, SPAM, SENT, DRAFT). Covers common operations beyond "labeling": archive (remove = "INBOX"), star (add = "STARRED"), trash (add = "TRASH"), mark-read (remove = "UNREAD").

Usage

mc_thread_modify(thread_id, add = NULL, remove = NULL)

Arguments

thread_id

Gmail thread ID (e.g. from mc_thread_find()).

add

Character vector of label names to add. NULL for none.

remove

Character vector of label names to remove. NULL for none.

Value

Invisibly returns the gmailr response.

Details

Pass names, not IDs. User-label names resolve to opaque IDs via gmailr::gm_labels(). System labels pass through unchanged. When a user label's name collides with a system label ID (e.g. a user label named "STARRED"), the system interpretation wins — almost always what's intended.

At least one of add or remove must be non-NULL. The gm_labels() call is skipped entirely when every input is a system label.

Examples

if (FALSE) { # \dontrun{
# Apply a user label
mc_thread_modify("18171fb2cec08e9d", add = "Clients/Acme")

# Archive and mark read in one call
mc_thread_modify("18171fb2cec08e9d", remove = c("INBOX", "UNREAD"))

# Star a thread
mc_thread_modify("18171fb2cec08e9d", add = "STARRED")

# Status transition
mc_thread_modify("18171fb2cec08e9d", add = "Done", remove = "Pending")
} # }