Gas City pack: JMAP mail for a city. The inbox agent (jmap-watch) delivers each new email to gc mail; an MCP server to follow
- Go 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .forgejo/workflows | ||
| internal/watch | ||
| .gitignore | ||
| .goreleaser.yaml | ||
| CHANGELOG.md | ||
| go.mod | ||
| go.sum | ||
| main.go | ||
| main_test.go | ||
| README.md | ||
| REVIEW.md | ||
jmap-watch
jmap-watch reports each new email of a JMAP account as it arrives. It listens on the account's push stream (an EventSource), and for each email created in the watched mailbox it either prints one JSON line on stdout or runs a command with that JSON on the command's stdin.
Install
Download an archive or a .deb package from the releases, or build it:
go install sarak.sh/mikluko/jmap-watch@latest
Use
export JMAP_SESSION_URL=https://mail.example.com/jmap/session
export JMAP_AUTH_TOKEN_FILE=/path/to/token
jmap-watch -state ~/.local/state/jmap-watch/state
Each new email in the Inbox prints a line like this one:
{"id":"cmaaaaat","receivedAt":"2026-11-09T19:45:01Z","mailboxIds":["a"],"mailboxes":["Inbox"],"from":[{"name":"Alice","email":"alice@example.com"}],"to":[{"email":"me+news@example.com"}],"cc":[],"subject":"Hello","preview":"First lines of the body"}
To run a command per email instead, put it after --:
jmap-watch -state ~/.local/state/jmap-watch/state -- ./route-email.sh
| Flag | Default | Meaning |
|---|---|---|
-session-url |
$JMAP_SESSION_URL |
The JMAP session URL. |
-token-file |
$JMAP_AUTH_TOKEN_FILE |
A file holding the bearer token. Without it, the token is read from $JMAP_AUTH_TOKEN. |
-account |
the primary mail account | The account ID to watch. |
-mailbox |
inbox |
Report only email in the mailbox with this role, name or ID, matched in that order. Empty reports every new email. |
-state |
none | A file keeping the state reported up to. |
-ping |
60 |
The push keep-alive interval in seconds. A stream silent for twice as long is reopened. |
-health-addr |
none | An address such as :8081 to serve GET /healthz on. Empty serves nothing. |
-version |
Print the version and exit. |
Behaviour
- Without
-state, or on the first start with it, jmap-watch reports only email that arrives after it starts. - With
-state, a restart reports the email that arrived while it was down, as long as the server still knows the recorded state. When it does not, jmap-watch says so on stderr and starts from the current state. - A command that exits non-zero stops the batch it belongs to. The batch is offered again after a backoff, so the command can see an email it already took; make it idempotent, for example by keying on
id. - When the server or the stream fails, jmap-watch reconnects with a backoff of up to a minute. Errors go to stderr.
- With
-health-addr,GET /healthzanswers200when jmap-watch is healthy and503when it is not, with a one-line reason in the body, such asno push event or ping since 2026-11-10T12:00:00Z. It is unhealthy when the push stream has delivered no event or ping for longer than twice-pingplus a minute (three minutes at the default), counted from the start until the first connection, or when the command has kept failing the same batch for longer than five minutes. While the command runs nobody reads the stream, so the silence limit is suspended and restarts when the command returns. It is healthy again as soon as an event or ping arrives, or the batch is handed over. With-ping 0the server sends no keep-alives, so a quiet stream is not counted as down once it has connected.
Development
go test -race ./...
Work on the push stream itself lives in sarak.sh/mikluko/jmap, package core/push.
A release is cut when the newest entry in CHANGELOG.md names a version that has no tag yet.