Documentation
¶
Overview ¶
Package watch is `email watch`: a long-running process that waits for new mail and wakes the agent with one HTTP notification per batch, so the agent spends no tokens while nothing arrives.
Each account runs on its own: IMAP accounts wait with IDLE on INBOX (falling back to polling), the others poll their provider's sync cursor. New messages go through the watch policy filters into a per-account buffer; a batch is sent once the debounce window after its first message ends. Watch reads metadata only and never changes or sends mail.
Index ¶
Constants ¶
const MaxPayloadMessages = 20
MaxPayloadMessages is how many messages one notification lists; Count still gives the real number.
Variables ¶
var DefaultRetries = []time.Duration{5 * time.Second, 30 * time.Second, 2 * time.Minute}
DefaultRetries are the waits before the 2nd, 3rd and 4th attempt.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Accounts []Account
Filter policy.WatchSection
Notifier Notifier
Debounce time.Duration
PollInterval time.Duration
StateDir string
HealthAddr string // "" = no health endpoint
Log *slog.Logger
Audit *audit.Logger
// NoIdle polls every account, also those whose server offers IDLE (for
// servers that accept IDLE but never report new mail; see doctor).
NoIdle bool
// Zero values get the defaults below; tests shorten them.
IdleMax time.Duration // renew IDLE this often (Gmail drops it at ~29 min)
BackoffMin time.Duration
BackoffMax time.Duration
DegradedRetry time.Duration // how often a degraded account is retried and logged
IdlePause time.Duration // polling time after IdleFailures failed IDLEs
IdleFailures int
OfflineLimit time.Duration // /healthz is 503 once every account is offline this long
}
type HTTPNotifier ¶
type HTTPNotifier struct {
URL string
Token string
Client *http.Client // nil: a client with a 30 s timeout
Retries []time.Duration // nil: DefaultRetries
Log *slog.Logger
}
HTTPNotifier POSTs the payload as JSON, with the token in X-Gitlab-Token (the header the Hermes webhook adapter checks).
type Idler ¶
Idler is a Source that can wait for new mail on the server (IMAP IDLE). It returns errs.Unsupported when the server cannot.
type Item ¶
type Item struct {
ID string `json:"id"`
ThreadID string `json:"thread_id,omitempty"`
From provider.Address `json:"from"`
Subject string `json:"subject"`
Date time.Time `json:"date"`
WebLink string `json:"web_link,omitempty"`
HasAttachments bool `json:"has_attachments"`
Unread bool `json:"unread"`
}
Item is the metadata of one new message, as the notification carries it. Bodies are never read: the agent fetches one with `email get`.
type Payload ¶
type Payload struct {
Source string `json:"source"`
Account string `json:"account"`
Count int `json:"count"`
Messages []Item `json:"messages"`
}
Payload is the body of one notification. It covers one account.
type Source ¶
type Source interface {
Sync(ctx context.Context, state string) (*provider.SyncResult, error)
Close() error
}
Source is one account's mailbox, as watch uses it. Sync returns the mail that arrived after state ("" sets a baseline).