---
title: "Threads, labels and search"
description: "How mail is grouped into threads, the system labels and your own, full-text search, changes to many messages at once, and deleting."
url: "https://docs.yoagent.dev/email/threads-labels-and-search"
---

# Threads, labels and search

## Threads

A thread is a conversation in one inbox. A received message joins the thread of the message it answers, found by its `In-Reply-To` and `References` headers — never by its subject, so two unrelated emails called “Welcome” stay apart. A reply you send stays in its message’s thread; a new message and a forward start a new one.

`GET /v0/threads` (MCP: `list_threads`) lists an inbox’s threads, the latest first, each with its `subject`, `labels`, `message_count` and `last_message_at`; `GET /v0/threads/{thread_id}` (`get_thread`) lists its messages, oldest first.

## Labels

Labels mark messages and threads. YoAgent sets its **system labels** itself:

| Label                                            | On                                                                                                                               |
| ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| `received`                                       | Every message that came in                                                                                                       |
| `unread`                                         | New mail; reading it removes the label                                                                                           |
| `unauthenticated`                                | Mail whose sender nothing proves ([Receive and read email](https://docs.yoagent.dev/email/receive-and-read-email))               |
| `parse_failed`                                   | Mail that could not be read as MIME; the raw message is kept                                                                     |
| `sent`                                           | The inbox’s own sent copies                                                                                                      |
| `delivered`, `bounced`, `complained`, `rejected` | Sent mail, by what happened to its recipients ([Send, reply and forward](https://docs.yoagent.dev/email/send-reply-and-forward)) |

Of these, only `unread` is yours to change: mark a message read by removing it, unread by adding it. The others are facts about the message and cannot be set or removed.

**Your own labels** — `verified`, `needs-reply`, `billing` — belong to a project and can go on any of its messages and threads: lower-case letters, digits, `_`, `.`, `:` and `-`. Put a label on mail and it is created; or create one first:

**curl**

```bash
curl -s https://api.yoagent.dev/v0/labels \
  -H "Authorization: Bearer $YOAGENT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name": "verified", "inbox_id": "test@k7m2xq4p.yoagent.email"}'
```

**MCP**

```text
create_label(name="verified", inbox_id="test@k7m2xq4p.yoagent.email")
```

Give the project as `project_id`, or one of its inboxes as `inbox_id`. A name the project has already returns that label. Renaming (`PATCH /v0/labels/{label_id}`) changes it on all its mail; deleting (`POST /v0/labels/delete`) takes it off all its mail. A message or thread carries up to 50 labels; a project has up to 500.

In the dashboard, an inbox’s mail is in **Folders** — Inbox (received), Unread, Read, Sent, All mail and Parse failed — and your own **Labels** below them.

![An inbox in the dashboard: its folders and own labels on the left, the messages of a label on the right](https://docs.yoagent.dev/_astro/labels.Dht1CgkZ_2g1G7c.webp)

## Search

`search` on `GET /v0/messages` and `GET /v0/threads` (MCP: `list_messages`, `list_threads`) finds mail by its words: the subject, the body, every party’s name and address, and attachment names.

```bash
curl -s -G https://api.yoagent.dev/v0/messages \
  -H "Authorization: Bearer $YOAGENT_KEY" \
  --data-urlencode "inbox_id=support@k7m2xq4p.yoagent.email" \
  --data-urlencode "search=invoice -paid" \
  --data-urlencode "labels=unread"
```

Every word must match; `or` between two words matches either, and `-word` leaves out mail that has it. Quotes don’t make a phrase. `GET /v0/messages` also narrows by `from`, `subject`, `to` (the exact address mail was sent to), `labels` (all of them), `exclude_labels` (none of them), `after` and `before`.

## Many messages at once

`POST /v0/messages/update` (MCP: `update_messages`) adds and removes labels on up to 200 messages:

```json
{
  "message_ids": [
    "msg_01je56wqswfmn9pgbc1wq8tjgq",
    "msg_01je56wqswfmn9pgbc1wq8tjgr"
  ],
  "add_labels": ["verified"],
  "remove_labels": ["unread"]
}
```

It changes all of them or none: a message the key cannot see is `404`, one it may not change is `403`. `POST /v0/messages/delete` (`delete_messages`) deletes up to as many.

## Delete

| What          | REST                               | MCP               |
| ------------- | ---------------------------------- | ----------------- |
| A message     | `DELETE /v0/messages/{message_id}` | `delete_message`  |
| Many messages | `POST /v0/messages/delete`         | `delete_messages` |
| A thread      | `DELETE /v0/threads/{thread_id}`   | `delete_thread`   |
| An inbox      | `DELETE /v0/inboxes/{inbox_id}`    | `delete_inbox`    |

Deleting is for good: there is no trash. A thread left with no messages goes too. A sent message still being delivered can be deleted once it is sent (`409 conflict` until then). Your plan also deletes mail older than its retention by itself ([Plans and limits](https://docs.yoagent.dev/account/plans-and-limits)).
