imapbackend

package
v1.42.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 22 Imported by: 1 module, 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 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

View Source
const GmailFeature = "X-GM-EXT-1"

GmailFeature is the capability of a server with Gmail's IMAP extensions.

Variables

View Source
var PollInterval = 5 * time.Minute

PollInterval is how often an account syncs when the server cannot push. Tests lower it.

Functions

func Decode

func Decode(ref string) (validity, n uint32)

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

func Encode(validity, n uint32) string

Encode is the server_ref of UID n under validity, or a folder cursor whose last seen UID is n.

func Roles

func Roles(list []*imap.ListData) []backend.Role

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

func Selectable(d *imap.ListData) bool

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 New

func New(cfg Config) *Receiver

New is a Receiver on the account cfg reaches.

func (*Receiver) Apply

func (r *Receiver) Apply(ctx context.Context, op backend.Op) (_ backend.Result, err error)

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

func (r *Receiver) Check(ctx context.Context) (_ backend.CheckResult, err error)

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

func (r *Receiver) Close() error

Close closes the connection; a second Close is harmless.

func (*Receiver) Describe

func (r *Receiver) Describe(ctx context.Context) (backend.Description, error)

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.

func (*Receiver) Watch

func (r *Receiver) Watch(ctx context.Context, wake func(folders []backend.FolderRef)) (err error)

Watch selects INBOX and IDLEs on the session's connection, waking with INBOX at each change the server reports. It wakes once, with nil, as soon as INBOX is selected: a sync after that wake misses nothing. When ctx ends it returns with IDLE still running; Close ends it.

Jump to

Keyboard shortcuts

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