Skip to content

feat(mail): add allow-block sender shortcuts#1728

Open
sysuljx wants to merge 4 commits into
larksuite:mainfrom
sysuljx:feat/a834648
Open

feat(mail): add allow-block sender shortcuts#1728
sysuljx wants to merge 4 commits into
larksuite:mainfrom
sysuljx:feat/a834648

Conversation

@sysuljx

@sysuljx sysuljx commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Adds mail shortcuts for managing allow and block sender lists.

  • Adds list, search, set, and delete commands for allow/block senders.
  • Implements request validation, dry-run output, HTTP method/path/body handling, address parsing, and user-facing error hints.
  • Registers the shortcuts and covers validation, request construction, address files, retry hints, and error wrapping in tests.
  • Updates the mail skill documentation and references for the new commands.

Summary by CodeRabbit

  • New Features
    • Added user-level mail allow/block sender list commands: +allow-block-list, +allow-block-search, +allow-block-set, +allow-block-delete (list/search, bulk add, and remove).
    • Includes pagination + keyword search, stricter --type validation, and bulk input via --address-file with trimming/deduping; results aggregate allow/block with per-list counts.
  • Bug Fixes
    • +allow-block-delete preserves original address casing and improves deletion success counting across response shapes.
  • Documentation
    • Updated mail/skill references with the user-level workflow and preview + confirmation requirements for set/delete.
  • Tests
    • Added coverage for registration, validation, dry-run payloads, set/delete behaviors, list aggregation, and decorated error hints.

@github-actions github-actions Bot added domain/mail PR touches the mail domain size/L Large or sensitive change across domains or core paths labels Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 25a336e7-abe7-4608-9281-d1be4e0a235f

📥 Commits

Reviewing files that changed from the base of the PR and between e3d96e3 and 2429df4.

📒 Files selected for processing (6)
  • shortcuts/mail/mail_allow_block.go
  • shortcuts/mail/mail_allow_block_test.go
  • shortcuts/mail/shortcuts.go
  • skill-template/domains/mail.md
  • skills/lark-mail/SKILL.md
  • skills/lark-mail/references/lark-mail-allow-block.md
✅ Files skipped from review due to trivial changes (2)
  • skill-template/domains/mail.md
  • skills/lark-mail/references/lark-mail-allow-block.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • shortcuts/mail/shortcuts.go
  • shortcuts/mail/mail_allow_block.go
  • shortcuts/mail/mail_allow_block_test.go

📝 Walkthrough

Walkthrough

Adds four mail shortcuts for per-user sender allow/block list management, including list/search/set/delete flows, validation, file-backed address input, API error decoration, registration, tests, and documentation updates.

Changes

Allow/Block sender list feature

Layer / File(s) Summary
Shared constants and helpers
shortcuts/mail/mail_allow_block.go
Defines allow/block constants and limits, shared flags, output shapes, validation helpers, request builders, item normalization, count conversion, and API error decoration helpers.
List and search shortcuts
shortcuts/mail/mail_allow_block.go
Implements +allow-block-list and +allow-block-search, including shortcut wiring, validation, backend GET requests, aggregation, and formatted output.
Set and delete shortcuts
shortcuts/mail/mail_allow_block.go
Implements +allow-block-set and +allow-block-delete, including address collection, file reading, deduplication, batch payload construction, API invocation, fallback handling, and formatted counts.
Shortcut registration
shortcuts/mail/shortcuts.go
Registers the four new allow-block shortcuts in Shortcuts().
Unit tests for allow-block shortcuts
shortcuts/mail/mail_allow_block_test.go
Adds tests for registration, validation, dry-run API targets, file-backed sender input, delete casing, list aggregation, and API error decoration.
Skill and reference documentation
skill-template/domains/mail.md, skills/lark-mail/SKILL.md, skills/lark-mail/references/lark-mail-allow-block.md
Updates skill-template and lark-mail documentation to define the user-level allow/block sender list, require confirmation for set/delete, and add a dedicated reference guide.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant MailAllowBlockList
  participant MailAllowBlockSet
  participant MailAllowBlockDelete
  participant MailBackend
  CLI->>MailAllowBlockList: +allow-block-list / +allow-block-search
  MailAllowBlockList->>MailBackend: GET allow_senders or blocked_senders
  MailBackend-->>MailAllowBlockList: items and counts
  MailAllowBlockList-->>CLI: formatted list/search output
  CLI->>MailAllowBlockSet: +allow-block-set with addresses
  MailAllowBlockSet->>MailBackend: POST batch_create
  MailBackend-->>MailAllowBlockSet: failed_items / requested counts
  MailAllowBlockSet-->>CLI: formatted set output
  CLI->>MailAllowBlockDelete: +allow-block-delete with addresses
  MailAllowBlockDelete->>MailBackend: DELETE batch_delete
  MailBackend-->>MailAllowBlockDelete: deleted_count or fallback error
  MailAllowBlockDelete-->>CLI: formatted delete output
Loading

Possibly related PRs

  • larksuite/cli#749: Extends the same confirmation-rule documentation pattern used here for +allow-block-set and +allow-block-delete.

