-
Notifications
You must be signed in to change notification settings - Fork 948
feat: add default signatures to mail send #1303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bubbmon233
wants to merge
2
commits into
larksuite:main
Choose a base branch
from
bubbmon233:feat/ea59764
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,246 @@ | ||
| // Copyright (c) 2026 Lark Technologies Pte. Ltd. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package mail | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/larksuite/cli/internal/httpmock" | ||
| ) | ||
|
|
||
| func registerSendSignatureList(reg *httpmock.Registry, mailboxID string, signatures []map[string]interface{}, usages []map[string]interface{}) { | ||
| reg.Register(&httpmock.Stub{ | ||
| Method: "GET", | ||
| URL: mailboxPath(mailboxID, "settings", "signatures"), | ||
| Body: map[string]interface{}{ | ||
| "code": 0, | ||
| "data": map[string]interface{}{ | ||
| "signatures": signatures, | ||
| "usages": usages, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func registerSendAsForSignature(reg *httpmock.Registry, mailboxID, email string) { | ||
| reg.Register(&httpmock.Stub{ | ||
| Method: "GET", | ||
| URL: mailboxPath(mailboxID, "settings", "send_as"), | ||
| Body: map[string]interface{}{ | ||
| "code": 0, | ||
| "data": map[string]interface{}{ | ||
| "sendable_addresses": []map[string]interface{}{ | ||
| {"email_address": email, "name": "Sender"}, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func registerDraftCaptureStubsForMailbox(reg *httpmock.Registry, mailboxID string) *httpmock.Stub { | ||
| createStub := &httpmock.Stub{ | ||
| Method: "POST", | ||
| URL: mailboxPath(mailboxID, "drafts"), | ||
| Body: map[string]interface{}{ | ||
| "code": 0, | ||
| "data": map[string]interface{}{"draft_id": "draft_001"}, | ||
| }, | ||
| } | ||
| reg.Register(createStub) | ||
| return createStub | ||
| } | ||
|
|
||
| func TestMailSendAppendsDefaultSignatureToHTMLBody(t *testing.T) { | ||
| f, stdout, _, reg := mailShortcutTestFactoryWithSendScope(t) | ||
| mailboxID := "sig-html-box" | ||
| sender := "sender@example.com" | ||
| registerSendSignatureList(reg, mailboxID, | ||
| []map[string]interface{}{ | ||
| { | ||
| "id": "sig_default", | ||
| "name": "Default", | ||
| "signature_type": "USER", | ||
| "signature_device": "PC", | ||
| "content": `<div>Best,<br>Alice</div>`, | ||
| }, | ||
| }, | ||
| []map[string]interface{}{ | ||
| {"email_address": sender, "send_mail_signature_id": "sig_default"}, | ||
| }, | ||
| ) | ||
| registerSendAsForSignature(reg, mailboxID, sender) | ||
| createStub := registerDraftCaptureStubsForMailbox(reg, mailboxID) | ||
|
|
||
| err := runMountedMailShortcut(t, MailSend, []string{ | ||
| "+send", | ||
| "--mailbox", mailboxID, | ||
| "--from", sender, | ||
| "--to", "bob@example.com", | ||
| "--subject", "hello", | ||
| "--body", "<p>Hello</p>", | ||
| }, f, stdout) | ||
| if err != nil { | ||
| t.Fatalf("send failed: %v", err) | ||
| } | ||
|
|
||
| raw := decodeCapturedRawEML(t, createStub.CapturedBody) | ||
| if !strings.Contains(raw, "lark-mail-signature") { | ||
| t.Fatalf("HTML EML missing signature wrapper:\n%s", raw) | ||
| } | ||
| if !strings.Contains(raw, "Best") || !strings.Contains(raw, "Alice") { | ||
| t.Fatalf("HTML EML missing signature content:\n%s", raw) | ||
| } | ||
| } | ||
|
|
||
| func TestMailSendAppendsDefaultSignatureToPlainTextBody(t *testing.T) { | ||
| f, stdout, _, reg := mailShortcutTestFactoryWithSendScope(t) | ||
| mailboxID := "sig-text-box" | ||
| sender := "sender@example.com" | ||
| registerSendSignatureList(reg, mailboxID, | ||
| []map[string]interface{}{ | ||
| { | ||
| "id": "sig_text", | ||
| "name": "Text", | ||
| "signature_type": "USER", | ||
| "signature_device": "PC", | ||
| "content": `<div>Best,<br>Alice</div>`, | ||
| }, | ||
| }, | ||
| []map[string]interface{}{ | ||
| {"email_address": sender, "send_mail_signature_id": "sig_text"}, | ||
| }, | ||
| ) | ||
| registerSendAsForSignature(reg, mailboxID, sender) | ||
| createStub := registerDraftCaptureStubsForMailbox(reg, mailboxID) | ||
|
|
||
| err := runMountedMailShortcut(t, MailSend, []string{ | ||
| "+send", | ||
| "--mailbox", mailboxID, | ||
| "--from", sender, | ||
| "--to", "bob@example.com", | ||
| "--subject", "hello", | ||
| "--body", "Hello", | ||
| }, f, stdout) | ||
| if err != nil { | ||
| t.Fatalf("send failed: %v", err) | ||
| } | ||
|
|
||
| raw := decodeCapturedRawEML(t, createStub.CapturedBody) | ||
| if !strings.Contains(raw, "Content-Type: text/plain") { | ||
| t.Fatalf("plain body should remain text/plain:\n%s", raw) | ||
| } | ||
| if strings.Contains(raw, "lark-mail-signature") || strings.Contains(raw, "Content-Type: text/html") { | ||
| t.Fatalf("plain body should not contain HTML signature wrapper:\n%s", raw) | ||
| } | ||
| if !strings.Contains(raw, "Hello") || !strings.Contains(raw, "Best") || !strings.Contains(raw, "Alice") { | ||
| t.Fatalf("plain EML missing body or signature text:\n%s", raw) | ||
| } | ||
| } | ||
|
|
||
| func TestMailSendNoSignatureSkipsSignatureLookup(t *testing.T) { | ||
| f, stdout, _, reg := mailShortcutTestFactoryWithSendScope(t) | ||
| mailboxID := "no-sig-box" | ||
| createStub := registerDraftCaptureStubsForMailbox(reg, mailboxID) | ||
|
|
||
| err := runMountedMailShortcut(t, MailSend, []string{ | ||
| "+send", | ||
| "--mailbox", mailboxID, | ||
| "--from", "sender@example.com", | ||
| "--to", "bob@example.com", | ||
| "--subject", "hello", | ||
| "--body", "<p>Hello</p>", | ||
| "--no-signature", | ||
| }, f, stdout) | ||
| if err != nil { | ||
| t.Fatalf("send failed: %v", err) | ||
| } | ||
|
|
||
| raw := decodeCapturedRawEML(t, createStub.CapturedBody) | ||
| if strings.Contains(raw, "lark-mail-signature") || strings.Contains(raw, "Best") { | ||
| t.Fatalf("--no-signature should keep EML signature-free:\n%s", raw) | ||
| } | ||
| } | ||
|
|
||
| func TestMailSendExplicitSignatureOverridesDefault(t *testing.T) { | ||
| f, stdout, _, reg := mailShortcutTestFactoryWithSendScope(t) | ||
| mailboxID := "sig-explicit-box" | ||
| sender := "sender@example.com" | ||
| registerSendSignatureList(reg, mailboxID, | ||
| []map[string]interface{}{ | ||
| { | ||
| "id": "sig_default", | ||
| "name": "Default", | ||
| "signature_type": "USER", | ||
| "signature_device": "PC", | ||
| "content": `<div>Default Signature</div>`, | ||
| }, | ||
| { | ||
| "id": "sig_explicit", | ||
| "name": "Explicit", | ||
| "signature_type": "USER", | ||
| "signature_device": "PC", | ||
| "content": `<div>Explicit Signature</div>`, | ||
| }, | ||
| }, | ||
| []map[string]interface{}{ | ||
| {"email_address": sender, "send_mail_signature_id": "sig_default"}, | ||
| }, | ||
| ) | ||
| registerSendAsForSignature(reg, mailboxID, sender) | ||
| createStub := registerDraftCaptureStubsForMailbox(reg, mailboxID) | ||
|
|
||
| err := runMountedMailShortcut(t, MailSend, []string{ | ||
| "+send", | ||
| "--mailbox", mailboxID, | ||
| "--from", sender, | ||
| "--to", "bob@example.com", | ||
| "--subject", "hello", | ||
| "--body", "<p>Hello</p>", | ||
| "--signature-id", "sig_explicit", | ||
| }, f, stdout) | ||
| if err != nil { | ||
| t.Fatalf("send failed: %v", err) | ||
| } | ||
|
|
||
| raw := decodeCapturedRawEML(t, createStub.CapturedBody) | ||
| if !strings.Contains(raw, "Explicit Signature") { | ||
| t.Fatalf("explicit signature missing from EML:\n%s", raw) | ||
| } | ||
| if strings.Contains(raw, "Default Signature") { | ||
| t.Fatalf("default signature should not be used when --signature-id is set:\n%s", raw) | ||
| } | ||
| } | ||
|
|
||
| func TestMailSendDryRunShowsSignatureLookupUnlessDisabled(t *testing.T) { | ||
| f, stdout, _, _ := mailShortcutTestFactoryWithSendScope(t) | ||
|
|
||
| if err := runMountedMailShortcut(t, MailSend, []string{ | ||
| "+send", | ||
| "--to", "bob@example.com", | ||
| "--subject", "hello", | ||
| "--body", "<p>Hello</p>", | ||
| "--dry-run", | ||
| }, f, stdout); err != nil { | ||
| t.Fatalf("dry-run failed: %v", err) | ||
| } | ||
| if !strings.Contains(stdout.String(), "/settings/signatures") { | ||
| t.Fatalf("default dry-run should include signatures lookup:\n%s", stdout.String()) | ||
| } | ||
|
|
||
| stdout.Reset() | ||
| if err := runMountedMailShortcut(t, MailSend, []string{ | ||
| "+send", | ||
| "--to", "bob@example.com", | ||
| "--subject", "hello", | ||
| "--body", "<p>Hello</p>", | ||
| "--no-signature", | ||
| "--dry-run", | ||
| }, f, stdout); err != nil { | ||
| t.Fatalf("dry-run with --no-signature failed: %v", err) | ||
| } | ||
| if strings.Contains(stdout.String(), "/settings/signatures") { | ||
| t.Fatalf("--no-signature dry-run should omit signatures lookup:\n%s", stdout.String()) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 AI Review | [P2 正确性] DryRun 少展示签名插值会调用的 send_as 请求
mail +send --dry-run在非--no-signature分支只展示了/settings/signatures,但真实执行在选中显式签名或默认签名后还会进入resolveSenderInfo,调用GET /settings/send_as来解析签名模板中的 sender 变量。AI/脚本用 dry-run 预判权限、接口计划或准备 mock 时,会少配这个接口,导致 dry-run 与实际执行不一致。修复建议: 在这个签名分支中补充
GET /settings/send_as,描述为用于签名模板 sender 变量插值;至少对--signature-id场景无条件展示,对默认签名场景说明命中默认签名后会调用。如有疑问或认为判断不准确,欢迎直接回复讨论。