pimsync

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 31 Imported by: 0 modules, 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 pimsync keeps each account's address books, calendars and task lists in step with its servers (docs/design/pim.md, ADR-0017): one loop per account with a service on, beside mail's actor and independent of it, polling every 5 minutes, at once on request and after a local change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(c api.CollectionCheck) bool

Clean reports whether a check found no difference.

func ContactIndexOf

func ContactIndexOf(card *vcardx.Card) store.ContactIndex

ContactIndexOf is the index of a parsed vCard, as sync and the people API's writes store it.

func EventRow

func EventRow(e calendar.Event) store.EventRow

EventRow is a parsed event as the events store keeps it.

func Instances

func Instances(events []store.EventRow, local *time.Location, from, to time.Time) ([]store.InstanceRow, error)

Instances expands one object's stored events over [from, to).

func Scope

func Scope(name string) (calendar.Scope, bool)

Scope is an EventEdit's scope as calendar takes it.

func StoreCalendarObject

func StoreCalendarObject(ctx context.Context, tx *store.Tx, o store.Object, opts calendar.Options, from, to time.Time) (int64, error)

StoreCalendarObject stores a calendar object as sent and indexes its events, expanding them over [from, to) (the instances window), in tx: what a pass does with each object it fetches. It returns the object's ID.

func Window

func Window(now time.Time) (from, to time.Time)

Window returns the UTC day's instances window: 365 days back and 730 ahead.

Types

type Config

type Config struct {
	Interval time.Duration // between passes [5m]
	// MinGap is how recently a pass may have ended for Poll without force
	// to skip the account [1m].
	MinGap time.Duration
	Batch  int // hrefs per multiget [100]
	// HTTP sends DAV and Tasks requests; nil uses davx's default.
	HTTP *http.Client
	// AllowHTTP permits plain http:// servers, for local test servers only
	// (FROSTMAIL_INSECURE_TLS=1).
	AllowHTTP bool
	// Tokens gives OAuth accounts their access tokens (oauth.Manager); nil
	// leaves OAuth accounts unable to sign in.
	Tokens TokenSource
	// UserAgent is sent with every request.
	UserAgent string
	// Now is the clock that places the instances window; nil means
	// time.Now.
	Now func() time.Time
	// Local is the zone of floating event times; nil means time.Local.
	Local *time.Location
	// GraphURL replaces Microsoft Graph's URL, for test servers.
	GraphURL string
	// Activity, when set, records each service's pass and refused changes
	// (ADR-0055); nil records nothing.
	Activity *activity.Hub
}

Config tunes sync. Zero fields take the defaults in brackets.

type ContactPayload

type ContactPayload struct {
	Changes []vcardx.Fields     `json:"vcard,omitzero"`
	Base    map[string][]string `json:"base,omitzero"`
	Whole   bool                `json:"whole,omitzero"`
	// Name is a delete's contact, for the app should the server refuse it.
	Name string `json:"name,omitzero"`
}

ContactPayload is a contact edit's put payload (ADR-0030; docs/design/ pim.md, Editing): the changes in order and, by property, the lines the source had before the first one; or Whole, a source written whole (a restore), which cannot be applied again.

func ParseContactPayload

func ParseContactPayload(payload string) (ContactPayload, bool)

ParseContactPayload reads a put's payload; ok is false for a put that is no contact edit (a creation, a task, an answer).

func (ContactPayload) Apply

func (p ContactPayload) Apply(server []byte, now time.Time) ([]byte, error)

Apply makes the changes again, in order, on the server's source.

func (ContactPayload) Encode

func (p ContactPayload) Encode() (string, error)

Encode is the payload as stored.

func (ContactPayload) Extend

func (p ContactPayload) Extend(src []byte, f vcardx.Fields) (ContactPayload, error)

Extend adds a change made on src, recording the base of the properties it touches that no earlier change touched.

func (ContactPayload) Fits

func (p ContactPayload) Fits(server []byte) bool

Fits reports whether another client left every property the changes touch as it was: the server's lines equal the base.

type EventEdit

type EventEdit struct {
	RecurrenceID string               `json:"recurrenceId,omitzero"`
	Scope        string               `json:"scope,omitzero"` // this, future or all
	Change       calendar.EventChange `json:"change,omitzero"`
	NewUID       string               `json:"newUid,omitzero"` // a split's new series, written by an op of its own
	Delete       bool                 `json:"delete,omitzero"`
}

