revert: undo auto-resolve local image paths in draft body HTML#199
revert: undo auto-resolve local image paths in draft body HTML#199infeng merged 3 commits intolarksuite:mainfrom
Conversation
…paths (larksuite#141)" This reverts commit 1ffe870.
…larksuite#81) (larksuite#139)" This reverts commit 70c72a2.
📝 WalkthroughWalkthroughChanged inline image handling in email draft patches from automatic local-path resolution and orphan cleanup to explicit post-apply validation. Removed auto-resolve logic for HTML Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
… paths (larksuite#141)" This reverts commit d465e08.
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@5051e259ba371df2e80a9119ffda186b6b123e63🧩 Skill updatenpx skills add infeng/cli#revert-relative-path-clarification -y -g |
Greptile SummaryThis PR reverts two commits that introduced auto-resolution of local The revert is broadly clean and the rationale is sound. Key changes:
Issues found:
Confidence Score: 4/5Safe to merge after fixing the orphan validator's ContentDisposition filter; the P2 CID character check is a hardening improvement that can be addressed in a follow-up. One clear P1 regression: validateOrphanedInlineCIDAfterApply flags HTML body parts that carry a Content-ID (valid RFC 2387 practice) as orphaned, returning an error on Apply for real-world drafts opened from emails generated by Apple Mail or Outlook. The fix is a one-line guard. The remaining finding (missing CID character validation) is a P2 input-hardening concern that does not block correctness for the common path. shortcuts/mail/draft/patch.go — validateOrphanedInlineCIDAfterApply loop needs a ContentDisposition: inline filter Important Files Changed
Reviews (1): Last reviewed commit: "Reapply "fix(mail): clarify that file pa..." | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@shortcuts/mail/draft/patch.go`:
- Around line 892-915: The validator validateOrphanedInlineCIDAfterApply
currently treats any part with a ContentID as an orphan candidate and returns
early if no HTML part exists; change it to only consider parts where
part.ContentDisposition == "inline" and part.ContentID != "" when building the
orphan list (use flattenParts to iterate and the same strings.ToLower checks),
and if htmlPart is nil then reject (return an error) only when at least one such
inline part exists after apply; keep the existing error message/format but
ensure you reference the same symbols (validateOrphanedInlineCIDAfterApply,
findPart, extractCIDRefs, flattenParts) when making the change.
In `@shortcuts/mail/mail_draft_edit.go`:
- Line 366: Update the comment that explains add_inline behavior to explicitly
state that draftpkg.Apply will reject orphaned inline parts at edit time (during
the +draft-edit command) rather than allowing the edit to succeed and only
failing at send; mention the immediate validation error returned by
draftpkg.Apply and keep the advice that to display the image inline you must
also call set_body/set_reply_body with an <img src="cid:...">. Reference
add_inline, set_body/set_reply_body, draftpkg.Apply and +draft-edit so readers
know where the validation occurs and what commands to use to avoid orphaned CID
attachments.
In `@skills/lark-mail/references/lark-mail-draft-edit.md`:
- Around line 315-327: The patch example uses two different filenames causing a
mismatch: the JSON is written to "./patch.json" but the command references
"/tmp/patch.json"; update either the heredoc target or the lark-cli invocation
so both use the same path (e.g., change the heredoc to write to
"/tmp/patch.json" or change the command to use "./patch.json")—look for the
heredoc that creates "patch.json" and the lark-cli mail +draft-edit --patch-file
argument and make them identical.
- Around line 253-256: The examples use an absolute path (/tmp/patch.json) which
will be rejected by the --patch-file validation; update the examples to use a
relative path (e.g., ./patch.json) so loadPatchFile passes
validate.SafeInputPath. Locate the usage in the docs around the mail draft edit
example and change the CLI invocation to use a relative path for --patch-file;
mention or show ./patch.json instead of /tmp/patch.json so the runtime call to
shortcuts/mail/mail_draft_edit.go (safePath := validate.SafeInputPath(...))
succeeds.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 270ce1e0-43e0-4370-8ddc-776a84688a65
📒 Files selected for processing (15)
shortcuts/mail/draft/patch.goshortcuts/mail/draft/patch_inline_resolve_test.goshortcuts/mail/draft/patch_test.goshortcuts/mail/mail_draft_create.goshortcuts/mail/mail_draft_edit.goshortcuts/mail/mail_forward.goshortcuts/mail/mail_reply.goshortcuts/mail/mail_reply_all.goshortcuts/mail/mail_send.goskills/lark-mail/references/lark-mail-draft-create.mdskills/lark-mail/references/lark-mail-draft-edit.mdskills/lark-mail/references/lark-mail-forward.mdskills/lark-mail/references/lark-mail-reply-all.mdskills/lark-mail/references/lark-mail-reply.mdskills/lark-mail/references/lark-mail-send.md
💤 Files with no reviewable changes (1)
- shortcuts/mail/draft/patch_inline_resolve_test.go
…ert (#199) The revert of PR #81 (eda2b9c) also removed two independent bugfixes: 1. CID character validation in newInlinePart — reject spaces, tabs, angle brackets, and parentheses to prevent malformed MIME output. 2. Stale PartID lookup in validateInlineCIDAfterApply and validateOrphanedInlineCIDAfterApply — use findPrimaryBodyPart by media type instead of findPart by PrimaryHTMLPartID, which can go stale when ops restructure the MIME tree.
* Revert "fix(mail): clarify that file path flags only accept relative paths (#141)" This reverts commit eac6fa9. * Revert "feat(mail): auto-resolve local image paths in draft body HTML (#81) (#139)" This reverts commit 22cc882. * Reapply "fix(mail): clarify that file path flags only accept relative paths (#141)" This reverts commit d465e08.
…ert (#230) * fix(mail): restore CID validation and stale PartID lookup lost in revert (#199) The revert of PR #81 (eda2b9c) also removed two independent bugfixes: 1. CID character validation in newInlinePart — reject spaces, tabs, angle brackets, and parentheses to prevent malformed MIME output. 2. Stale PartID lookup in validateInlineCIDAfterApply and validateOrphanedInlineCIDAfterApply — use findPrimaryBodyPart by media type instead of findPart by PrimaryHTMLPartID, which can go stale when ops restructure the MIME tree. * test(mail): add tests for CID character validation and stale PartID lookup - TestAddInlineRejectsInvalidCharactersInCID: verify spaces, tabs, embedded angle brackets, and parentheses in CID are rejected. - TestValidateInlineCIDAfterSetBody: verify inline CID validation works correctly after set_body restructures the MIME tree (covers the findPrimaryBodyPart fix for stale PartID). * fix(mail): add CID character validation to replaceInline and strengthen test assertions Address CR feedback: 1. Add the same CID character validation (spaces, tabs, angle brackets, parentheses) to replaceInline, matching the check in newInlinePart. Previously replace_inline could bypass the restriction. 2. Strengthen orphaned CID test assertion to check for specific "orphaned cids" error message, not just non-nil error. 3. Add TestReplaceInlineRejectsInvalidCharactersInCID to cover the new validation in replace_inline.
Summary
70c72a2—feat(mail): auto-resolve local image paths in draft body HTML (#81) (#139)The auto-resolve feature (
<img src="./local.png" />→ inline CID) was only wired into the+draft-editpatch path. All other EML-build paths (+draft-create,+send,+reply,+reply-all,+forward) did not support it, causing LLMs to misuse the pattern and produce broken inline images. Reverting until the feature can be implemented consistently across all entry points.Note:
1ffe870(fix(mail): clarify that file path flags only accept relative paths) is intentionally preserved.Test plan
go build ./shortcuts/mail/...passesgo test ./shortcuts/mail/...passes+draft-editinline images still work via explicitadd_inlineop with CIDSummary by CodeRabbit
Bug Fixes
<img src="cid:...">tags via body edits and corresponding inline attachments via the add operation. Orphaned or unreferenced inline images are now rejected.Documentation