← Changelog

Your Whole Inbox, On Your Own Disk

After trying a few email agents, we stopped renting one. kay-os now pulls every mailbox onto the hard drive, read-only, so agents can dig through years of mail without touching the provider.

Why Care?

An email agent is only as useful as the mail it can reach, and most of them see a thin slice of it through someone else's API. Asking a question across ten years and several addresses means a local copy you control.

So kay-os starts its email work with the archive, not the agent. Once the mail is on disk, a new agent can run over all of it from day one, and switching agents doesn't mean downloading anything again.

What's New?

  • kaymail add connects a mailbox with an app password. Run it once per address, and one machine can hold as many accounts as you have.

  • kaymail sync downloads everything, newest first. Stop it whenever; the next run fetches only what's missing.

  • mail/backfill.sh keeps a big first download going for days, retrying through provider limits.

  • kaymail search does full-text search across every account, with filters for sender and date, and --json output for agents.

  • kaymail watch checks for new mail on a timer and appends it to an event log. That log is what monitoring agents will read. The agents themselves come next.

How it Works

TEXT
Gmail / IMAP --(read-only)--> raw .eml files   one per message, the source of truth
                          \-> SQLite + FTS5    search, threads, labels
                          \-> events.jsonl     new arrivals, for agents

It can't change your mail. Mailboxes open with EXAMINE and bodies fetch with BODY.PEEK[], so a sync can't mark, move, or delete anything. A test holds that line by checking every command sent to the server. Mail deleted upstream stays in the archive.

It stays out of this repo. kay-os is public. Mail and credentials live under your home directory with owner-only permissions, and the tool refuses any path inside a git checkout.

Newest first means recent mail is useful within minutes, while years of old mail fill in behind it.

Under the Hood

It's Python's standard library and nothing else: imaplib, email, and sqlite3.

  • On Gmail we sync only All Mail. It holds each message once, with its labels and thread ID attached, and the other folders are views of it.

  • Raw messages are stored by SHA-256, so the same bytes in two folders take one file and one search result.

  • imaplib caps response lines at 1 MB, and listing every message ID in a mailbox this size blows straight past that, so we raise the cap.

  • A first backfill raises no events, or the monitoring log would open with hundreds of thousands of "new" messages.

  • backfill.sh stops on a failed login instead of retrying, so a stale password can't get an account locked.

The tests drive real imaplib over a socket against a small Gmail-shaped fake server. The first real run used two live mailboxes, and full backfills are underway.

What's Next?

Known limits:

  • Passwords sit in a plain-text, owner-only file, because this machine has no secret store yet.

  • Microsoft accounts generally need OAuth, which kaymail doesn't speak.

  • Search reads attachment filenames, not what's inside them.

  • watch polls every two minutes instead of holding an IMAP IDLE connection.

  • One message in our first 400 came through with no body text, and we haven't looked into why. The raw copy is kept either way.

Then the agents. Everything in this archive was written by whoever chose to email you, so an agent reading it is reading untrusted input. Agents that read mail won't also hold tools that send or delete without a human approving.