feat: add HTML email body and attachment support (#20)#21
Merged
radiosilence merged 3 commits intomainfrom Apr 11, 2026
Merged
Conversation
Send/reply/forward now support --html-body (inline), --html-file (from file), and -a/--attachment (repeatable file attachments). JMAP body construction handles plain text, multipart/alternative (text+HTML), and multipart/mixed (with attachments) in a single code path. Adds upload_blob method for posting raw bytes to Fastmail's upload endpoint. GraphQL mutations accept optional html_body parameter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
radiosilence
commented
Apr 11, 2026
Owner
Author
radiosilence
left a comment
There was a problem hiding this comment.
Solid work. Three nits:
1. match ... { Ok => ..., Err(e) => Err(e) } × 3
This pattern in main.rs (lines 488-499, 539-550, 563-574) is a verbose identity on Err. Simplify with ?:
} => {
let params = build_compose_params(
cc.as_deref(),
bcc.as_deref(),
from.as_deref(),
draft,
html_body,
html_file,
&attachments,
)?;
commands::send(&to, &subject, &body, reply_to.as_deref(), params).await
}Same for Reply and Forward.
2. upload_blob swallows 4xx errors
The catch-all _ => {} at jmap/mod.rs:980 lets 4xx errors (e.g. 413 payload too large, 400 bad request) fall through to the blobId parse, which fails with a confusing "Upload response missing blobId". Add:
400..=499 => {
let status = resp.status();
let text = resp.text().await.unwrap_or_default();
return Err(Error::Server(format!("Upload failed ({}): {}", status, text)));
}3. No unit tests for load_attachment / resolve_html
Both are simple but worth covering — especially resolve_html's three branches (inline, file, none) and load_attachment's MIME inference + error on missing file. The test module in util.rs is right there.
None of these are blocking, but worth a quick pass.
…ml tests
- upload_blob: explicit 4xx error arm instead of swallowing to confusing
"missing blobId" message
- Send/Reply/Forward: replace `match { Ok => ..., Err(e) => Err(e) }`
with `async { ...? }.await`
- Add 7 unit tests for load_attachment and resolve_html (tempfile dev-dep)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Extract `apply_body_structure` pure function from `create_and_submit_email` for direct unit testing without async/network dependencies - 6 body structure tests covering all JMAP modes: - plain text only (textBody array) - text + HTML (textBody + htmlBody arrays) - text + attachment (bodyStructure multipart/mixed) - HTML + attachment (bodyStructure with nested multipart/alternative) - multiple attachments - 3 upload_blob tests via wiremock mock server: - success (200 with real Fastmail response shape) - 413 payload too large (verifies 4xx error handling) - 429 rate limited - 55 total tests, all passing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
--html-body(inline) and--html-file(from file) flags on send, reply, and forward. JMAP assembles multipart/alternative automatically when both text and HTML are provided.-a/--attachmentflag (repeatable) on send, reply, and forward. Files uploaded via newupload_blobJMAP method, attached with proper multipart/mixed MIME tree usingbodyStructure.sendEmail,replyToEmail,forwardEmailaccept optionalhtml_bodyparameter. Previews indicate when HTML is included.create_and_submit_emailhandles plain text, text+HTML, and attachments. Extractedbuild_compose_paramshelper in main.rs to deduplicate CLI argument resolution across compose commands.Closes #20
Test plan
cargo test— 40 tests passcargo clippy --workspace -- -D warnings— zero warningscargo fmt --check— clean--html-bodyflag--html-fileflag-a attachment.pdf🤖 Generated with Claude Code