imapservice

package
v3.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-3.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const SyncFileVersion = 1

Variables

View Source
var ErrCacheNotAvailable = errors.New("cache no longer available")
View Source
var ErrInvalidSyncFileVersion = errors.New("invalid sync file version")

Functions

func BuildFlagSetFromMessageMetadata

func BuildFlagSetFromMessageMetadata(message proton.MessageMetadata) imap.FlagSet

func DeleteSyncState

func DeleteSyncState(configDir, userID string) error

func GetMailboxName

func GetMailboxName(label proton.Label) []string

func GetSyncConfigPath added in v3.5.2

func GetSyncConfigPath(path string, userID string) string

func MigrateVaultSettings

func MigrateVaultSettings(
	configDir, userID string,
	hasLabels, hasMessages bool,
	failedMessageIDs []string,
) (bool, error)

func WantLabel

func WantLabel(label proton.Label) bool

Types

type APIClient

type APIClient interface {
	CreateLabel(ctx context.Context, req proton.CreateLabelReq) (proton.Label, error)
	GetLabel(ctx context.Context, labelID string, labelTypes ...proton.LabelType) (proton.Label, error)
	UpdateLabel(ctx context.Context, labelID string, req proton.UpdateLabelReq) (proton.Label, error)
	DeleteLabel(ctx context.Context, labelID string) error
	LabelMessages(ctx context.Context, messageIDs []string, labelID string) error
	UnlabelMessages(ctx context.Context, messageIDs []string, labelID string) error
	GetLabels(ctx context.Context, labelTypes ...proton.LabelType) ([]proton.Label, error)

	GetGroupedMessageCount(ctx context.Context) ([]proton.MessageGroupCount, error)
	GetMessage(ctx context.Context, messageID string) (proton.Message, error)
	GetMessageMetadataPage(ctx context.Context, page, pageSize int, filter proton.MessageFilter) ([]proton.MessageMetadata, error)
	GetAllMessageIDs(ctx context.Context, afterID string) ([]string, error)
	CreateDraft(ctx context.Context, addrKR *crypto.KeyRing, req proton.CreateDraftReq) (proton.Message, error)
	UploadAttachment(ctx context.Context, addrKR *crypto.KeyRing, req proton.CreateAttachmentReq) (proton.Attachment, error)
	ImportMessages(ctx context.Context, addrKR *crypto.KeyRing, workers, buffer int, req ...proton.ImportReq) (stream.Stream[proton.ImportRes], error)
	GetFullMessage(ctx context.Context, messageID string, scheduler proton.Scheduler, storageProvider proton.AttachmentAllocator) (proton.FullMessage, error)
	GetAttachmentInto(ctx context.Context, attachmentID string, reader io.ReaderFrom) error
	GetAttachment(ctx context.Context, attachmentID string) ([]byte, error)
	DeleteMessage(ctx context.Context, messageIDs ...string) error
	MarkMessagesRead(ctx context.Context, messageIDs ...string) error
	MarkMessagesUnread(ctx context.Context, messageIDs ...string) error
	MarkMessagesForwarded(ctx context.Context, messageIDs ...string) error
	MarkMessagesUnForwarded(ctx context.Context, messageIDs ...string) error
}

type CacheAccessor

type CacheAccessor interface {
	connector.IMAPState
	Close()
}

type Connector

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

Connector contains all IMAP state required to satisfy sync and or imap queries.

func NewConnector

func NewConnector(
	addrID string,
	apiClient APIClient,
	labels sharedLabels,
	identityState sharedIdentity,
	addressMode usertypes.AddressMode,
	sendRecorder *sendrecorder.SendRecorder,
	panicHandler async.PanicHandler,
	telemetry Telemetry,
	showAllMail bool,
	syncState *SyncState,
) *Connector

func (*Connector) AddMessagesToMailbox

func (s *Connector) AddMessagesToMailbox(ctx context.Context, _ connector.IMAPStateWrite, messageIDs []imap.MessageID, mboxID imap.MailboxID) error

func (*Connector) Authorize

func (s *Connector) Authorize(ctx context.Context, username string, password []byte) bool

func (*Connector) Close

func (s *Connector) Close(_ context.Context) error

func (*Connector) CreateMailbox

func (s *Connector) CreateMailbox(ctx context.Context, _ connector.IMAPStateWrite, name []string) (imap.Mailbox, error)

func (*Connector) CreateMessage

func (s *Connector) CreateMessage(ctx context.Context, _ connector.IMAPStateWrite, mailboxID imap.MailboxID, literal []byte, flags imap.FlagSet, _ time.Time) (imap.Message, []byte, error)

