# Search

> Search cached mail across mailboxes and accounts.

---

LLMS index: [llms.txt](/llms.txt)

---

`GET /api/search` searches the local cache across every account. By default it
matches **metadata only** — subject, sender and recipient fields — so even a
large mailbox answers quickly. Set `body=1` to extend the query to message
bodies.

| Query | Default | Description |
| --- | --- | --- |
| `q` | — | Text to look for in the subject, sender and recipient fields (plus snippet and body text when `body=1`) |
| `from` | — | Only messages whose sender name or address contains this text |
| `subject` | — | Only messages whose subject contains this text |
| `since` | — | Only messages dated on or after this Unix timestamp (seconds) |
| `until` | — | Only messages dated on or before this Unix timestamp (seconds) |
| `body` | `0` | `1`/`true` also matches the snippet and body text of cached bodies |
| `account` | `0` (all) | Restrict results to one account ID |
| `limit` | `50` | Maximum results, capped at `200` |
| `offset` | `0` | Skip this many results, for paging |

At least one of `q`, `from`, `subject`, `since` or `until` is required;
otherwise the endpoint returns `400`. An inverted range (`since > until`) is
also rejected with `400`.

```bash
# Metadata search across all accounts
curl 'http://127.0.0.1:8787/api/search?q=invoice'

# Advanced: sender + subject + date range
curl 'http://127.0.0.1:8787/api/search?from=billing@example.com&subject=invoice&since=1764547200&until=1765151999'

# Body search, second page
curl 'http://127.0.0.1:8787/api/search?q=renewal&body=1&limit=50&offset=50'
```

Results are message summaries ordered newest first (`date` descending, ties
broken by `id` descending), and include the account and mailbox path so you
can tell where each hit lives:

```json
[
  {
    "id": 42,
    "accountId": 1,
    "mailboxId": 1,
    "mailbox": "INBOX",
    "uid": 507,
    "messageId": "<abc@example.com>",
    "subject": "Invoice for November",
    "from": [{"name": "Billing", "address": "billing@example.com"}],
    "date": 1764500000,
    "snippet": "Your invoice is attached…",
    "seen": true,
    "flagged": false,
    "hasAttachments": true,
    "size": 48211
  }
]
```

Use [read message](../messages/#read-one-message) with a result `id` to fetch
the full body.

## Web interface

- Type in the search box above the message list and press Enter to search all
  accounts. Press `/` anywhere in the app to jump to the search box.
- Each hit carries a chip naming its source account; opening a hit works
  across accounts.
- Expand **Advanced search** for sender, subject, date range, and the
  **Also search message body** checkbox.
- Press Esc or click the × button to leave the results and return to the
  previous mailbox.

## Scope and limits

- Search covers **only locally cached messages**. Run a
  [sync](../mailboxes/) first if the mailbox was never fetched.
- Matching is a case-insensitive `LIKE` substring; `%` and `_` in the query
  are escaped, so they match literally. Sender matching runs over the stored
  address JSON, so the literal words `name` and `address` can also match.
- `body=1` only searches bodies that are already cached — Pigeon fetches
  bodies lazily, so opening messages populates the searchable set over time.
  Body searches are slower on large mailboxes.
- There is no dedicated full-text index yet — predicates run over SQLite's
  `LIKE`. The date index keeps newest-first paging over the whole cache cheap.

MCP clients can call the equivalent `search_messages` tool; see
[MCP Server](../mcp/).

---

Backlinks:

- [Documentation](/docs/)
- [REST API Basics](/docs/api/)
