README.md
# Email Organizer (AgentRove native agent)
Offline email triage for mail you already have as text. Give it the raw text of `.eml` files or an
mbox export; it parses the messages, sorts them with rules you control, explains every decision, and
proposes filter rules for you to create yourself. It never connects to a mail server, never sends,
moves, deletes or labels anything.
- ID: `agentrove.email-organizer` · version 0.1.2 · MIT
- Published by AgentRove (provisional, configurable name). Package identifiers keep the agentrove prefix for compatibility.
- Runtime: Node.js 20 or newer, no npm dependencies
- Permissions: no filesystem access by tools, no network, no credentials
- External costs: none
## Tools
| Tool | What it does | Side effects |
| --- | --- | --- |
| `parse_messages` | Parses RFC 5322 `.eml` text or mbox text. Handles folded headers, encoded-word subjects and names (`=?UTF-8?B?…?=`, `=?…?Q?…?=`), MIME `multipart/*` (prefers the `text/plain` part of `multipart/alternative`, falls back to tag-stripped HTML), quoted-printable and base64, common charsets, RFC 2231 attachment names. Returns decoded headers, an ISO date (UTC), the text body and attachment metadata (name, type, size only, never contents). | none |
| `triage` | Assigns each message a `category` (`vip`, `needs_reply`, `newsletter`, `notification`, `fyi`, or a category from your keyword rules), a `priority` (`high`/`normal`/`low`), `reply_needed`, any `deadlines` found, and the `reasons` for each decision. | none |
| `suggest_filters` | Proposes filter rules as data: mailing lists (List-Id), newsletters (List-Unsubscribe), automated senders (no-reply, Auto-Submitted, Precedence), shared subject tags like `[ops]`, and VIP senders (when given a triage result). Always returns `applied: false`. | none |
### Triage rules, in order
1. **Your keyword rules** (`rules.keyword_rules`): whole-word, case-insensitive matches in the subject,
body or both. The first matching rule with a `category` sets the category; the first with a
`priority` sets the priority, and nothing later overrides it.
2. **VIP senders** (`rules.vip_senders`): exact addresses, `@domain`, or a bare domain (also matches
subdomains). VIP mail is `high` priority.
3. **Newsletters**: a `List-Unsubscribe` or `List-Id` header. **Notifications**: a no-reply style sender,
an `Auto-Submitted` header other than `no`, or `Precedence: bulk|list|junk`. Both are `low` priority
unless a VIP or keyword rule says otherwise, and reply heuristics are skipped for them.
4. **Reply needed**: a question in the new text (quoted `>` lines, `On … wrote:` history and signatures
after `-- ` are ignored), a request phrase ("can you", "please confirm", "let me know", …) or a
deadline phrase ("by Friday", "due 2026-12-01", "before Dec 3", "by Wed., Dec 2", "before 5pm Friday", "by EOD"). A dated deadline that has
passed or falls within `rules.urgent_within_days` (default 2) of `now` raises priority to `high`.
If `rules.my_addresses` is given and you are only in Cc, that urgency bump is not applied.
Weekday and month-day deadlines are resolved relative to the message's own `Date` header (UTC), and
dates without a year go to the nearest matching date. Numeric dates such as `03/04` are only resolved
when one side cannot be a month (`25/12`); otherwise they are reported with `date: null`.
## Typed IO (AgentRove composition)
| Name | Type | Where |
| --- | --- | --- |
| input `raw` | `text` | `parse_messages.raw` |
| input `messages` | `email_messages` | `triage.messages`, `suggest_filters.messages` |
| output `messages` | `email_messages` | `parse_messages` → `messages` |
| output `triage` | `email_triage` | the whole `triage` result (`{messages, summary}`) |
## Usage (Node CLI)
Tools take JSON. Because tools do not read files themselves, put the mail text into an input file
first (this one-liner only reads the file you name and writes `input.json`):
```sh
node -e "const fs=require('node:fs');fs.writeFileSync('input.json',JSON.stringify({raw:fs.readFileSync(process.argv[1],'utf8')}))" ~/mail/export.mbox
node bin/cli.js parse_messages --input input.json > parsed.json
```
Triage with your own rules (bash):
```sh
node -e "const fs=require('node:fs');const p=JSON.parse(fs.readFileSync('parsed.json','utf8'));fs.writeFileSync('triage-in.json',JSON.stringify({messages:p.messages,rules:{vip_senders:['boss@example.com','@client.example'],my_addresses:['me@example.com'],keyword_rules:[{keywords:['invoice','receipt'],category:'finance',priority:'normal'}]}}))"
node bin/cli.js triage --input triage-in.json
```
Small inline call (PowerShell needs the JSON in single quotes, with inner double quotes escaped as `\"`
on Windows PowerShell 5.1; using `--input` files avoids quoting problems):
```sh
node bin/cli.js parse_messages --json '{"raw":"From: a@example.com\nSubject: Hi?\n\nCan you call me?"}'
node bin/cli.js --help
```
`--input -` reads the input JSON from stdin instead of a file. Output is JSON on stdout; errors are JSON on stderr with exit code 1, for example
`{"error":"invalid_input","message":"Invalid input: $.raw: required"}`.
## Use as an MCP server (stdio)
`bin/mcp.js` speaks the Model Context Protocol over stdio (`initialize`, `tools/list`, `tools/call`).
Register it with an MCP client using an absolute path, for example in Claude Code:
```sh
claude mcp add email-organizer -- node /absolute/path/to/email-organizer/bin/mcp.js
```
or in a project `.mcp.json`:
```json
{ "mcpServers": { "email-organizer": { "command": "node", "args": ["/absolute/path/to/email-organizer/bin/mcp.js"] } } }
```
The `claude-code/SKILL.md` file is an optional Claude Code skill that runs the CLI instead of MCP.
**Status:** tested with Node.js (unit tests plus MCP message handling). Not yet verified inside Claude
Code by AgentRove; the commands above follow Claude Code's documented MCP conventions.
## Limitations
- Input must be text. Binary-safe parsing of 8-bit bodies in non-UTF-8 charsets depends on how you
read the file (read it as UTF-8; quoted-printable and base64 parts are decoded byte-exactly).
- No S/MIME, PGP, TNEF (`winmail.dat`), uuencode or `message/rfc822` unpacking (forwarded messages are
listed as attachments). HTML-only mail is reduced to plain text by stripping tags.
- Heuristics are English-centric and can be wrong: a rhetorical question still counts as a question.
Every decision lists its reasons so you can check it.
- Dates are UTC; deadlines are calendar dates (a clock time such as "5pm" is ignored, and a time with no date, like "by 3pm", is not detected). "By Friday" on a Friday means that same day.
- Limits: 25 M characters of input, 1000 messages by default (max 5000), 20 000 body characters per
message by default, 200 MIME parts and 8 nesting levels per message.
## Security and privacy
See [SECURITY.md](SECURITY.md). Mail content is treated as untrusted data: it is pattern-matched only,
never executed, rendered or followed, and nothing leaves your machine.
## License
MIT, see [LICENSE](LICENSE).