# Clinic Mail

Read-only access to the clinic’s Zoho mailboxes as an API, a CLI and an MCP server. Every account, folder, message and raw source sits behind one bearer-token endpoint, so an agent can read the reply to a patient letter — or the bounce that says it never arrived — without touching the mailbox. Fetching uses IMAP BODY.PEEK, so reading never marks mail as read.

**Status:** Private · Projects · 2026

- **Local checkout:** `/Users/simon/Developer/clinic-mail` (branch `main`, last commit 2565e24, 2026-11-07 — Mailbox list: one FETCH for the page instead of one per message)
- **Uncommitted changes:** 1 file(s) at brief generation time
- **Repository:** https://github.com/ShimonNavon/clinic-mail
- **On another machine:** `git clone https://github.com/ShimonNavon/clinic-mail` — the paths below are Simon's Mac
- **Note:** Token required

## Stack

Python 3.12 stdlib (imaplib + http.server), Node CLI/MCP (no deps), nginx-unprivileged edge proxy, Kubernetes, Cloudflare Tunnel

## Start here

- `app/app.py` — the API: bearer auth, multi-account IMAP, folders/messages/search/raw
- `lib/client.mjs` — shared HTTP client (config file + env token)
- `bin/clinic-mail.mjs` — CLI: accounts, status, folders, ls, show, raw, search
- `mcp/server.mjs` — MCP tools: mailbox_accounts/status/folders/list/search/read
- `tests/smoke.mjs` — API auth + health, CLI, MCP handshake without touching Zoho
- `deploy/k8s.yaml` — namespace clinic-mail, python:3.12-slim pod, NodePort 30103
- `deploy/make_env.py` — builds IMAP_ACCOUNTS + token from the visit recorder's SMTP credentials
- `deploy/accounts.local.json` — extra mailboxes (git-ignored; passwords live here + in the secret)

## Commands

- **Accounts + state:** `clinic-mail accounts`
- **Named mailbox:** `clinic-mail ls --account jaffemd --limit 10`
- **Read a message:** `clinic-mail show 14`
- **Raw message:** `clinic-mail raw 14 > message.eml`
- **Search:** `clinic-mail search "ביקורת"`
- **Run the MCP server:** `node mcp/server.mjs`
- **Tests:** `npm test`
- **Deploy:** `./deploy/deploy.sh`

## Deploy and where it runs

- Namespace clinic-mail: one python:3.12-slim pod running app.py from a ConfigMap, credentials + bearer token in Secret clinic-mail-env, NodePort 30103; public at https://clinic-mail.navonsimon.com via the Cloudflare Tunnel + edge nginx (GET only, rate limited).

## Current state

Live and reading jaffemd@handclinic.co.il (INBOX and Sent). it@handclinic.co.il still needs an app password: Zoho asks for account re-verification before one can be generated. Zoho admin: IMAP allowed by the 'IMAP and POP' access restriction on the default policy, and enabled per user in Mailbox Actions.

## Secrets — locations only, never print values

- k8s Secret clinic-mail-env: IMAP_ACCOUNTS (per-mailbox passwords) + MAILBOX_TOKEN
- ~/.config/clinic-mail/config.json: url + token, mode 600
- deploy/accounts.local.json (git-ignored): extra mailbox passwords for the next secret build

## Tags

Zoho IMAP, API, MCP, Kubernetes

---

Brief generated 2026-11-08 from `~/Developer/my-projects/context/`. Canonical URL: https://projects.navonsimon.com/context/clinic-mail.md