Suggested reviewers: chanthuang

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding allow/block sender shortcuts.
Description check ✅ Passed It covers the summary and main changes, but it does not follow the template headings or include a test plan and related issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 commented Jul 2, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

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

🧩 Skill update

npx skills add sysuljx/cli#feat/a834648 -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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
shortcuts/mail/mail_allow_block_test.go (1)

273-293: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Hardcoded page-size default applied to all int flags.

Every int-typed flag gets allowBlockDefaultPageSize as its default here, regardless of fl.Default. Currently harmless since the only int flag (page-size) is always overridden via values, but this will silently produce a wrong default if another int flag is added or a test omits an override for page-size.

♻️ Suggested fix to parse the flag's own default
 		switch fl.Type {
 		case "int":
-			cmd.Flags().Int(fl.Name, allowBlockDefaultPageSize, "")
+			def, _ := strconv.Atoi(fl.Default)
+			cmd.Flags().Int(fl.Name, def, "")
🤖 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/mail_allow_block_test.go` around lines 273 - 293, The helper
runtimeForAllowBlockDryRun is hardcoding allowBlockDefaultPageSize for every int
flag instead of using each flag’s own default. Update the flag initialization
loop to read fl.Default for int-typed flags as well, so future int flags and any
tests that rely on the declared default behave correctly.
🤖 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.

Inline comments:
In `@shortcuts/mail/mail_allow_block_test.go`:
- Around line 32-78: The validation test helper is too weak because
assertValidationError only checks the message text, so regressions in
category/subtype/param can slip through. Update assertValidationError to verify
the returned error with errs.ProblemOf and confirm the validation cause is
preserved, then keep TestAllowBlockValidate using that helper for
MailAllowBlockList, MailAllowBlockSearch, MailAllowBlockSet, and
MailAllowBlockDelete.

In `@shortcuts/mail/mail_allow_block.go`:
- Line 15: The shortcuts/mail package is importing internal/vfs directly, which
violates shortcuts-no-vfs. Update mail_allow_block.go to use runtime.FileIO()
and runtime.ValidatePath() for file access instead of vfs, and if the code needs
the entire file contents, open it through runtime.FileIO().Open() and read it
with io.ReadAll(); keep the change localized to the mail shortcut flow and any
helpers it calls.

In `@skills/lark-mail/references/lark-mail-allow-block.md`:
- Line 53: The allow/block list flow in the lark-mail reference should not
silently remove API-rejected senders and retry, because that makes the confirmed
payload differ from the actual write. Update the guidance to require surfacing
the rejected values, showing the adjusted final sender list/count again, and
asking the user to re-confirm before any retry or set/delete operation. Keep the
preview/confirmation requirement aligned with the final payload in the
allow/block list workflow.

---

Nitpick comments:
In `@shortcuts/mail/mail_allow_block_test.go`:
- Around line 273-293: The helper runtimeForAllowBlockDryRun is hardcoding
allowBlockDefaultPageSize for every int flag instead of using each flag’s own
default. Update the flag initialization loop to read fl.Default for int-typed
flags as well, so future int flags and any tests that rely on the declared
default behave correctly.
🪄 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: 59b152a4-abb9-4d10-8c7a-3198565a3698

📥 Commits

Reviewing files that changed from the base of the PR and between c2d6038 and dc55434.

📒 Files selected for processing (6)
  • shortcuts/mail/mail_allow_block.go
  • shortcuts/mail/mail_allow_block_test.go
  • shortcuts/mail/shortcuts.go
  • skill-template/domains/mail.md
  • skills/lark-mail/SKILL.md
  • skills/lark-mail/references/lark-mail-allow-block.md

Comment thread shortcuts/mail/mail_allow_block_test.go
Comment thread shortcuts/mail/mail_allow_block.go Outdated
Comment thread skills/lark-mail/references/lark-mail-allow-block.md Outdated
sysuljx added 4 commits July 6, 2026 01:17
Use shortcut runtime FileIO for address files, strengthen validation assertions, and clarify rejected sender retry guidance.

Change-Type: ci-fix
}
listType := runtime.Str("type")
data, err := runtime.CallAPITyped("DELETE",
allowBlockResourcePath(resolveMailboxID(runtime), listType)+"/batch_delete",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 AI Review | [P1 稳定性] 删除命令调用了未注册的 OAPI 路径

+allow-block-delete 的 dry-run 和执行路径都拼成 DELETE .../batch_delete,但本轮 registry Meta 新增的用户级 allow/block sender 删除接口是 POST .../batch_remove(见 lark/larksuite-cli-registry!113registry-conf/meta/mail_v1.jsonuser_mailbox.*.batch_remove)。真实 OAPI 只会注册 Meta 里的 method/path,当前 CLI 删除命令会打到未注册路由,用户删除白/黑名单时会遇到 404/405 或网关找不到接口。

修复建议: 将 CLI 删除逻辑、dry-run、单测和 skill 文档统一改为 POST {allow_senders|blocked_senders}/batch_remove,或者反向调整 registry/OpenAPI 契约为 DELETE .../batch_delete;关键是 5 个仓库的 method/path 保持一致。

如有疑问或认为判断不准确,欢迎直接回复讨论。

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/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant