Skip to content

Commit 7337889

Browse files
authored
Merge pull request #6 from noc0dev/feature/draft
Add email.draft command for safe AI agent email workflows
2 parents 8d494b9 + ef3eb91 commit 7337889

6 files changed

Lines changed: 347 additions & 13 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ wheels/
1212
# Editor files
1313
*.swp
1414
*~
15+
.aider*

README.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h1 align="center">fastmail-cli</h1>
66

77
<p align="center">
8-
<strong>Read-only email access for AI agents via JMAP.</strong>
8+
<strong>Read-only email access for AI agents via JMAP, and draft responses.</strong>
99
</p>
1010

1111
<p align="center">
@@ -38,7 +38,7 @@ uvx fastmail-cli help
3838
## Setup
3939

4040
```bash
41-
export FASTMAIL_READONLY_API_TOKEN="fmu1-..." # from Fastmail Settings → Integrations
41+
export FASTMAIL_API_TOKEN="fmu1-..." # from Fastmail Settings → Integrations
4242
```
4343

4444
## Usage
@@ -50,6 +50,37 @@ fastmail-cli email.get --ids '["M123"]' # get by ID
5050
fastmail-cli mailbox.query # list mailboxes
5151
```
5252

53+
### Create Drafts (Safe for AI Agents)
54+
55+
```bash
56+
# Create a draft - human reviews in Fastmail UI before sending
57+
fastmail-cli email.draft \
58+
--to "recipient@example.com" \
59+
--subject "Re: Your question" \
60+
--body "Here's the response..."
61+
62+
# Draft with body from file
63+
fastmail-cli email.draft \
64+
--to "user@example.com" \
65+
--subject "Report" \
66+
--body @report.txt
67+
```
68+
69+
### Draft Replies to Existing Emails
70+
71+
```bash
72+
# Reply to an email (auto-threads, auto-sets subject)
73+
fastmail-cli email.draft-reply \
74+
--id "M12345" \
75+
--body "Thanks for reaching out..."
76+
77+
# Reply-all to include all original recipients
78+
fastmail-cli email.draft-reply \
79+
--id "M12345" \
80+
--body "Replying to everyone..." \
81+
--reply-all
82+
```
83+
5384
All output is JSON with `ok`, `command`, `meta`, and `data`/`error` fields.
5485

5586
## Required Reading

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "fastmail-cli"
3-
version = "0.1.1"
4-
description = "Read-only CLI for agents to access Fastmail via JMAP"
3+
version = "0.2.0"
4+
description = "CLI for AI agents to access Fastmail via JMAP - draft responses without sending"
55
readme = "README.md"
66
license = "Apache-2.0"
77
requires-python = ">=3.13"
@@ -30,7 +30,7 @@ Repository = "https://github.com/noc0dev/fastmail-cli"
3030
Issues = "https://github.com/noc0dev/fastmail-cli/issues"
3131

3232
[project.scripts]
33-
fastmail-cli = "fastmail_cli:main"
33+
fastmail-cli = "fastmail_cli.cli:main"
3434

3535
[build-system]
3636
requires = ["hatchling"]

src/fastmail_cli/cli.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
import sys
77

88
DEFAULT_HOST = "api.fastmail.com"
9-
DEFAULT_TOKEN_ENV = "FASTMAIL_READONLY_API_TOKEN"
9+
DEFAULT_TOKEN_ENV = "FASTMAIL_API_TOKEN"
10+
LEGACY_TOKEN_ENV = "FASTMAIL_READONLY_API_TOKEN"
1011

1112

1213
def main(argv=None) -> int:
1314
# Set default host if not provided
1415
os.environ.setdefault("JMAP_HOST", DEFAULT_HOST)
15-
# Promote FASTMAIL_READONLY_API_TOKEN to JMAP_API_TOKEN if not already set
16-
if "JMAP_API_TOKEN" not in os.environ and DEFAULT_TOKEN_ENV in os.environ:
17-
os.environ["JMAP_API_TOKEN"] = os.environ[DEFAULT_TOKEN_ENV]
16+
# Promote FASTMAIL_API_TOKEN to JMAP_API_TOKEN if not already set
17+
# Fall back to legacy FASTMAIL_READONLY_API_TOKEN for backwards compatibility
18+
if "JMAP_API_TOKEN" not in os.environ:
19+
if DEFAULT_TOKEN_ENV in os.environ:
20+
os.environ["JMAP_API_TOKEN"] = os.environ[DEFAULT_TOKEN_ENV]
21+
elif LEGACY_TOKEN_ENV in os.environ:
22+
os.environ["JMAP_API_TOKEN"] = os.environ[LEGACY_TOKEN_ENV]
1823
from .jmapc import main as jmap_main
1924
return jmap_main(argv)
2025

0 commit comments

Comments
 (0)