Documentation
¶
Index ¶
- Constants
- Variables
- func DialPublicTCP(ctx context.Context, kind, host string, port int) (net.Conn, error)
- func Dispatch(ctx context.Context, h Handler, action string, args map[string]any) (any, error)
- func Folders(acct EmailAccount) ([]string, error)
- func FormatDryRun(acct EmailAccount, opts SendOptions) string
- func InputSchema() map[string]any
- func MarkSeen(acct EmailAccount, folder string, uid uint32, seen bool) error
- func ResolvePublicHost(kind, host string) ([]netip.Addr, error)
- func SaveAttachments(acct EmailAccount, folder string, uid uint32, dir string) ([]string, error)
- func Send(acct EmailAccount, opts SendOptions) error
- func ValidateAccountEgress(acct EmailAccount) error
- func ValidateAccountName(name string) error
- type Access
- func (a *Access) Accounts(ctx context.Context) (AccountList, error)
- func (a *Access) Folders(ctx context.Context, account string) ([]string, error)
- func (a *Access) List(ctx context.Context, account string, opts ListOptions) ([]Envelope, error)
- func (a *Access) MarkSeen(ctx context.Context, account, folder string, uid uint32, seen bool) error
- func (a *Access) Read(ctx context.Context, account, folder string, uid uint32) (*Message, error)
- func (a *Access) Send(ctx context.Context, account string, opts SendOptions, idempotencyKey string) (SendResult, error)
- type AccountList
- type AccountsInput
- type AttachmentInfo
- type Config
- type EmailAccount
- type Envelope
- type Handler
- type ListInput
- type ListOptions
- type Message
- type Queries
- type ReadInput
- type SendInput
- type SendOptions
- type SendResult
- type Service
- type Tool
Constants ¶
const InputSchemaJSON = `` /* 4453-byte string literal not displayed */
const ToolName = "email"
Variables ¶
var ErrMessageNotFound = errors.New("message not found")
Functions ¶
func DialPublicTCP ¶ added in v0.43.0
func Folders ¶
func Folders(acct EmailAccount) ([]string, error)
Folders returns a sorted list of mailbox names available on the server.
func FormatDryRun ¶
func FormatDryRun(acct EmailAccount, opts SendOptions) string
FormatDryRun returns a human-readable representation of the email that would be sent, for use with --dry-run.
func InputSchema ¶ added in v0.60.0
func MarkSeen ¶ added in v0.26.0
func MarkSeen(acct EmailAccount, folder string, uid uint32, seen bool) error
MarkSeen adds or removes the \Seen flag on a message identified by UID. seen=true marks the message as read; seen=false marks it as unread.
func ResolvePublicHost ¶ added in v0.43.0
ResolvePublicHost resolves host and rejects any result that is not safe for server-side email egress. Callers must connect to the returned IPs, not resolve the original hostname again, or DNS rebinding reopens the SSRF hole.
func SaveAttachments ¶
SaveAttachments downloads and saves all attachments of a message to dir. It returns the list of file paths written.
func Send ¶
func Send(acct EmailAccount, opts SendOptions) error
Send composes and sends an email via SMTP using the provided account configuration.
func ValidateAccountEgress ¶ added in v0.43.0
func ValidateAccountEgress(acct EmailAccount) error
ValidateAccountEgress rejects email server hosts that would make stellad connect to local or private infrastructure on behalf of an authenticated user.
func ValidateAccountName ¶
Types ¶
type Access ¶ added in v0.60.0
type Access struct {
// contains filtered or unexported fields
}
Access is one email use case bound to one trusted Authority. Email is a user-owned capability: the account config lives in the acting user's vault, so ownership is simply the captured userID — every operation loads that user's config and nothing else. A delegated AgentActor acts as its delegating user (an agent shares its user's mail), so it reaches the same accounts. There is no policy evaluation: transports and the agent tool pass a trusted authz.Authority and never a bare identity, and the per-user vault namespace is the boundary.
func (*Access) Accounts ¶ added in v0.60.0
func (a *Access) Accounts(ctx context.Context) (AccountList, error)
func (*Access) Send ¶ added in v0.60.0
func (a *Access) Send(ctx context.Context, account string, opts SendOptions, idempotencyKey string) (SendResult, error)
type AccountList ¶ added in v0.60.0
type AccountsInput ¶ added in v0.60.0
type AccountsInput struct {
}
type AttachmentInfo ¶
type AttachmentInfo struct {
Filename string `json:"filename"`
Size int64 `json:"size"`
MIMEType string `json:"mime_type"`
}
AttachmentInfo holds metadata about a message attachment (no content).
type Config ¶
type Config struct {
Default string `json:"default"`
Accounts map[string]EmailAccount `json:"accounts"`
}
func LoadFromEnv ¶
func (*Config) AccountNames ¶
func (*Config) SetDefault ¶
func (*Config) Upsert ¶
func (c *Config) Upsert(name string, partial EmailAccount)
type EmailAccount ¶
type EmailAccount struct {
IMAPHost string `json:"imap_host,omitempty"`
IMAPPort int `json:"imap_port,omitempty"`
IMAPTLS string `json:"imap_tls,omitempty"`
SMTPHost string `json:"smtp_host,omitempty"`
SMTPPort int `json:"smtp_port,omitempty"`
SMTPTLS string `json:"smtp_tls,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
From string `json:"from,omitempty"`
}
type Envelope ¶
type Envelope struct {
UID uint32 `json:"uid"`
MessageID string `json:"message_id,omitempty"`
From string `json:"from"`
FromName string `json:"from_name,omitempty"`
FromAddr string `json:"from_addr,omitempty"`
To []string `json:"to"`
Subject string `json:"subject"`
Date time.Time `json:"date"`
Flags []string `json:"flags"`
HasAttachments bool `json:"has_attachments"`
Size int64 `json:"size"`
}
Envelope holds metadata about an email message.
func List ¶
func List(acct EmailAccount, opts ListOptions) ([]Envelope, error)
List returns envelope metadata for messages in the given folder, filtered by opts.
type ListInput ¶ added in v0.60.0
type ListInput struct {
Account string `json:"account,omitempty"`
Before string `json:"before,omitempty"`
Folder string `json:"folder,omitempty"`
From string `json:"from,omitempty"`
Limit int `json:"limit,omitempty"`
Since string `json:"since,omitempty"`
Subject string `json:"subject,omitempty"`
Unread *bool `json:"unread,omitempty"`
}
type ListOptions ¶
type ListOptions struct {
Folder string
Limit int
Unread bool
From string
Subject string
Since *time.Time
Before *time.Time
}
ListOptions controls which messages are returned by List.
type Message ¶
type Message struct {
Envelope
TextBody string `json:"text_body,omitempty"`
HTMLBody string `json:"html_body,omitempty"`
Attachments []AttachmentInfo `json:"attachments,omitempty"`
}
Message is a fully-fetched email message including body and attachment metadata.
type Queries ¶ added in v0.60.0
type Queries interface {
DeleteExpiredEmailSendDedup(context.Context) error
CreateEmailSendDedup(context.Context, sqlc.CreateEmailSendDedupParams) (sqlc.EmailSendDedup, error)
GetEmailSendDedup(context.Context, sqlc.GetEmailSendDedupParams) (sqlc.EmailSendDedup, error)
DeleteEmailSendDedup(context.Context, sqlc.DeleteEmailSendDedupParams) error
}
type SendInput ¶ added in v0.60.0
type SendInput struct {
Account string `json:"account,omitempty"`
Bcc []any `json:"bcc,omitempty"`
Body string `json:"body,omitempty"`
Cc []any `json:"cc,omitempty"`
From string `json:"from,omitempty"`
Html *bool `json:"html,omitempty"`
IdempotencyKey string `json:"idempotency_key,omitempty"`
InReplyTo string `json:"in_reply_to,omitempty"`
ReplyTo string `json:"reply_to,omitempty"`
Subject string `json:"subject,omitempty"`
To []any `json:"to,omitempty"`
}
type SendOptions ¶
type SendOptions struct {
To []string
Cc []string
Bcc []string
Subject string
Body string
HTML bool
Attachments []string // file paths
From string // override sender
ReplyTo string
InReplyTo string // Message-ID of the message being replied to
}
SendOptions holds the parameters for composing and sending an email.
type SendResult ¶ added in v0.60.0
type Service ¶ added in v0.60.0
type Service struct {
// contains filtered or unexported fields
}
func NewServiceForPool ¶ added in v0.60.0
NewServiceForPool creates an email service that owns the sqlc query set for the email tables, so callers pass only the pgx pool.
func (*Service) Access ¶ added in v0.60.0
Access binds one email use case to a trusted Authority. It rejects an invalid Authority (403) and one carrying no user (401) up front, so every method can assume a non-empty acting user.
func (*Service) SetSendFunc ¶ added in v0.60.0
func (s *Service) SetSendFunc(fn func(EmailAccount, SendOptions) error)
type Tool ¶ added in v0.60.0
type Tool struct {
// contains filtered or unexported fields
}
func (*Tool) Definition ¶ added in v0.60.0
func (t *Tool) Definition() tools.Definition