Documentation
¶
Overview ¶
Package service is the layer between the CLI and providers. Every operation goes through it: policy gate first, then the provider call, then the audit log. It also normalises bodies (HTML → sanitized text, truncation) and appends the signoff to agent-written text.
Index ¶
- Constants
- func NormalizeBody(m *provider.Message, includeHTML bool, maxBody int)
- func SanitizeFilename(name, fallbackID string) string
- type APIResult
- type DownloadResult
- type DownloadedFile
- type DryRunResult
- type GetOptions
- type OKResult
- type SendOutput
- type Service
- func (s *Service) API(ctx context.Context, method, path string, body []byte) (any, error)
- func (s *Service) CreateDraft(ctx context.Context, in provider.DraftInput) (any, error)
- func (s *Service) DefaultSyncStateFile(label string) string
- func (s *Service) DeleteDraft(ctx context.Context, id string) (any, error)
- func (s *Service) DownloadAttachments(ctx context.Context, id, attachmentID, outDir string) (*DownloadResult, error)
- func (s *Service) EffectiveMode() policy.Mode
- func (s *Service) ForwardDraft(ctx context.Context, in provider.ForwardInput) (any, error)
- func (s *Service) Get(ctx context.Context, id string, o GetOptions) (*provider.Message, error)
- func (s *Service) GetDraft(ctx context.Context, id string, o GetOptions) (*provider.Message, error)
- func (s *Service) Label(ctx context.Context, id string, add, remove []string) (any, error)
- func (s *Service) List(ctx context.Context, o provider.ListOptions) (*provider.Page, error)
- func (s *Service) ListAttachments(ctx context.Context, id string) ([]provider.AttachmentMeta, error)
- func (s *Service) ListDrafts(ctx context.Context, o provider.ListOptions) (*provider.Page, error)
- func (s *Service) Mark(ctx context.Context, id string, o provider.MarkOptions) (any, error)
- func (s *Service) Move(ctx context.Context, id, dest string) (any, error)
- func (s *Service) ReplyDraft(ctx context.Context, in provider.ReplyInput) (any, error)
- func (s *Service) Search(ctx context.Context, o provider.SearchOptions) (*provider.Page, error)
- func (s *Service) Send(ctx context.Context, draftID, key string) (any, error)
- func (s *Service) Sync(ctx context.Context, label, stateFile string) (*SyncOutput, error)
- func (s *Service) SyncFrom(ctx context.Context, label, state string) (*provider.SyncResult, error)
- func (s *Service) Thread(ctx context.Context, threadID string, limit int, o GetOptions) ([]provider.Message, error)
- func (s *Service) UpdateDraft(ctx context.Context, id string, u provider.DraftUpdate) (any, error)
- func (s *Service) WithSignoff(body string) string
- type SyncOutput
Constants ¶
const DefaultMaxBody = 20000
const ( // IdempotencyWindow is how long a sent key is remembered. IdempotencyWindow = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
func NormalizeBody ¶
NormalizeBody derives BodyText from HTML when HTML is present (so hidden text is stripped and the model reads what a human would see), drops raw HTML unless requested, and truncates.
func SanitizeFilename ¶
SanitizeFilename keeps a safe basename: no path separators, no control or shell-hostile characters, no leading dots, max 200 bytes.
Types ¶
type APIResult ¶
type APIResult struct {
Status int `json:"status"`
Body json.RawMessage `json:"body,omitempty"`
}
type DownloadResult ¶
type DownloadResult struct {
MessageID string `json:"message_id"`
Files []DownloadedFile `json:"files"`
}
func (*DownloadResult) IDs ¶
func (r *DownloadResult) IDs() []string
type DownloadedFile ¶
type DryRunResult ¶
type DryRunResult struct {
DryRun bool `json:"dry_run"`
Op policy.Op `json:"op"`
Account string `json:"account"`
Decision policy.Decision `json:"decision"`
Args any `json:"args"`
}
DryRunResult is returned instead of performing a write under --dry-run.
type GetOptions ¶
type SendOutput ¶
type SendOutput struct {
Sent bool `json:"sent"`
Replayed bool `json:"replayed"` // true: an earlier send with this key; nothing was sent now
Account string `json:"account"`
DraftID string `json:"draft_id"`
MessageID string `json:"message_id,omitempty"`
InternetMessageID string `json:"internet_message_id,omitempty"`
ThreadID string `json:"thread_id,omitempty"`
Recipients []string `json:"recipients"`
Subject string `json:"subject"`
SentAt time.Time `json:"sent_at"`
IdempotencyKey string `json:"idempotency_key"`
}
SendOutput is the result of `email send`.
func (*SendOutput) IDs ¶
func (o *SendOutput) IDs() []string
IDs makes `--format id` print the sent message's id.
type Service ¶
type Service struct {
Account *auth.Account
Provider provider.Provider
Policy *policy.Policy
Audit *audit.Logger
StateDir string
DryRun bool
}
func (*Service) CreateDraft ¶
func (*Service) DefaultSyncStateFile ¶
func (*Service) DeleteDraft ¶
func (*Service) DownloadAttachments ¶
func (s *Service) DownloadAttachments(ctx context.Context, id, attachmentID, outDir string) (*DownloadResult, error)
DownloadAttachments writes attachments (all, or just attachmentID) into outDir with sanitized names. Files are written 0600 and never executed.
func (*Service) EffectiveMode ¶
func (*Service) ForwardDraft ¶
func (*Service) ListAttachments ¶
func (*Service) ListDrafts ¶
func (*Service) ReplyDraft ¶
func (*Service) Send ¶
Send sends an existing draft. The body is sent as written: the signoff was added when the draft was written.
Order matters: the mode check comes first so draft mode never touches the network; the idempotency lookup comes before reading the draft because a sent draft no longer exists; the recipient rules run on the draft as it is now on the server.
func (*Service) Sync ¶
Sync returns mail that arrived since the cursor in stateFile, then advances the cursor. The first run only records a baseline.
func (*Service) SyncFrom ¶
SyncFrom returns mail that arrived since the cursor state ("" sets a baseline). The caller keeps the cursor: `email watch` has its own, apart from `email sync`'s state files.
func (*Service) UpdateDraft ¶
func (*Service) WithSignoff ¶
WithSignoff appends the policy signoff to agent-written body text, once.