mailsync

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoadStateFunc

type LoadStateFunc func(ctx context.Context, name string) (*State, error)

LoadStateFunc is the function definition of LoadState in the Store interface.

type Manager

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

Manager manages mail syncers and persists their state in a store.

func NewManager

func NewManager(ctx context.Context, store Store) (*Manager, error)

NewManagerreturns a new mailsync manager that uses the given MongoDB client and database.

func (*Manager) NewSyncer

func (mng *Manager) NewSyncer(ctx context.Context, name string, interval time.Duration, cfg *mailbox.Config) (*Syncer, error)

NewSyncer returns a new.

type MessageHandler

type MessageHandler interface {
	HandleMail(ctx context.Context, mail *mailbox.EMail)
}

MessageHandler is called for each new E-Mail that has been received by the watched mailbox.

type MessageHandlerFunc

type MessageHandlerFunc func(context.Context, *mailbox.EMail)

MessageHandlerFunc is a convenience type for implementing MessageHandler.

func (MessageHandlerFunc) HandleMail

func (fn MessageHandlerFunc) HandleMail(ctx context.Context, mail *mailbox.EMail)

HandleMail implements MessageHandler.

type SaveStateFunc

type SaveStateFunc func(ctx context.Context, state State) error

SaveStateFunc is the function definition of SaveState in the Store interface.

type SimpleStore

type SimpleStore struct {
	Load LoadStateFunc
	Save SaveStateFunc
}

SimpleStore is a convenience struct for implementing Store with anonymous functions.

func (*SimpleStore) LoadState

func (s *SimpleStore) LoadState(ctx context.Context, name string) (*State, error)

LoadState implements Store.LoadState.

func (*SimpleStore) SaveState

func (s *SimpleStore) SaveState(ctx context.Context, state State) error

SaveState implements Store.SaveState.

type State

type State struct {
	// ID is the MongoDB object ID.
	ID primitive.ObjectID `bson:"_id,omitempty"`
	// Name is the name of the mail syncer the
	// state belongs to.
	Name string `bson:"name,omitempty"`
	// UIDValidtity is the last UIDVALIDITY value
	// seen.
	UIDValidity uint32 `bson:"uidValidity,omitempty"`
	// LastUIDFetched is the last mail UID that has
	// been fetched.
	// Only valid if UIDValidity is still unchanged.
	LastUIDFetched uint32 `bson:"lastUidFetched,omitempty"`
}

State is the state of a mail syncer.

type Store

type Store interface {
	// LoadState should return the state stored under name. If no state
	// is stored LoadState should return a nil state and a nil error.
	// In case of an error LoadState should return a non-nil error.
	LoadState(ctx context.Context, name string) (*State, error)

	// SaveState should store state and make it retrievable by it's name.
	// It should return a non-nil error if the state cannot be stored
	// for whatever reason.
	SaveState(ctx context.Context, state State) error
}

Store stores the state of individual mail syncers.

type Syncer

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

Syncer syncs mails with mongodb.

func (*Syncer) OnMessage

func (sync *Syncer) OnMessage(handler MessageHandler)

OnMessage configures the message handler.

func (*Syncer) Start

func (sync *Syncer) Start() error

Start starts the syncer.

func (*Syncer) Stop

func (sync *Syncer) Stop() error

Stop stops the syncer.

Jump to

Keyboard shortcuts

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