Documentation
¶
Overview ¶
Package mailsync stores what an account's protocol backend reports (ADR 0037): folders, server locations, claims, orphans, merges and threads.
Index ¶
- Constants
- Variables
- func AltRole(role string) string
- func DeleteLocal(ctx context.Context, db *store.DB, accountID int64, ids []int64) (hashes []string, tids []int64, err error)
- func Fetch(ctx context.Context, db *store.DB, recv backend.Receiver, accountID int64, ...) (more bool, err error)
- func FetchOlder(ctx context.Context, db *store.DB, recv backend.Receiver, ...) (more bool, err error)
- func NextOpDue(ctx context.Context, db *store.DB, accountID int64, t time.Time) (time.Time, error)
- func PurgeNowRole(role string, due time.Time) string
- func PushNewOps(ctx context.Context, db *store.DB, recv backend.Receiver, accountID int64, ...) error
- func PushOps(ctx context.Context, db *store.DB, recv backend.Receiver, accountID int64, ...) error
- func QueuePurge(ctx context.Context, db *store.DB, recv backend.Receiver, 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, accountID int64) (ref backend.FolderRef, known bool, err error)
- func ShowIn(msg, folder int64, out []int64) []sqlite.Statement
- func Sync(ctx context.Context, db *store.DB, recv backend.Receiver, accountID int64, ...) (more bool, err error)
- type FlagsPayload
- type Local
- 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 page of a sync 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 applySnapshot reading the local flags and writing the server's. Tests only.
var ErrNotSynced = backend.ErrNotSynced
ErrNotSynced is FetchOlder on a folder whose first sync (at the server's current state) 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 Confirm of a purge's push: "selected", then "stored" (on IMAP: \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 AltRole ¶ added in v1.5.0
AltRole is the detected role that stands in for role when no folder is detected with it: Gmail's All Mail for archive. Else role itself.
func DeleteLocal ¶ added in v1.31.0
func DeleteLocal(ctx context.Context, db *store.DB, accountID int64, ids []int64) (hashes []string, tids []int64, err error)
DeleteLocal deletes the local archive's messages ids for good (ADR 0036) and returns the content hashes of their originals, for the caller to remove, and the threads they were in.
func Fetch ¶
func Fetch(ctx context.Context, db *store.DB, recv backend.Receiver, accountID int64, bus *events.Bus, only []backend.FolderRef) (more bool, err error)
Fetch syncs the folders of the account in only (nil: every folder) through recv, then, after a round of every folder, refreshes the Authentication-Results of cached messages. more reports that a backfill has work left: the caller should sync again soon.
func FetchOlder ¶
func FetchOlder(ctx context.Context, db *store.DB, recv backend.Receiver, 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, through recv. It keeps what it imports; the range's backfill only ever adds what is missing, so the next sync neither refetches nor deletes it. more reports whether the server holds still more the folder lacks.
func NextOpDue ¶ added in v1.30.0
NextOpDue is the account's first undo deadline after t; zero for none.
func PurgeNowRole ¶ added in v1.21.0
PurgeNowRole is the payload of a purge op the user asked for: it expunges the message from the role's folder (trash, junk) at due, whatever the policy.
func PushNewOps ¶
func PushNewOps(ctx context.Context, db *store.DB, recv backend.Receiver, accountID int64, now time.Time) error
PushNewOps is PushOps limited to ops never attempted, for a second round after a fetch: ops that waited for a claim (an Unlocated move), for another server location (a deferred archive) or that were queued meanwhile run, ones that failed are not retried. Without such an op it sends nothing to the server.
func PushOps ¶
func PushOps(ctx context.Context, db *store.DB, recv backend.Receiver, accountID int64, now time.Time) error
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, as do purges whose undo window is still open at now; once the dependency failed or conflicted the op is re-based (depends_on cleared) and runs from the message's current server location. The backend is asked only when an op is ready. 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 whose backend declares the purge feature (IMAP's needs 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. Without an archive detected, Gmail's All Mail is it: archiving there takes mail out of the inbox. 0 when there is none.
func SentFolder ¶
func SentFolder(ctx context.Context, db *store.DB, accountID int64) (ref backend.FolderRef, known bool, err error)
SentFolder returns the account's Sent folder (RoleFolder) on the server, or "" when it has none there. known is false before a sync stored any folder: whether it has one is not known yet.
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.
type Local ¶ added in v1.31.0
type Local struct {
ID, ThreadID int64
Merged []int64 // threads merged into ThreadID
Moved []int64 // their messages
}
Local is a message InsertLocal stored, and the threads it merged.
func InsertLocal ¶ added in v1.31.0
func InsertLocal(ctx context.Context, db *store.DB, accountID, folderID int64, p *mail.Parsed, size int64, hash string) (Local, error)
InsertLocal stores p, a local archive's message whose original file hashes to hash, in folderID with no server location (ADR 0036): its thread, attachment list, full-text index and security verdict, as importMessage does. It is old mail: read, with no receive event, and already labeled and scanned, so neither the AI labeler nor the security scanner takes it.