Add email draft creation with safety validation #16
+278
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the ability to create email drafts in the user's Drafts folder, allowing Claude Code to compose contextual replies and new messages for human review before sending. Draft creation is structurally separated from sending—no submission scope is requested, and sending remains impossible.
Key Changes
New
jm draftcommand with four composition modes:jm draft --to alice@example.com --subject "..." --body "..."jm draft --reply-to <email-id> --body "..."jm draft --reply-all <email-id> --body "..."jm draft --forward <email-id> --to bob@example.com --body "..."--body-stdin--htmlflag for HTML bodiesDefense-in-depth safety validation via new
ValidateSetForDraft()function:Email/setrequests contain exactly one draft$draftkeyword is setUpdateorDestroyoperationsReply/reply-all/forward threading support:
In-Reply-ToandReferencesheaders for proper threadingNew types and output formatting:
DraftResulttype for structured draft creation responsesImplementation Details
cmd/draft.go: Command-line interface with flag parsing and composition mode selectioninternal/client/draft.go: Core draft creation logic with helper for fetching original emailsinternal/client/draft_test.go: Comprehensive unit tests for all composition modes and error casesinternal/client/safety.go: New validation function with corresponding testsinternal/types/types.go: NewDraftResultstructinternal/output/text.go: Formatter support for draft resultsNo new JMAP scopes are requested; draft creation uses only the existing
urn:ietf:params:jmap:mailscope. Sending remains structurally impossible—theemailsubmissionpackage is never imported.https://claude.ai/code/session_01AxdRmnzzLbF61zhwZAK72N