mailsync

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package mailsync pulls folders and messages from IMAP into the store.

Index

Constants

View Source
const MaxAttempts = 5

MaxAttempts is how many times an op is sent before it is marked failed.

Variables

View Source
var BackfillPage = 1000

BackfillPage is how many messages one FETCH of a range backfill asks for, which bounds its memory. Tests lower it.

View Source
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.

View Source
var BeforeFlagsWrite func()

BeforeFlagsWrite, when set, runs between syncFlags reading the local flags and writing the server's. Tests only.

View Source
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.

View Source
var OlderPage = 200

OlderPage is how many messages one FetchOlder imports. Tests lower it.

View Source
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.

View Source
var PurgeRoles = []string{"junk", "trash"}

PurgeRoles are the roles a purge can empty.

View Source
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).

View Source
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

func PushNewOps(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64) error

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

func PushOps(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64) 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; 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

func QueuePurge(ctx context.Context, db *store.DB, c *imapclient.Client, accountID int64) error

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.

type OpsError

type OpsError struct {
	Problems []string
	Changed  []int64
}

OpsError lists ops that PushOps marked conflict or failed; the push went on. Changed holds messages shown in a different folder because a move ended so.

func (*OpsError) Error

func (e *OpsError) Error() string

Jump to

Keyboard shortcuts

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