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
This repository has been archived on 2026-11-20. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
gascity-argos 717dbcdbbb
All checks were successful
Release / changelog (push) Successful in 4s
Release / test (push) Successful in 26s
Release / ci (push) Successful in 0s
Release / plan (push) Successful in 4s
Release / build (push) Has been skipped
Release / release (push) Has been skipped
README: link the releases under the repository's current name (#7)
2026-11-17 19:31:55 +00:00
.forgejo/workflows Point the changelog action at sarak.sh/mikluko/changelog 2026-11-11 14:49:53 +01:00
internal/watch Keep /healthz healthy while the command runs (jwatch-1ag) 2026-11-10 15:46:59 +00:00
.gitignore Report each new JMAP email over the push stream 2026-11-09 20:48:18 +01:00
.goreleaser.yaml Report each new JMAP email over the push stream 2026-11-09 20:48:18 +01:00
CHANGELOG.md jmap-watch 0.2.2: the module version from -version 2026-11-13 23:43:14 +01:00
go.mod Report each new JMAP email over the push stream 2026-11-09 20:48:18 +01:00
go.sum Report each new JMAP email over the push stream 2026-11-09 20:48:18 +01:00
main.go Report the module version when no release build set one 2026-11-13 23:28:35 +01:00
main_test.go Report the module version when no release build set one 2026-11-13 23:28:35 +01:00
README.md README: link the releases under the repository's current name (#7) 2026-11-17 19:31:55 +00:00
REVIEW.md Add REVIEW.md: what the city's reviewer checks beyond CI (#1) 2026-11-10 00:16:22 +00:00

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 /healthz answers 200 when jmap-watch is healthy and 503 when it is not, with a one-line reason in the body, such as no 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 -ping plus 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 0 the 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.