Skip to content

fix(mail): write X-LMS-Reply-Type header on +reply/+reply-all/+forward#1621

Open
xzcong0820 wants to merge 1 commit into
larksuite:mainfrom
xzcong0820:fix/reply-forward-label
Open

fix(mail): write X-LMS-Reply-Type header on +reply/+reply-all/+forward#1621
xzcong0820 wants to merge 1 commit into
larksuite:mainfrom
xzcong0820:fix/reply-forward-label

Conversation

@xzcong0820

@xzcong0820 xzcong0820 commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

larkcli +reply/+reply-all/+forward now emit an X-LMS-Reply-Type EML header (REPLY/FORWARD) alongside X-LMS-Reply-To-Message-Id, so the mail backend can label the original message with the REPLIED(-603)/FORWARD(-604) system label and the client shows the replied/forwarded arrow.

  • emlbuilder: add LMSReplyType(t) builder method (value-receiver, immutable; only REPLY/FORWARD accepted).
  • mail_reply.go / mail_reply_all.go: LMSReplyType("REPLY").
  • mail_forward.go: LMSReplyType("FORWARD").
  • No CI / workflow file changes.

Summary by CodeRabbit

  • New Features

    • Mail replies and forwards now include a reply classification when a message ID is present.
    • Supported values are limited to reply or forward, with invalid values ignored.
  • Bug Fixes

    • Improved consistency of generated email headers for reply and forward actions.
  • Tests

    • Added coverage for valid and invalid reply classification values in generated email output.

larkcli reply/reply-all/forward built the reply relationship via
X-LMS-Reply-To-Message-Id but never carried the reply type, so the backend
could not distinguish REPLY vs FORWARD and never labeled the original message.
Add emlbuilder.LMSReplyType (REPLY/FORWARD) and call it after
LMSReplyToMessageID in the three mail shortcuts.
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The mail EML builder now supports X-LMS-Reply-Type. Reply, reply-all, and forward shortcut flows set REPLY or FORWARD when a message ID is present, and tests cover valid and invalid header emission.

Changes

LMS reply type support

Layer / File(s) Summary
Builder support and header emission
shortcuts/mail/emlbuilder/builder.go, shortcuts/mail/emlbuilder/builder_test.go
Builder stores an lmsReplyType value, accepts REPLY and FORWARD through LMSReplyType, emits X-LMS-Reply-Type during Build(), and tests cover valid and invalid values.
Reply and forward shortcut wiring
shortcuts/mail/mail_reply.go, shortcuts/mail/mail_reply_all.go, shortcuts/mail/mail_forward.go
The reply, reply-all, and forward shortcut paths now set LMSReplyType alongside LMSReplyToMessageID when message-id is provided.

Sequence Diagram(s)

sequenceDiagram
  participant MailReply
  participant MailReplyAll
  participant MailForward
  participant Builder
  MailReply->>Builder: LMSReplyToMessageID(messageId) and LMSReplyType("REPLY")
  MailReplyAll->>Builder: LMSReplyToMessageID(messageId) and LMSReplyType("REPLY")
  MailForward->>Builder: LMSReplyToMessageID(messageId) and LMSReplyType("FORWARD")
  Builder->>Builder: Build() emits X-LMS-Reply-Type when In-Reply-To exists
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

Hoppity hop, I pricked my ears today,
REPLY and FORWARD found their way.
The builder tucked a header tight,
Then sprang into the EML at night. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately names the main change: adding the X-LMS-Reply-Type header for reply, reply-all, and forward flows.
Description check ✅ Passed The description covers Summary and Changes well, but omits the required Test Plan and Related Issues sections.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added domain/mail PR touches the mail domain size/M Single-domain feat or fix with limited business impact labels Jun 26, 2026
@github-actions

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@f9e8ac5b6ea85bc1115ca16f638cd8fde1de0473

🧩 Skill update

