Documentation
¶
Overview ¶
Package mailsync pulls folders and messages from IMAP into the store.
Index ¶
- Constants
- Variables
- func CountFolders(c *imapclient.Client) (int, error)
- func Fetch(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64, ...) (more bool, err error)
- func FetchOlder(ctx context.Context, db *store.DB, c *imapclient.Client, ...) (more bool, err error)
- func Idle(ctx context.Context, c *imapclient.Client, updates, wake <-chan struct{}, ...) error
- func PushNewOps(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64) error
- func PushOps(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64) error
- func QueuePurge(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64) error
- func RoleFolder(ctx context.Context, db *store.DB, accountID int64, role string) (id int64, name string, err error)
- func SentFolder(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64) (string, error)
- type FlagsPayload
- type OpsError
Constants ¶
const MaxAttempts = 5
MaxAttempts is how many times an op is sent before it is marked failed.
Variables ¶
var BackfillPage = 1000
BackfillPage is how many messages one FETCH of a range backfill asks for, which bounds its memory. Tests lower it.
var BackfillPages = 2
BackfillPages is how many pages a range backfill takes per sync round before it yields, so new mail, ops and SyncNow wait at most that long; the next round goes on. Tests lower it.
var BeforeFlagsWrite func()
BeforeFlagsWrite, when set, runs between syncFlags reading the local flags and writing the server's. Tests only.
var ErrNotSynced = errors.New("folder not synced yet")
ErrNotSynced is FetchOlder on a folder whose first sync (at the server's UIDVALIDITY) has not completed: the next sync, not a page, fills it.
var OlderPage = 200
OlderPage is how many messages one FetchOlder imports. Tests lower it.
var PartFetchBytes int64 = 3 * mail.MaxBodyBytes
PartFetchBytes is how much of one text part a sync downloads: enough encoded bytes for mail.MaxBodyBytes of text even in quoted-printable. Tests lower it.
var PurgeRoles = []string{"junk", "trash"}
PurgeRoles are the roles a purge can empty.
var PurgeStep func(step string)
PurgeStep, when set (tests only), runs at each step of a purge's push: "selected", then "stored" (\Deleted set, UID EXPUNGE not sent yet).
var Roles = []string{"drafts", "sent", "junk", "trash", "archive"}
Roles are the roles a user can give a folder (folders.role_override).
Functions ¶
func CountFolders ¶
func CountFolders(c *imapclient.Client) (int, error)
CountFolders is how many selectable folders LIST returns: those a sync mirrors.
func Fetch ¶
func Fetch(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64, bus *events.Bus) (more bool, err error)
Fetch syncs every folder of the account over c: folder list, new messages (headers and text parts only; attachments stay lazy), threading, remote flag changes and expunges. Rows committed before an error are still announced. more reports that a range backfill used its pages for the round and has work left: the caller should sync again soon.
func FetchOlder ¶
func FetchOlder(ctx context.Context, db *store.DB, c *imapclient.Client, accountID, folderID int64, bus *events.Bus) (more bool, err error)
FetchOlder imports one page of the folder's mail that the sync range left out: the newest server UIDs up to last_uid that the folder does not store. It keeps what it imports; the range's backfill and filled_since only ever add what is missing, so the next sync neither refetches nor deletes it. more reports whether the server holds still more the folder lacks.
func Idle ¶
func Idle(ctx context.Context, c *imapclient.Client, updates, wake <-chan struct{}, max time.Duration) error
Idle waits on c, which has INBOX selected, until the server reports a change (a signal on updates), wake fires, max passes or ctx ends. A NOOP first collects changes the server queued since SELECT, so mail that arrived before IDLE began still ends the wait. When ctx ends the caller closes c, which also stops IDLE.
func PushNewOps ¶
PushNewOps is PushOps limited to ops never attempted, for a second round after a fetch claimed moves: ops that were waiting run, ones that failed are not retried.
func PushOps ¶
PushOps sends the account's pending ops to the server in id order. Ops whose message has no server location yet, or whose dependency is still pending or awaiting its claim, wait for a later round; once the dependency failed or conflicted the op is re-based (depends_on cleared) and runs from the message's current server location. Problems with single ops come back as *OpsError; any other error means the connection is unusable and the push stopped.
func QueuePurge ¶
QueuePurge queues the account's due junk and trash purges as purge ops, which PushOps expunges after checking again. A folder is purged at most once a day, and only on a server with UIDPLUS: a plain EXPUNGE would also remove mail other clients marked \Deleted. When the role's folder is not the one the policy's clock ran for, the clock restarts there and nothing is purged.
func RoleFolder ¶
func RoleFolder(ctx context.Context, db *store.DB, accountID int64, role string) (id int64, name string, err error)
RoleFolder is the account's folder of role, the one place roles resolve: the folder the user gave the role, else the lowest id detected with it, unless the user gave that folder another role or none. 0 when there is none.
func SentFolder ¶
func SentFolder(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64) (string, error)
SentFolder returns the name of the account's Sent folder (RoleFolder), or "" when it has none. Before the first sync stored any folder, it is found from LIST the way sync assigns roles.
Types ¶
type FlagsPayload ¶
type FlagsPayload struct {
Add []string `json:"add,omitempty"`
Remove []string `json:"remove,omitempty"`
}
FlagsPayload is the payload of a flags op: flags to add, then flags to remove.