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 ¶
- func Clean(c api.CollectionCheck) bool
- func ContactIndexOf(card *vcardx.Card) store.ContactIndex
- func EventRow(e calendar.Event) store.EventRow
- func Instances(events []store.EventRow, local *time.Location, from, to time.Time) ([]store.InstanceRow, error)
- func Scope(name string) (calendar.Scope, bool)
- func StoreCalendarObject(ctx context.Context, tx *store.Tx, o store.Object, opts calendar.Options, ...) (int64, error)
- func Window(now time.Time) (from, to time.Time)
- type Config
- type ContactPayload
- type EventEdit
- type EventPayload
- type Manager
- func (m *Manager) Discover(ctx context.Context, accountID int64, service api.ServiceKind, start string) (string, error)
- func (m *Manager) Kick(accountID int64)
- func (m *Manager) Pass(ctx context.Context, accountID int64) error
- func (m *Manager) Poll(accountID int64, force bool)
- func (m *Manager) Reload(ctx context.Context) error
- func (m *Manager) Start(ctx context.Context) error
- func (m *Manager) UseServerDefaultCalendar(ctx context.Context, accountID int64) error
- func (m *Manager) Verify(ctx context.Context, accountID int64) ([]api.CollectionCheck, error)
- func (m *Manager) Wait()
- type TokenSource
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 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 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.
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) 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 ¶
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 (*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) Pass ¶
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 ¶
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 ¶
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) UseServerDefaultCalendar ¶
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 ¶
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.