func (*Connector) DeleteMailbox

func (s *Connector) DeleteMailbox(ctx context.Context, _ connector.IMAPStateWrite, mboxID imap.MailboxID) error

func (*Connector) GetMailboxVisibility

func (s *Connector) GetMailboxVisibility(_ context.Context, mboxID imap.MailboxID) imap.MailboxVisibility

func (*Connector) GetMessageLiteral

func (s *Connector) GetMessageLiteral(ctx context.Context, id imap.MessageID) ([]byte, error)

func (*Connector) GetUpdates

func (s *Connector) GetUpdates() <-chan imap.Update

func (*Connector) Init

func (s *Connector) Init(ctx context.Context, cache connector.IMAPState) error

func (*Connector) MarkMessagesFlagged

func (s *Connector) MarkMessagesFlagged(ctx context.Context, _ connector.IMAPStateWrite, messageIDs []imap.MessageID, flagged bool) error

func (*Connector) MarkMessagesForwarded added in v3.7.1

func (s *Connector) MarkMessagesForwarded(ctx context.Context, _ connector.IMAPStateWrite, messageIDs []imap.MessageID, flagged bool) error

func (*Connector) MarkMessagesSeen

func (s *Connector) MarkMessagesSeen(ctx context.Context, _ connector.IMAPStateWrite, messageIDs []imap.MessageID, seen bool) error

func (*Connector) MoveMessages

func (s *Connector) MoveMessages(ctx context.Context, _ connector.IMAPStateWrite, messageIDs []imap.MessageID, mboxFromID, mboxToID imap.MailboxID) (bool, error)

func (*Connector) RemoveMessagesFromMailbox

func (s *Connector) RemoveMessagesFromMailbox(ctx context.Context, _ connector.IMAPStateWrite, messageIDs []imap.MessageID, mboxID imap.MailboxID) error

func (*Connector) ShowAllMail

func (s *Connector) ShowAllMail(v bool)

func (*Connector) StateClose

func (s *Connector) StateClose()

func (*Connector) UpdateMailboxName

func (s *Connector) UpdateMailboxName(ctx context.Context, _ connector.IMAPStateWrite, mboxID imap.MailboxID, name []string) error

type EventProvider

type EventProvider interface {
	userevents.Subscribable
	RewindEventID(ctx context.Context, eventID string) error
}

type GluonIDProvider

type GluonIDProvider interface {
	GetGluonID(addrID string) (string, bool)
	GetGluonIDs() map[string]string
	SetGluonID(addrID, gluonID string) error
	RemoveGluonID(addrID, gluonID string) error
	GluonKey() []byte
}

type IMAPServerManager

type IMAPServerManager interface {
	AddIMAPUser(
		ctx context.Context,
		connector connector.Connector,
		addrID string,
		idProvider GluonIDProvider,
		syncStateProvider syncservice.StateProvider,
	) error

	RemoveIMAPUser(ctx context.Context, deleteData bool, provider GluonIDProvider, addrID ...string) error
}

type NullIMAPServerManager

type NullIMAPServerManager struct{}

func NewNullIMAPServerManager

func NewNullIMAPServerManager() *NullIMAPServerManager

func (NullIMAPServerManager) AddIMAPUser

func (NullIMAPServerManager) RemoveIMAPUser

func (n NullIMAPServerManager) RemoveIMAPUser(
	_ context.Context,
	_ bool,
	_ GluonIDProvider,
	_ ...string,
) error

type Service

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

func NewService

func NewService(
	client APIClient,
	identityState *useridentity.State,
	gluonIDProvider GluonIDProvider,
	eventProvider EventProvider,
	serverManager IMAPServerManager,
	eventPublisher events.EventPublisher,
	bridgePassProvider useridentity.BridgePassProvider,
	keyPassProvider useridentity.KeyPassProvider,
	panicHandler async.PanicHandler,
	sendRecorder *sendrecorder.SendRecorder,
	telemetry Telemetry,
	reporter reporter.Reporter,
	addressMode usertypes.AddressMode,
	subscription events.Subscription,
	syncConfigDir string,
	maxSyncMemory uint64,
	showAllMail bool,
) *Service

func (*Service) Close

func (s *Service) Close()

func (*Service) GetLabels

func (s *Service) GetLabels(ctx context.Context) (map[string]proton.Label, error)

func (*Service) GetSyncFailedMessageIDs

func (s *Service) GetSyncFailedMessageIDs(ctx context.Context) ([]string, error)

func (*Service) HandleAddressEvents

func (s *Service) HandleAddressEvents(ctx context.Context, events []proton.AddressEvent) error

func (*Service) HandleLabelEvents

