Documentation
¶
Overview ¶
Package imapbackend is the IMAP protocol backend (ADR 0037): it speaks IMAP, with Gmail's extensions, and hands over change sets.
Its 服务器位置 (backend.MessageRef) and folder cursors are UIDVALIDITY:UID, each zero-padded to 10 digits, so the refs of one UIDVALIDITY sort as text by UID. A folder's backend.FolderRef is its name.
Index ¶
- Constants
- Variables
- func Decode(ref string) (validity, n uint32)
- func Encode(validity, n uint32) string
- func Roles(list []*imap.ListData) []backend.Role
- func Selectable(d *imap.ListData) bool
- type Config
- type Receiver
- func (r *Receiver) Apply(ctx context.Context, op backend.Op) (_ backend.Result, err error)
- func (r *Receiver) Check(ctx context.Context) (_ backend.CheckResult, err 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, err error)
- func (r *Receiver) Find(ctx context.Context, folder backend.FolderRef, messageID string, size int64) (_ []backend.MessageRef, err error)
- func (r *Receiver) Headers(ctx context.Context, folder backend.FolderRef, refs []backend.MessageRef, ...) (_ map[backend.MessageRef][]byte, err error)
- func (r *Receiver) Sync(ctx context.Context, req backend.SyncRequest, commit func(backend.Page) error) (_ bool, err error)
- func (r *Receiver) Watch(ctx context.Context, wake func(folders []backend.FolderRef)) (err error)
Constants ¶
const GmailFeature = "X-GM-EXT-1"
GmailFeature is the capability of a server with Gmail's IMAP extensions.
Variables ¶
var PollInterval = 5 * time.Minute
PollInterval is how often an account syncs when the server cannot push. Tests lower it.
Functions ¶
func Decode ¶
Decode is Encode's inverse; "" (NULL) and anything malformed decode to 0, 0, as the NULL UIDVALIDITY and last_uid of a folder never synced did.
func Encode ¶
Encode is the server_ref of UID n under validity, or a folder cursor whose last seen UID is n.
func Roles ¶
Roles are the roles of LIST's folders, in its order: each folder's SPECIAL-USE role, else one guessed from its (last) name segment, unless another folder carries that role as SPECIAL-USE (Gmail's [Gmail]/Sent Mail beats a folder named Sent Messages).
func Selectable ¶
Selectable reports whether the folder can hold mail: those a sync mirrors.
Types ¶
type Config ¶
type Config struct {
Host string
Port int
Security conn.Security
Credentials backend.CredentialsFunc
}
Config is how to reach an account's IMAP server.
type Receiver ¶
type Receiver struct {
// contains filtered or unexported fields
}
Receiver is an IMAP account's backend.Receiver: one session, over one connection it dials on first use, signing in with Config.Credentials, and keeps until Close, reconnecting if a verb loses the connection. It is not safe for concurrent use, and Watch holds the connection while it runs.
func (*Receiver) Apply ¶
Apply writes one op back. A server's NO is Failed; a location whose folder was recreated (another UIDVALIDITY) is backend.ErrNotFound.
shortcut: Delete is not done yet (nothing queues it); the verb that needs it adds it.
func (*Receiver) Check ¶
Check is the add-account check: a sign-in and the folders a sync would mirror. A failing LIST does not fail it; it reports no folders.
func (*Receiver) Describe ¶
Describe declares what the server's capabilities allow, as they were at sign-in.
func (*Receiver) Fetch ¶
func (r *Receiver) Fetch(ctx context.Context, req backend.ContentRequest) (_ io.ReadCloser, err error)
Fetch streams the content req names. Closing the stream before its end cuts the connection, since IMAP has no way to stop a literal; the next call dials a fresh one.
func (*Receiver) Find ¶
func (r *Receiver) Find(ctx context.Context, folder backend.FolderRef, messageID string, size int64) (_ []backend.MessageRef, err error)
Find lists the messages in folder, examined, whose Message-ID is exactly messageID and, when size > 0, of that size. SEARCH HEADER matches substrings and ignores case, so each hit is checked.
func (*Receiver) Headers ¶
func (r *Receiver) Headers(ctx context.Context, folder backend.FolderRef, refs []backend.MessageRef, fields []string) (_ map[backend.MessageRef][]byte, err error)
Headers reads the fields of refs in folder with one UID FETCH; refs of another UIDVALIDITY than the folder's are gone. A SELECT the server refuses is a backend.FolderError.
func (*Receiver) Sync ¶
func (r *Receiver) Sync(ctx context.Context, req backend.SyncRequest, commit func(backend.Page) error) (_ bool, err error)
Sync runs one sync round: the folder list, then each folder's new mail, backfill and flags snapshot, in LIST order. A folder the server refuses is skipped, so it cannot hold back the others' arrivals round after round; its refusal comes back as a backend.FolderError, and a broken connection still stops the round.