iSMAIL / web API
The API surface is the CLI contract: option names in JSON are exactly the CLI flag
names without the leading dashes, validated against the same generated
spec/flags.json (325 spellings) the parser uses. There is no second schema to drift.
Authentication
A request to any protected endpoint passes with either the API bearer token
(--apitoken/--apitokenfile, sent as
Authorization: Bearer <token> — the script path) or a valid login session
cookie (ismail_session, the browser path). With neither configured the API is open to
whatever can reach the bind address.
UI login (v0.7): --authuser <u> --authpassfile <f> enables classic
username/password (env fallbacks ISMAIL_AUTH_USER/ISMAIL_AUTH_PASSWORD,
though a 600-mode file beats env — env is visible in docker inspect).
--oidc-issuer <url> --oidc-clientid <id> --oidc-clientsecretfile <f>
--oidc-redirect <url> enables OIDC login (Authorization Code + PKCE, discovery doc,
JWKS RS256 validation, nonce/state CSRF) against any conformant IdP — Keycloak, Authentik, Entra ID.
Optional --oidc-allowemails a@x,b@y restricts which IdP users get in. Sessions are
in-memory (8 h TTL; a restart logs everyone out). The web UI asks /api/whoami on load
and shows the matching login form.
Open mode: with neither a UI login nor a bearer token configured, /api/whoami
reports "open":true and the UI opens straight away (the API was always open in that
configuration — bind to 127.0.0.1 or put it behind a reverse proxy). A token-only
server has no browser login: a browser cannot send an Authorization header, so add
--authuser/--authpassfile (or OIDC) if you want the UI on such a server.
Login endpoints
| method & path | returns |
|---|---|
GET /api/whoami | {"authed":bool,"oidc":bool,"classic":bool,"token":bool,"open":bool,"user":"..."} — public, tells the UI what to show |
POST /api/login | {"user","password"} → Set-Cookie: ismail_session=...; HttpOnly, or 401 |
POST /api/logout | clears the session |
GET /api/oidc/start | 302 to the IdP (needs OIDC configured) |
GET /api/oidc/callback | IdP redirect target; verifies code/state/nonce/signature, then 302 to / with the session cookie |
Endpoints
| method & path | returns |
|---|---|
GET /api/version | {"version":"0.9.0","contract":325} — also handy as a healthcheck |
POST /api/sync | starts a run, 202 {"run_id":N}; 400 with a message for unknown options or missing credentials |
GET /api/runs | run summaries: {"id","dry","state","exit","started","source"} — state: running → done; source: api or sched:<id> |
GET /api/runs/<id>/log | full transcript, text/plain, grows while the run is in progress; passwords never appear in it |
GET /api/schedules | schedule list (see below) |
POST /api/schedules | create → 201; bad cron → 400 |
POST /api/schedules/<id> | partial update of name / spec / options / enabled → 200 |
DELETE /api/schedules/<id> | 200, or 404 |
GET /api/logs | server event log: a JSON array of stamped lines (boot, run start/finish, schedule changes, logins) — last 300 events, kept in memory |
GET /api/config | read-only server info: {"version","contract","listen","sched_file","started","uptime","runs","auth":{…}} — modes only, secrets are never served |
GET / | embedded web UI |
Option objects: CLI flags as JSON
{
"host1": "imap.gmail.com", "user1": "you@gmail.com", "password1": "app-pass",
"ssl1": true, "gmail1": true,
"host2": "mail.example.com", "user2": "you@example.com", "password2": "secret", "ssl2": true,
"port2": 993,
"exclude": ["[Gmail]", "Trash"],
"foldersizes": false,
"dry": true
}
- Flags (boolean options):
true→--name;false→--no<name>when the contract defines that negation ("foldersizes": false→--nofoldersizes), otherwise 400. - Array options (
--exclude,--regextrans2, …): a JSON array of values, or a bare scalar for a single value. - Everything else takes a string; numbers and booleans are stringified for you
(
"port2": 993works). - Unknown keys are rejected:
400 unknown option: --bogusflag.
Example session
curl -s -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{"host1":"imap.example.com","user1":"a","password1":"x","ssl1":true,
"host2":"mail.example.com","user2":"b","password2":"y","ssl2":true,"dry":true}' \
https://ismail.example.com/api/sync
# {"run_id":7}
curl -s -H "Authorization: Bearer $TOKEN" https://ismail.example.com/api/runs
# [{"id":7,"dry":true,"state":"running","exit":null,"started":1764597000,"source":"api"}]
curl -s -H "Authorization: Bearer $TOKEN" https://ismail.example.com/api/runs/7/log | tail
# ++++ Statistics ... (same keys as imapsync's transcript)
Schedules
A schedule is {"id","name","spec","options","enabled","last_fire"} where
options is exactly the POST /api/sync body. spec is a
classic 5-field cron expression (minute hour day-of-month month day-of-week)
evaluated in the server's local time: supports *, lists
(1,15), ranges (1-5) and steps (*/6), with
day-of-week 0–7 where both 0 and 7 are Sunday. The scheduler ticks every 10 s and fires each
schedule at most once per matching minute. Schedules persist to the
--schedulefile (atomic write after every change); their transcripts show up as
ordinary runs with source: "sched:<id>.
curl -s -X POST -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{"name":"nightly","spec":"30 2 * * *","options":{ …same body as /api/sync… }}' \
https://ismail.example.com/api/schedules
# 201 {"id":1,"name":"nightly","spec":"30 2 * * *", … }