Mailboxes & Sync
The mailbox object
| Field | Description |
|---|---|
id |
Mailbox ID used by the messages endpoints |
accountId |
Owning account |
name |
Display name (last path segment) |
path |
Full IMAP path, e.g. INBOX, Archive/2026 |
delimiter |
Hierarchy delimiter reported by the server |
attrs |
IMAP attributes such as \Inbox, \Sent, \Drafts, \Junk, \Trash |
uidValidity, uidNext |
IMAP UID bookkeeping from the last sync |
total, unread |
Message and unseen counts from the last sync |
lastSyncAt |
Unix seconds of the last sync; 0 if never synced |
Mailboxes appear after the account’s first sync. New accounts have none until sync runs.
List mailboxes
GET /api/accounts/{id}/mailboxes
Returns an array of mailbox objects, ordered with INBOX first. The unread
values are aggregated into the account’s unread field.
Synchronizing
POST /api/accounts/{id}/sync
Each sync does the following over a fresh IMAP connection:
- Refreshes the mailbox list, creating or updating every selectable
mailbox and its counts (
STATUS), and picks up the server’s\Sentmailbox. - Selects the target mailbox (
INBOXwhen the body is empty ormailboxis omitted). - Resets the local cache if
UIDVALIDITYchanged, because UIDs are no longer comparable. - Fetches new messages with UID-based incremental sync — only UIDs above the highest one stored locally.
Response:
| Field | Description |
|---|---|
mailbox |
Path that was synchronized |
mailboxes |
Selectable mailboxes seen on the server |
newMessages |
Messages stored locally by this sync |
total, unread |
Fresh counts for the target mailbox |
What gets cached
- The first sync of a mailbox stores every message received in the last 7 days, bodies included.
- Later syncs fetch up to 200 new messages per run. Bodies are stored when the batch is at most 200 messages; larger backlogs are stored newest-first and bodies are fetched on demand when a message is opened.
- Fetching uses
BODY.PEEK, so syncing never marks mail as read. - Older messages beyond the cache are not deleted from the server and are not listed locally. Opening a cached message that lacks a body triggers a single-message body fetch.
Sync runs only when requested — there is no background scheduler yet, so call
this endpoint (or pigeon digest --sync, or the MCP sync_mailbox tool) when
you want fresh mail.
Errors contacting or authenticating with the IMAP server return 502; cached
mail remains readable.
Fetching older mail
POST /api/mailboxes/{id}/fetch-older
The web UI calls this when you click Load more and the local cache is exhausted. It backfills mail older than the oldest cached message:
- The mailbox is searched day by day, walking backwards from the oldest
cached message, collecting at most 200 uncached messages per call (override
with
{"limit": N}, clamped to 200). - A quiet week does not mean the mailbox start. The walk keeps going
further back until it finds mail again, and only a history that is empty all
the way down reports
hasOlder: false— hide the button then. - Only envelopes are stored; bodies are fetched lazily when a message is opened.
- Repeat calls keep rewinding day by day; each response reports whether older mail remains.
Response:
| Field | Description |
|---|---|
mailbox |
Path that was backfilled |
newMessages |
Messages stored locally by this call |
hasOlder |
Whether more mail remains beyond what has been walked |
total, unread |
Fresh counts for the mailbox |
If the server reset the mailbox UIDVALIDITY, the call returns 409 — run a
regular sync first, which rebuilds the cache.