bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
59 lines
2.5 KiB
Go
59 lines
2.5 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package mail
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/larksuite/cli/shortcuts/common"
|
|
)
|
|
|
|
// MailMessage is the `+message` shortcut: fetch full content of one email
|
|
// by one message ID (normalized body + attachments / inline metadata).
|
|
var MailMessage = common.Shortcut{
|
|
Service: "mail",
|
|
Command: "+message",
|
|
Description: "Use only when reading full content for one email by one message ID. For multiple message IDs, use mail +messages; do not loop mail +message. Returns normalized body content plus attachments metadata, including inline images.",
|
|
Risk: "read",
|
|
Scopes: []string{"mail:user_mailbox.message:readonly", "mail:user_mailbox.message.address:read", "mail:user_mailbox.message.subject:read", "mail:user_mailbox.message.body:read"},
|
|
AuthTypes: []string{"user", "bot"},
|
|
HasFormat: true,
|
|
Flags: []common.Flag{
|
|
{Name: "mailbox", Default: "me", Desc: "email address (default: me)"},
|
|
{Name: "message-id", Desc: "Required. Single email message ID only. For multiple IDs, use mail +messages --message-ids.", Required: true},
|
|
{Name: "html", Type: "bool", Default: "true", Desc: "Whether to return HTML body (false returns plain text only to save bandwidth)"},
|
|
{Name: "print-output-schema", Type: "bool", Desc: "Print output field reference (run this first to learn field names before parsing output)"},
|
|
},
|
|
Validate: func(ctx context.Context, runtime *common.RuntimeContext) error {
|
|
return validateBotMailboxNotMe(runtime)
|
|
},
|
|
DryRun: func(ctx context.Context, runtime *common.RuntimeContext) *common.DryRunAPI {
|
|
mailboxID := resolveMailboxID(runtime)
|
|
messageID := runtime.Str("message-id")
|
|
return common.NewDryRunAPI().
|
|
Desc("Fetch full email content and attachments metadata, including inline images").
|
|
GET(mailboxPath(mailboxID, "messages", messageID))
|
|
},
|
|
Execute: func(ctx context.Context, runtime *common.RuntimeContext) error {
|
|
if runtime.Bool("print-output-schema") {
|
|
printMessageOutputSchema(runtime)
|
|
return nil
|
|
}
|
|
mailboxID := resolveMailboxID(runtime)
|
|
hintIdentityFirst(runtime, mailboxID)
|
|
messageID := runtime.Str("message-id")
|
|
html := runtime.Bool("html")
|
|
|
|
msg, err := fetchFullMessage(runtime, mailboxID, messageID, html)
|
|
if err != nil {
|
|
return mailDecorateProblemMessage(err, "failed to fetch email")
|
|
}
|
|
|
|
out := buildMessageOutput(msg, html)
|
|
runtime.Out(out, nil)
|
|
maybeHintReadReceiptRequest(runtime, mailboxID, messageID, msg)
|
|
return nil
|
|
},
|
|
}
|