func (s *Service) HandleLabelEvents(ctx context.Context, events []proton.LabelEvent) error

func (*Service) HandleMessageEvents

func (s *Service) HandleMessageEvents(ctx context.Context, events []proton.MessageEvent) error

func (*Service) HandleRefreshEvent

func (s *Service) HandleRefreshEvent(ctx context.Context, _ proton.RefreshFlag) error

func (*Service) HandleUserEvent

func (s *Service) HandleUserEvent(_ context.Context, user *proton.User) error

func (*Service) OnBadEvent

func (s *Service) OnBadEvent(ctx context.Context) error

func (*Service) OnBadEventResync

func (s *Service) OnBadEventResync(ctx context.Context) error

func (*Service) OnLogout

func (s *Service) OnLogout(ctx context.Context) error

func (*Service) Resync

func (s *Service) Resync(ctx context.Context) error

func (*Service) SetAddressMode

func (s *Service) SetAddressMode(ctx context.Context, mode usertypes.AddressMode) error

func (*Service) ShowAllMail

func (s *Service) ShowAllMail(ctx context.Context, v bool) error

func (*Service) Start

func (s *Service) Start(
	ctx context.Context,
	group *orderedtasks.OrderedCancelGroup,
	syncRegulator syncservice.Regulator,
	lastEventID string,
) error

type SharedCache

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

SharedCache is meant to protect access to the database and guarantee it's always valid. There may be some corner cases where the Gluon connector can get closed while we are processing events in parallel. If for some reason Gluon closes the database, the instance is invalidated and any attempts to access this state will return `ErrCacheNotAvailable`.

func NewSharedCached

func NewSharedCached() *SharedCache

func (*SharedCache) Acquire

func (s *SharedCache) Acquire() (CacheAccessor, error)

func (*SharedCache) Close

func (s *SharedCache) Close()

func (*SharedCache) Set

func (s *SharedCache) Set(cache connector.IMAPState)

type SyncMessageBuilder

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

func NewSyncMessageBuilder

func NewSyncMessageBuilder(rw *rwIdentity) *SyncMessageBuilder

func (SyncMessageBuilder) BuildMessage

func (s SyncMessageBuilder) BuildMessage(
	apiLabels map[string]proton.Label,
	full proton.FullMessage,
	addrKR *crypto.KeyRing,
	buffer *bytes.Buffer,
) (syncservice.BuildResult, error)

func (SyncMessageBuilder) WithKeys

func (s SyncMessageBuilder) WithKeys(f func(*crypto.KeyRing, map[string]*crypto.KeyRing) error) error

type SyncState

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

func NewSyncState

func NewSyncState(filePath string) (*SyncState, error)

func (*SyncState) AddFailedMessageID

func (s *SyncState) AddFailedMessageID(_ context.Context, ids ...string) error

func (*SyncState) ClearSyncStatus

func (s *SyncState) ClearSyncStatus(_ context.Context) error

func (*SyncState) GetSyncStatus

func (s *SyncState) GetSyncStatus(_ context.Context) (syncservice.Status, error)

func (*SyncState) RemFailedMessageID

func (s *SyncState) RemFailedMessageID(_ context.Context, ids ...string) error

func (*SyncState) SetHasLabels

func (s *SyncState) SetHasLabels(_ context.Context, b bool) error

func (*SyncState) SetHasMessages

func (s *SyncState) SetHasMessages(_ context.Context, b bool) error

func (*SyncState) SetLastMessageID

func (s *SyncState) SetLastMessageID(_ context.Context, s2 string, i int64) error

func (*SyncState) SetMessageCount

func (s *SyncState) SetMessageCount(_ context.Context, i int64) error

type SyncUpdateApplier

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

func NewSyncUpdateApplier

func NewSyncUpdateApplier() *SyncUpdateApplier

func (*SyncUpdateApplier) ApplySyncUpdates

func (s *SyncUpdateApplier) ApplySyncUpdates(ctx context.Context, updates []syncservice.BuildResult) error

func (*SyncUpdateApplier) Close

func (s *SyncUpdateApplier) Close()

func (*SyncUpdateApplier) SyncLabels

func (s *SyncUpdateApplier) SyncLabels(ctx context.Context, labels map[string]proton.Label) error

func (*SyncUpdateApplier) SyncSystemLabelsOnly

func (s *SyncUpdateApplier) SyncSystemLabelsOnly(ctx context.Context, labels map[string]proton.Label) error

type Telemetry

type Telemetry interface {
	useridentity.Telemetry
	SendConfigStatusSuccess(ctx context.Context)
	ReportConfigStatusFailure(errDetails string)
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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