service

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultMaxBody = 20000
View Source
const (
	// IdempotencyWindow is how long a sent key is remembered.
	IdempotencyWindow = 24 * time.Hour
)

Variables

This section is empty.

Functions

func NormalizeBody

func NormalizeBody(m *provider.Message, includeHTML bool, maxBody int)

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

func SanitizeFilename(name, fallbackID string) string

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 DownloadedFile struct {
	ID   string `json:"id"`
	Name string `json:"name"` // original (untrusted) name
	Path string `json:"path"` // sanitized local path
	Size int64  `json:"size"`
	MIME string `json:"mime,omitempty"`
}

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 GetOptions struct {
	IncludeHTML bool
	Headers     bool
	MaxBody     int // 0 = DefaultMaxBody, <0 = unlimited
}

type OKResult

type OKResult struct {
	OK bool   `json:"ok"`
	ID string `json:"id"`
}

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) API

func (s *Service) API(ctx context.Context, method, path string, body []byte) (any, error)

func (*Service) CreateDraft

func (s *Service) CreateDraft(ctx context.Context, in provider.DraftInput) (any, error)

func (*Service) DefaultSyncStateFile

func (s *Service) DefaultSyncStateFile(label string) string

func (*Service) DeleteDraft

func (s *Service) DeleteDraft(ctx context.Context, id string) (any, error)

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 (s *Service) EffectiveMode() policy.Mode

func (*Service) ForwardDraft

func (s *Service) ForwardDraft(ctx context.Context, in provider.ForwardInput) (any, error)

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string, o GetOptions) (*provider.Message, error)

func (*Service) GetDraft

func (s *Service) GetDraft(ctx context.Context, id string, o GetOptions) (*provider.Message, error)

func (*Service) Label

func (s *Service) Label(ctx context.Context, id string, add, remove []string) (any, error)

func (*Service) List

func (*Service) ListAttachments

func (s *Service) ListAttachments(ctx context.Context, id string) ([]provider.AttachmentMeta, error)

func (*Service) ListDrafts

func (s *Service) ListDrafts(ctx context.Context, o provider.ListOptions) (*provider.Page, error)

func (*Service) Mark

func (s *Service) Mark(ctx context.Context, id string, o provider.MarkOptions) (any, error)

func (*Service) Move

func (s *Service) Move(ctx context.Context, id, dest string) (any, error)

func (*Service) ReplyDraft

func (s *Service) ReplyDraft(ctx context.Context, in provider.ReplyInput) (any, error)

func (*Service) Search

func (*Service) Send

func (s *Service) Send(ctx context.Context, draftID, key string) (any, error)

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

func (s *Service) Sync(ctx context.Context, label, stateFile string) (*SyncOutput, error)

Sync returns mail that arrived since the cursor in stateFile, then advances the cursor. The first run only records a baseline.

func (*Service) SyncFrom

func (s *Service) SyncFrom(ctx context.Context, label, state string) (*provider.SyncResult, error)

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) Thread

func (s *Service) Thread(ctx context.Context, threadID string, limit int, o GetOptions) ([]provider.Message, error)

func (*Service) UpdateDraft

func (s *Service) UpdateDraft(ctx context.Context, id string, u provider.DraftUpdate) (any, error)

func (*Service) WithSignoff

func (s *Service) WithSignoff(body string) string

WithSignoff appends the policy signoff to agent-written body text, once.

type SyncOutput

type SyncOutput struct {
	Account     string             `json:"account"`
	Label       string             `json:"label"`
	Initialized bool               `json:"initialized"`
	StateFile   string             `json:"state_file"`
	Messages    []provider.Message `json:"messages"`
}

func (*SyncOutput) IDs

func (o *SyncOutput) IDs() []string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL