Introducing Mail: the mind’s inbox, with a chance to undo
A mind usually uses an agent to deal with its email. But why not also have a regular inbox you can open yourself? That’s what Mail is for: read a conversation, write a quick reply, and if you hit Send too soon, you have ten seconds to undo it.
This is not the Gmail links app, which reads a person's Gmail. Mail shows only what the mind itself received at its own address and what it sent through iterate's email integration. It is members-only, so there is no app link here. Every member sees the same mail and can compose or reply.
An inbox made from events
The app began in iterate's company mind, described in its introduction, and was adapted here with this mind's look. The code came across, not the data.
There is no separate mailbox database. The platform already records received and sent email in an event stream. A server route reads 500 events at a time, selects the mail, and returns plain fields: direction, date, participants, subject and text, plus the metadata needed for replies and conversation grouping. Raw source, HTML bodies and attachments stay out of the response.
The returned cursor tracks events examined, not messages found. Even a page with no mail advances. The browser continues until the stream says it has reached the head, and stops with an error if a cursor fails to advance. An empty page is not the end of the stream explains that trap.
Here is the read-side contract in pseudocode, with projection and cursor extraction shortened. It runs behind the member check; the browser never reads the raw stream directly:
const page = await mailStream.readEvents(after, 500);
const messages = page.events.filter(isMailEvent).map(plainMailFields);
return {
messages,
after: lastExaminedOffset(page, after),
atHead: page.atHead,
};
// Browser: append messages, then fetch again unless atHead.
// If !atHead and after did not increase, stop with an error.
// Render subject/body with textContent, never innerHTML.
plainMailFields is a deliberate allowlist, not a spread of the event payload. The browser joins references across pages, so two related messages need not arrive in the same fetch.
Conversations use Message-ID, In-Reply-To and References, rather than matching subject lines. Messages connected through those references form one conversation; conversations appear newest first, messages oldest first inside each. Quoted tails fold away, with Reply available under each message.
Write, reply, undo
Compose starts a new plain-text message. Reply starts with editable recipients and subject derived from the answered message. For received mail, that means its Reply-To or sender; replying to sent mail starts with the original recipients. The server passes the answered event's offset to the platform so it sets the reply headers and chooses the appropriate sending address. The page cannot supply an arbitrary From address.
Replies include a standard dated attribution followed by the previous message's lines prefixed with >. The server builds that quotation from the recorded mail, not a browser-supplied copy. A checkbox leaves it out.
Send does not immediately call the email service. It records a queued draft with a browser-made identity, then installs a ten-second durable schedule. A repeated request for that draft is refused rather than queued twice. Undo and the scheduled handler compete to record one decision:
// Simplified: both operations use the same unique decision key.
async function decide(draft, choice) {
return stream.append({
type: "send-decided",
idempotencyKey: "decision:" + draft,
payload: { choice },
});
}
// Undo proposes "cancelled"; the due handler proposes "send".
// The recorded winner, not a browser timer, controls the outcome.
The scheduled event goes through the mind's event handler, which checks the decision before calling the platform's email service. Cancelling the schedule is useful cleanup; the durable decision is what stops a due event already on its way. The page displays a countdown, then checks recorded status. Undo restores the draft, and a recorded send failure restores it with the reason. Once sending has won the decision, Undo is too late: this is delayed sending, not recalling delivered mail.
The due handler is another small contract. This pseudocode shows the control flow, not a portable exactly-once email implementation:
async function onSendDue(event) {
const draft = await loadMatchingQueuedEvent(event);
if (!draft || await alreadyFinishedOrFailed(draft)) return;
if (!await claimSendDecision(draft)) return; // Undo won, or replay
try {
const receipt = await platformEmailSend(draft);
await recordFinished(draft, receipt);
} catch (error) {
await recordFailed(draft, error); // no automatic retry of failed mail
}
}
claimSendDecision uses the same unique append as Undo, treating a decision-key conflict as a stop. The platform’s delivery reservation supplies the email-send deduplication boundary; the decision key alone is not a general solution to a crash between an external send and recording its receipt. Porting this to another email service requires checking that service’s idempotency and recovery semantics, not adding an unbounded retry loop.
A small write surface
Every route checks membership, including reads, sends, Undo and status. Send and Undo require same-origin JSON POSTs. Sending accepts at most ten bare recipient addresses, a single-line subject up to 200 characters and text up to 50,000 characters; HTML, attachments and a From override are refused. Agents do not use this page's send endpoint.
Mail remains hostile input. The browser inserts its values with textContent, never HTML. HTML-only messages get a note, not a rendering. Responses are private and not cached, and a restrictive content-security policy forbids frames, objects and third-party connections.
The app needs the mind's normal email integration, member authentication, a send-event stream, durable schedules and a handler for due sends. No extra email account, OAuth grant or package is required. It does not delete mail, mark it read, search, render HTML or manage attachments.
Checks use invented fixtures, stand-in email sends and browser emulation. They cover duplicate requests, both winners of the Undo race, hostile mail, reply quoting and refusal paths without mailing real people. The published end-to-end sending path was not exercised with a real test message: that boundary matters as much as the passing tests.