Documentation
¶
Overview ¶
Package jmap is the JMAP protocol backend (RFC 8620, 8621; ADR 0037): a backend.Receiver and backend.Sender over an account's JMAP session.
Index ¶
- Constants
- Variables
- type Config
- type Receiver
- func (r *Receiver) Apply(ctx context.Context, op backend.Op) (backend.Result, error)
- func (r *Receiver) Check(ctx context.Context) (backend.CheckResult, error)
- func (r *Receiver) Close() error
- func (r *Receiver) Describe(ctx context.Context) (backend.Description, error)
- func (r *Receiver) Fetch(ctx context.Context, req backend.ContentRequest) (io.ReadCloser, error)
- func (r *Receiver) Find(ctx context.Context, folder backend.FolderRef, messageID string, size int64) ([]backend.MessageRef, error)
- func (r *Receiver) Headers(ctx context.Context, folder backend.FolderRef, refs []backend.MessageRef, ...) (map[backend.MessageRef][]byte, error)
- func (r *Receiver) Sync(ctx context.Context, req backend.SyncRequest, commit func(backend.Page) error) (bool, error)
- func (r *Receiver) Watch(ctx context.Context, wake func(folders []backend.FolderRef)) error
- type Sender
Constants ¶
const ReasonNoSubmission = "jmap.no_submission"
ReasonNoSubmission is the add-account check's refusal of a JMAP server (or API token) whose session does not advertise urn:ietf:params:jmap:submission.
Variables ¶
var ErrNoSubmission = errors.New(ReasonNoSubmission)
ErrNoSubmission is Check or Send on a session without JMAP email submission. Its message is ReasonNoSubmission. Check returns it with a full CheckResult: the account can still receive.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// SessionURL is the session resource, or /.well-known/jmap to discover it.
SessionURL string
Credentials backend.CredentialsFunc
// SentFolder, when non-nil, overrides which mailbox Sender files the sent
// copy into: *SentFolder is the target Mailbox id, or "" when the account
// has no Sent folder (the staged copy is destroyed once submitted). When
// nil, Sender uses the server's RoleSent mailbox.
SentFolder *backend.FolderRef
}
Config is how to reach an account.
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
Receiver is a JMAP account's receiving backend. Its folders are mailboxes (FolderRef is the Mailbox id), a message's ServerID and every MessageRef of it are its Email id, and its cursor is the account's Mailbox and Email state.
func (*Receiver) Apply ¶
Apply implements backend.Receiver: each op is one Email/set. The Email id stays the same wherever the message goes, so Done carries it.
func (*Receiver) Describe ¶
Describe implements backend.Receiver. Its first call signs in, fetching the session, so refused credentials are ErrAuthFailed here.
func (*Receiver) Fetch ¶
func (r *Receiver) Fetch(ctx context.Context, req backend.ContentRequest) (io.ReadCloser, error)
Fetch implements backend.Receiver. Sync gives the whole message, which local storage parses, so a part is named by its IMAP part path ("1.2") and cut from the whole message, still transfer-encoded as IMAP gives it. shortcut: a part downloads the whole message; use the part's own blobId from bodyStructure if large mail makes that slow.
func (*Receiver) Find ¶
func (r *Receiver) Find(ctx context.Context, folder backend.FolderRef, messageID string, size int64) ([]backend.MessageRef, error)
Find implements backend.Receiver.
func (*Receiver) Headers ¶
func (r *Receiver) Headers(ctx context.Context, folder backend.FolderRef, refs []backend.MessageRef, fields []string) (map[backend.MessageRef][]byte, error)
Headers implements backend.Receiver. shortcut: one download per message, as Fetch; ask Email/get for the header:* properties of all refs at once if refreshes get slow.
func (*Receiver) Sync ¶
func (r *Receiver) Sync(ctx context.Context, req backend.SyncRequest, commit func(backend.Page) error) (bool, error)
Sync implements backend.Receiver. It reports changes since the cursor and the mail a window wider than the cursor's adds, or everything in the window at first and after the server cannot calculate changes (then each folder is reset first). It always syncs the whole account: Only is not used, nor are Pages and PageSize, so more is false. shortcut: no 加载更早 (Older) on JMAP yet, so it is ErrUnsupported; add an Email/query past each folder's window when core asks for it.
func (*Receiver) Watch ¶
Watch implements backend.Receiver over the session's EventSource. It wakes for every state the server sends, the one on connect included, which covers what changed while it was not connected. When the server closes the stream, or sends nothing, not even a ping, for watchStall, it connects again.
type Sender ¶ added in v1.35.0
type Sender struct {
// contains filtered or unexported fields
}
Sender is a JMAP account's sending backend (RFC 8621 section 7): it uploads the RFC 5322 message as a blob, then imports the Email and creates an EmailSubmission with an explicit envelope and onSuccessUpdateEmail in one JMAP request.
func (*Sender) SavesSent ¶ added in v1.35.0
SavesSent implements backend.Sender: Email/import + onSuccessUpdateEmail places the sent copy in the Sent mailbox on the server, unless the follow-up Email/set failed (or the configured Sent mailbox was missing), in which case SavesSent reports false so core's outbox archives or retains recovery state.
func (*Sender) Send ¶ added in v1.35.0
Send implements backend.Sender. Any failure before the EmailSubmission/set HTTP request is written whole (session, Identity/get, blob upload) is a plain error (or ErrAuthFailed / *RejectedError) and safe to retry. Once the submission HTTP request has been written, a lost response (timeout, dropped connection, unreadable body, or HTTP 5xx) returns backend.ErrUncertain.