EventEdit is one change calendar.update or calendar.delete made to an event's object: a patch of the event (no RecurrenceID), or of one of a series' occurrences in a scope, or a delete of occurrences.

type EventPayload

type EventPayload struct {
	Edits   []EventEdit         `json:"event,omitzero"`
	Base    map[string][]string `json:"base,omitzero"`
	Whole   bool                `json:"whole,omitzero"`
	Summary string              `json:"summary,omitzero"`
	After   int64               `json:"after,omitzero"`
}

EventPayload is an event write's payload (ADR-0030; docs/design/pim.md, Editing). A put holds its edits in order and, by component and property, the lines the source had before the first one; or Whole, a source written whole (a restore), which cannot be applied again. A delete holds the event's summary, for calendar.refused, and, for a move, the put to the other calendar it waits for.

func ParseEventPayload

func ParseEventPayload(payload string) (EventPayload, bool)

ParseEventPayload reads a write's payload; ok is false for a put that is no edit (a creation, an answer).

func (EventPayload) Apply

func (p EventPayload) Apply(server []byte, now time.Time) ([]byte, error)

Apply makes the edits again, in order, on the server's source. A split's new series is its own op, so only the old one is kept here.

func (EventPayload) Encode

func (p EventPayload) Encode() (string, error)

Encode is the payload as stored.

func (EventPayload) Extend

func (p EventPayload) Extend(src []byte, e EventEdit) (EventPayload, error)

Extend adds an edit made on src, recording the base of what it touches that no earlier edit touched: for an event, the properties it rewrites; for a series, those and its shape in every VEVENT, and which VEVENTs the object has.

func (EventPayload) Fits

func (p EventPayload) Fits(server []byte) bool

Fits reports whether another client left everything the edits touch as it was: the server's lines equal the base.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager runs one loop per account with a service on.

func New

func New(db *store.DB, sec secrets.Store, log *slog.Logger, cfg Config) *Manager

New returns a Manager.

func (*Manager) Discover

func (m *Manager) Discover(ctx context.Context, accountID int64, service api.ServiceKind, start string) (string, error)

Discover finds the home set of a service for an account from start (a provider's URL, the user's, or one SRV records gave), signing in as the account does. maild calls it when a service is turned on.

func (*Manager) Kick

func (m *Manager) Kick(accountID int64)

Kick tells an account's loop that changes are queued (pim_ops).

func (*Manager) Pass

func (m *Manager) Pass(ctx context.Context, accountID int64) error

Pass runs one pass of an account's services now and returns the first error; passes of one account never overlap. The loops call it; tests call it directly.

func (*Manager) Poll

func (m *Manager) Poll(accountID int64, force bool)

Poll asks for a pass now: of one account, or of every account when accountID is 0. Without force it skips accounts whose last pass ended within Config.MinGap, as the app's focus polls do.

func (*Manager) Reload

func (m *Manager) Reload(ctx context.Context) error

Reload starts loops for accounts that gained a service and stops those of accounts that have none left; running loops pass again at once, since a service or its URL may have changed.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start runs a loop for every account with a service on until ctx ends.

func (*Manager) UseServerDefaultCalendar

func (m *Manager) UseServerDefaultCalendar(ctx context.Context, accountID int64) error

UseServerDefaultCalendar asks the account's calendar server for the user's default calendar (RFC 6638's schedule-default-calendar-URL) and makes it the default of the account's calendars, unless the user chose one. A server that names none, or names one not synced here, changes nothing.

func (*Manager) Verify

func (m *Manager) Verify(ctx context.Context, accountID int64) ([]api.CollectionCheck, error)

Verify compares each enabled collection of an account's services with the server, changing nothing (docs/design/pim.md, Operational notes). Objects with changes waiting to be written are left out of ETag and missing-on-server checks. DAV services without a home set are skipped; Google Tasks checks the task lists already discovered by a pass.

func (*Manager) Wait

func (m *Manager) Wait()

Wait blocks until every loop has stopped after the Start context ended.

type TokenSource

type TokenSource interface {
	AccessToken(ctx context.Context, accountID int64) (string, error)
	// Invalidate drops a token the server refused.
	Invalidate(accountID int64)
}

TokenSource gives OAuth access tokens.

Jump to

Keyboard shortcuts

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