Documentation
¶
Overview ¶
Package engine talks to mail servers: it keeps the local copy in step with IMAP, applies the user's actions there, and sends over SMTP.
Index ¶
- Constants
- Variables
- func CleanHTML(h string) string
- func Credential(ctx context.Context, sec secrets.Store, a store.Account) (cred, refresh string, err error)
- func TestAccount(a store.Account, password string) (store.Account, error)
- type Attachment
- type Draft
- type Engine
- func (e *Engine) Apply(ctx context.Context, ids []int64, action string, targetFolder int64) error
- func (e *Engine) Build(ctx context.Context, d Draft) ([]byte, []string, store.Account, error)
- func (e *Engine) Cleanup(ctx context.Context, ids []int64, view string, identities map[int64]string) error
- func (e *Engine) Credential(ctx context.Context, a store.Account) (string, error)
- func (e *Engine) EnsureBody(ctx context.Context, id int64) (store.Message, error)
- func (e *Engine) FetchPart(ctx context.Context, id int64, path string) (store.Part, []byte, error)
- func (e *Engine) Send(ctx context.Context, d Draft) error
- func (e *Engine) Start() error
- func (e *Engine) StartAccount(id int64)
- func (e *Engine) Stop()
- func (e *Engine) StopAccount(id int64)
- func (e *Engine) SyncNow(accountID int64)
Constants ¶
const ( ActRead = "read" ActUnread = "unread" ActFlag = "flag" ActUnflag = "unflag" ActArchive = "archive" ActTrash = "trash" ActSpam = "spam" ActNotSpam = "inbox" // move back to the inbox ActMove = "move" // ActNotJunk is the user's "Not spam": a message in a Junk folder goes // back to the inbox, one the local junk filter hid shows there again; // either way the filter learns it and never flags the sender again. ActNotJunk = "notjunk" )
Action names accepted by Apply.
Variables ¶
var ( FullSyncEvery = 5 * time.Minute PollEvery = 2 * time.Minute // when the server has no IDLE IdleRestart = 20 * time.Minute )
Intervals; tests shorten them.
var ( // AutoLearnCap is how many messages of each kind are learned without the // user (the Junk folder as spam; the Sent folder and mail the user // replied to, starred, or got from a correspondent as ham). The user's own // Spam and Not spam are always learned. AutoLearnCap = 2000 // JunkHeaderStep is how many stored inbox messages get their header read // again per sync pass, newest first, until every one has. JunkHeaderStep = 300 // RejudgeCap is how many of the newest inbox messages are judged again // (locally, from stored facts) when the classifier first becomes ready. RejudgeCap = 2000 // MaxJunkTokens bounds the classifier's table. MaxJunkTokens = 60000 )
Limits; tests shorten them.
var ( InitialWindow = 500 // newest messages fetched on the first sync of a folder BackfillStep = 500 // older messages added per full sync MaxPerFolder = 20000 // stop backfilling past this BodiesPerPass = 300 // bodies fetched per folder per pass MaxTextPart = int64(2 << 20) )
How much history is kept locally; older mail is fetched in steps.
var ErrBadAction = errors.New("unknown action")
ErrBadAction is returned for an unknown action.
var ErrNoPart = errors.New("no such part")
ErrNoPart is returned for an unknown part path.
var ErrNoRecipients = errors.New("no recipients")
ErrNoRecipients is returned for a draft with nobody to send to.
var TLSConfig *tls.Config
TLSConfig is used for every TLS connection; tests replace it to trust a local server.
Functions ¶
func CleanHTML ¶
CleanHTML removes what can act: scripts, frames, refreshes, event handlers. It is defence in depth; the reader also renders mail in a sandboxed iframe under a CSP that blocks scripts and remote loads.
func Credential ¶ added in v0.116.0
func Credential(ctx context.Context, sec secrets.Store, a store.Account) (cred, refresh string, err error)
Credential is what signs an account in: its password, or for an OAuth account an access token refreshed from the stored refresh token (cached until a minute before it expires). refresh is the refresh token in use, "" for a password account. A refresh token the provider rotated is saved back.
Types ¶
type Attachment ¶
type Attachment struct {
Filename string `json:"filename"`
Type string `json:"type"`
Data []byte `json:"data"` // base64 in JSON
}
Attachment is a file to send.
type Draft ¶
type Draft struct {
AccountID int64 `json:"account_id"`
To []store.Address `json:"to"`
Cc []store.Address `json:"cc"`
Bcc []store.Address `json:"bcc"`
Subject string `json:"subject"`
Text string `json:"text"`
HTML string `json:"html"`
InReplyTo int64 `json:"in_reply_to"` // local message id being answered
Attachments []Attachment `json:"attachments"`
}
Draft is a message to send.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs one worker per account.
func (*Engine) Apply ¶
Apply performs an action on messages, which may span accounts and folders. targetFolder is used by ActMove.
func (*Engine) Build ¶
Build renders a draft as an RFC 5322 message. Returns the bytes and envelope recipients.
func (*Engine) Cleanup ¶ added in v0.135.0
func (e *Engine) Cleanup(ctx context.Context, ids []int64, view string, identities map[int64]string) error
Cleanup is scoped: Spam only moves to Trash; Trash only deletes from Trash. It never falls back to expunging unrelated messages on older IMAP servers.
func (*Engine) Credential ¶ added in v0.116.0
Credential is the engine's view of the package function.
func (*Engine) EnsureBody ¶
EnsureBody fetches a message's body now if the background pass has not yet.
func (*Engine) Send ¶
Send delivers a draft over SMTP, files it in Sent and marks the original answered.
func (*Engine) StartAccount ¶
StartAccount launches (or restarts) the worker of an account.
func (*Engine) StopAccount ¶
StopAccount ends an account's worker.