npx skills add xzcong0820/larksuite-cli#fix/reply-forward-label -y -g

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
shortcuts/mail/emlbuilder/builder.go (1)

740-747: 🎯 Functional Correctness | 🟡 Minor

LMS reply headers are incorrectly gated on inReplyTo condition

The X-LMS-Reply-To-Message-Id and X-LMS-Reply-Type headers are only written when b.inReplyTo != "", but these builder fields are set independently of inReplyTo. In the call sites (mail_reply.go, mail_reply_all.go, mail_forward.go), inReplyTo is populated only when normalizeMessageID(orig.smtpMessageId) != "", while lmsReplyToMessageID and lmsReplyType are set whenever messageId is provided.

If a message lacks an SMTP Message-ID but has the Lark messageId (a realistic case for fetched Lark messages), the LMS header setters are called but the headers are silently dropped. This prevents the backend from labeling the original message as REPLIED/FORWARD, defeating the PR's purpose.

Fix: Write the LMS headers unconditionally when their respective builder fields are non-empty, independent of the inReplyTo check:

Current code (lines 740-747)
	if b.inReplyTo != "" {
		writeHeader(&buf, "In-Reply-To", "<"+b.inReplyTo+">")
		if b.lmsReplyToMessageID != "" {
			writeHeader(&buf, "X-LMS-Reply-To-Message-Id", b.lmsReplyToMessageID)
		}
		if b.lmsReplyType != "" {
			writeHeader(&buf, "X-LMS-Reply-Type", b.lmsReplyType)
		}
Proposed fix
	if b.inReplyTo != "" {
		writeHeader(&buf, "In-Reply-To", "<"+b.inReplyTo+">")
	}
	if b.lmsReplyToMessageID != "" {
		writeHeader(&buf, "X-LMS-Reply-To-Message-Id", b.lmsReplyToMessageID)
	}
	if b.lmsReplyType != "" {
		writeHeader(&buf, "X-LMS-Reply-Type", b.lmsReplyType)
	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@shortcuts/mail/emlbuilder/builder.go` around lines 740 - 747, The LMS reply
headers are incorrectly tied to the In-Reply-To branch in Builder.writeHeaders,
so X-LMS-Reply-To-Message-Id and X-LMS-Reply-Type get dropped whenever
b.inReplyTo is empty. Update the header-writing logic so b.lmsReplyToMessageID
and b.lmsReplyType are emitted independently whenever those fields are
non-empty, while keeping the In-Reply-To header behind its existing check. This
change should preserve the reply-specific LMS metadata set by the mail_reply.go,
mail_reply_all.go, and mail_forward.go call sites even when
normalizeMessageID(orig.smtpMessageId) yields an empty value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@shortcuts/mail/emlbuilder/builder.go`:
- Around line 740-747: The LMS reply headers are incorrectly tied to the
In-Reply-To branch in Builder.writeHeaders, so X-LMS-Reply-To-Message-Id and
X-LMS-Reply-Type get dropped whenever b.inReplyTo is empty. Update the
header-writing logic so b.lmsReplyToMessageID and b.lmsReplyType are emitted
independently whenever those fields are non-empty, while keeping the In-Reply-To
header behind its existing check. This change should preserve the reply-specific
LMS metadata set by the mail_reply.go, mail_reply_all.go, and mail_forward.go
call sites even when normalizeMessageID(orig.smtpMessageId) yields an empty
value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f108a1ee-8a42-46b7-bd00-69cc8948c0b0

📥 Commits

Reviewing files that changed from the base of the PR and between 8a268aa and f9e8ac5.

📒 Files selected for processing (5)
  • shortcuts/mail/emlbuilder/builder.go
  • shortcuts/mail/emlbuilder/builder_test.go
  • shortcuts/mail/mail_forward.go
  • shortcuts/mail/mail_reply.go
  • shortcuts/mail/mail_reply_all.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain/mail PR touches the mail domain size/M Single-domain feat or fix with limited business impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant