transfer

package
v1.8.12 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Overview

Package transfer provides tools to export messages from one provider and import them to another provider. Provider can be EML, MBOX, IMAP or PMAPI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LeastUsedColor

func LeastUsedColor(mailboxes []Mailbox) string

LeastUsedColor is intended to return color for creating a new inbox or label.

Types

type EMLProvider

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

EMLProvider implements import and export to/from EML file structure.

func NewEMLProvider

func NewEMLProvider(root string) *EMLProvider

NewEMLProvider creates EMLProvider.

func (*EMLProvider) CreateMailbox

func (p *EMLProvider) CreateMailbox(mailbox Mailbox) (Mailbox, error)

CreateMailbox does nothing. Folders are created dynamically during the import.

func (*EMLProvider) DefaultMailboxes

func (p *EMLProvider) DefaultMailboxes(sourceMailbox Mailbox) []Mailbox

DefaultMailboxes returns the default mailboxes for default rules if no other is found.

func (*EMLProvider) ID

func (p *EMLProvider) ID() string

ID is used for generating transfer ID by combining source and target ID. We want to keep the same rules for import from or export to local files no matter exact path, therefore it returns constant. The same as EML.

func (*EMLProvider) Mailboxes

func (p *EMLProvider) Mailboxes(includeEmpty, includeAllMail bool) (mailboxes []Mailbox, err error)

Mailboxes returns all available folder names from root of EML files. In case the same folder name is used more than once (for example root/a/foo and root/b/foo), it's treated as the same folder.

func (*EMLProvider) TransferFrom

func (p *EMLProvider) TransferFrom(rules transferRules, progress *Progress, ch <-chan Message)

TransferFrom imports messages from channel.

func (*EMLProvider) TransferTo

func (p *EMLProvider) TransferTo(rules transferRules, progress *Progress, ch chan<- Message)

TransferTo exports messages based on rules to channel.

type ErrIMAPAuth

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

ErrIMAPAuth is error representing authentication issues.

func (ErrIMAPAuth) Cause

func (e ErrIMAPAuth) Cause() error

func (ErrIMAPAuth) Error

func (e ErrIMAPAuth) Error() string

func (ErrIMAPAuth) Is

func (e ErrIMAPAuth) Is(target error) bool

func (ErrIMAPAuth) Unwrap

func (e ErrIMAPAuth) Unwrap() error

type ErrIMAPAuthMethod

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

ErrIMAPAuthMethod is error representing wrong auth method.

func (ErrIMAPAuthMethod) Cause

func (e ErrIMAPAuthMethod) Cause() error

func (ErrIMAPAuthMethod) Error

func (e ErrIMAPAuthMethod) Error() string

func (ErrIMAPAuthMethod) Is

func (e ErrIMAPAuthMethod) Is(target error) bool

func (ErrIMAPAuthMethod) Unwrap

func (e ErrIMAPAuthMethod) Unwrap() error

type ErrIMAPConnection

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

ErrIMAPConnection is error representing connection issues.

func (ErrIMAPConnection) Cause

func (e ErrIMAPConnection) Cause() error

func (ErrIMAPConnection) Error

func (e ErrIMAPConnection) Error() string

func (ErrIMAPConnection) Is

func (e ErrIMAPConnection) Is(target error) bool

func (ErrIMAPConnection) Unwrap

func (e ErrIMAPConnection) Unwrap() error

type IMAPClientProvider

type IMAPClientProvider interface {
	Capability() (map[string]bool, error)
	Support(capability string) (bool, error)
	State() imap.ConnState
	SupportAuth(mech string) (bool, error)
	Authenticate(auth sasl.Client) error
	Login(username, password string) error
	List(ref, name string, ch chan *imap.MailboxInfo) error
	Select(name string, readOnly bool) (*imap.MailboxStatus, error)
	Fetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error
	UidFetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error
}

type IMAPProvider

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

IMAPProvider implements export from IMAP server.

func NewIMAPProvider

func NewIMAPProvider(username, password, host, port string) (*IMAPProvider, error)

NewIMAPProvider returns new IMAPProvider.

func (*IMAPProvider) ID

func (p *IMAPProvider) ID() string

ID is used for generating transfer ID by combining source and target ID. We want to keep the same rules for import from any IMAP server, therefore it returns constant.

func (*IMAPProvider) Mailboxes

func (p *IMAPProvider) Mailboxes(includeEmpty, includeAllMail bool) ([]Mailbox, error)

Mailboxes returns all available folder names from root of EML files. In case the same folder name is used more than once (for example root/a/foo and root/b/foo), it's treated as the same folder.

func (*IMAPProvider) TransferTo

func (p *IMAPProvider) TransferTo(rules transferRules, progress *Progress, ch chan<- Message)

TransferTo exports messages based on rules to channel.

type LocalProvider

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

LocalProvider implements import from local EML and MBOX file structure.

func NewLocalProvider

func NewLocalProvider(root string) *LocalProvider

func (*LocalProvider) ID

func (p *LocalProvider) ID() string

ID is used for generating transfer ID by combining source and target ID. We want to keep the same rules for import from or export to local files no matter exact path, therefore it returns constant. The same as EML and MBOX.

func (*LocalProvider) Mailboxes

func (p *LocalProvider) Mailboxes(includeEmpty, includeAllMail bool) ([]Mailbox, error)

Mailboxes returns all available folder names from root of EML and MBOX files.

func (*LocalProvider) TransferTo

func (p *LocalProvider) TransferTo(rules transferRules, progress *Progress, ch chan<- Message)

TransferTo exports messages based on rules to channel.

type MBOXProvider

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

MBOXProvider implements import and export to/from MBOX structure.

func NewMBOXProvider

func NewMBOXProvider(root string) *MBOXProvider

func (*MBOXProvider) CreateMailbox

func (p *MBOXProvider) CreateMailbox(mailbox Mailbox) (Mailbox, error)

CreateMailbox does nothing. Files are created dynamically during the import.

func (*MBOXProvider) DefaultMailboxes

func (p *MBOXProvider) DefaultMailboxes(sourceMailbox Mailbox) []Mailbox

DefaultMailboxes returns the default mailboxes for default rules if no other is found.

func (*MBOXProvider) ID

func (p *MBOXProvider) ID() string

ID is used for generating transfer ID by combining source and target ID. We want to keep the same rules for import from or export to local files no matter exact path, therefore it returns constant. The same as EML.

func (*MBOXProvider) Mailboxes

func (p *MBOXProvider) Mailboxes(includeEmpty, includeAllMail bool) ([]Mailbox, error)

Mailboxes returns all available folder names from root of EML files. In case the same folder name is used more than once (for example root/a/foo and root/b/foo), it's treated as the same folder.

func (*MBOXProvider) TransferFrom

func (p *MBOXProvider) TransferFrom(rules transferRules, progress *Progress, ch <-chan Message)

TransferFrom imports messages from channel.

func (*MBOXProvider) TransferTo

func (p *MBOXProvider) TransferTo(rules transferRules, progress *Progress, ch chan<- Message)

TransferTo exports messages based on rules to channel.

type Mailbox

type Mailbox struct {
	ID          string
	Name        string
	Color       string
	IsExclusive bool
}

Mailbox is universal data holder of mailbox details for every provider.

func (Mailbox) Hash

func (m Mailbox) Hash() string

Hash returns unique identifier to be used for matching.

func (Mailbox) IsSystemFolder

func (m Mailbox) IsSystemFolder() bool

IsSystemFolder returns true when ID corresponds to PM system folder.

type Message

type Message struct {
	ID      string
	Unread  bool
	Body    []byte
	Sources []Mailbox
	Targets []Mailbox
}

Message is data holder passed between import and export.

type MessageStatus

type MessageStatus struct {
	SourceID string // Message ID at the source.

	// Info about message displayed to user.
	// This is needed only for failed messages, but we cannot know in advance
	// which message will fail. We could clear it once the message passed
	// without any error. However, if we say one message takes about 100 bytes
	// in average, it's about 100 MB per million of messages, which is fine.
	Subject string
	From    string
	Time    time.Time
	// contains filtered or unexported fields
}

MessageStatus holds status for message used by progress manager.

func (*MessageStatus) GetErrorMessage

func (status *MessageStatus) GetErrorMessage() string

GetErrorMessage returns error message.

func (*MessageStatus) String

func (status *MessageStatus) String() string

type MetricsManager

type MetricsManager interface {
	Load(int)
	Start()
	Complete()
	Cancel()
	Fail()
}

type PMAPIProvider

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

PMAPIProvider implements import and export to/from ProtonMail server.

func NewPMAPIProvider

func NewPMAPIProvider(client pmapi.Client, userID, addressID string) (*PMAPIProvider, error)

NewPMAPIProvider returns new PMAPIProvider.

func (*PMAPIProvider) CreateMailbox

func (p *PMAPIProvider) CreateMailbox(mailbox Mailbox) (Mailbox, error)

CreateMailbox creates label in ProtonMail account.

func (*PMAPIProvider) DefaultMailboxes

func (p *PMAPIProvider) DefaultMailboxes(_ Mailbox) []Mailbox

DefaultMailboxes returns the default mailboxes for default rules if no other is found.

func (*PMAPIProvider) ID

func (p *PMAPIProvider) ID() string

ID returns identifier of current setup of PMAPI provider. Identification is unique per user.

func (*PMAPIProvider) Mailboxes

func (p *PMAPIProvider) Mailboxes(includeEmpty, includeAllMail bool) ([]Mailbox, error)

Mailboxes returns all available labels in ProtonMail account.

func (*PMAPIProvider) SetConnectionDown added in v1.8.0

func (p *PMAPIProvider) SetConnectionDown()

func (*PMAPIProvider) SetConnectionUp added in v1.8.0

func (p *PMAPIProvider) SetConnectionUp()

func (*PMAPIProvider) TransferFrom

func (p *PMAPIProvider) TransferFrom(rules transferRules, progress *Progress, ch <-chan Message)

TransferFrom imports messages from channel.

func (*PMAPIProvider) TransferTo

func (p *PMAPIProvider) TransferTo(rules transferRules, progress *Progress, ch chan<- Message)

TransferTo exports messages based on rules to channel.

type PanicHandler

type PanicHandler interface {
	HandlePanic()
}

type Progress

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

Progress maintains progress between import, export and user interface. Import and export update progress about processing messages and progress informs user interface, vice versa action (such as pause or resume) from user interface is passed down to import and export.

func (*Progress) FileReport

func (p *Progress) FileReport() string

FileReport returns path to generated defailed file report.

func (*Progress) GenerateBugReport

func (p *Progress) GenerateBugReport() []byte

GenerateBugReport generates similar file to import log except private information.

func (*Progress) GetCounts

func (p *Progress) GetCounts() ProgressCounts

GetCounts returns counts of exported and imported messages.

func (*Progress) GetFailedMessages

func (p *Progress) GetFailedMessages() []*MessageStatus

GetFailedMessages returns statuses of failed messages.

func (*Progress) GetFatalError

func (p *Progress) GetFatalError() error

GetFatalError returns fatal error (progress failed and did not finish).

func (*Progress) GetUpdateChannel

func (p *Progress) GetUpdateChannel() chan struct{}

GetUpdateChannel returns channel notifying any update from import or export.

func (*Progress) IsPaused

func (p *Progress) IsPaused() bool

IsPaused returns whether progress is paused.

func (*Progress) IsStopped

func (p *Progress) IsStopped() bool

IsStopped returns whether progress is stopped.

func (*Progress) Pause

func (p *Progress) Pause(reason string)

Pause pauses the progress.

func (*Progress) PauseReason

func (p *Progress) PauseReason() string

PauseReason returns pause reason.

func (*Progress) Resume

func (p *Progress) Resume()

Resume resumes the progress.

func (*Progress) Stop

func (p *Progress) Stop()

Stop stops the process.

type ProgressCounts

type ProgressCounts struct {
	Failed,
	Skipped,
	Imported,
	Exported,
	Added,
	Total uint
}

ProgressCounts holds counts counted by Progress.

func (*ProgressCounts) Progress

func (c *ProgressCounts) Progress() float32

Progress returns ratio between processed messages (fully imported, skipped and failed ones) and total number of messages as percentage (0 - 1).

type Provider

type Provider interface {
	// ID is used for generating transfer ID by combining source and target ID.
	ID() string

	// Mailboxes returns all available mailboxes.
	// Provider used as source returns only non-empty maibloxes.
	// Provider used as target does not return all mail maiblox.
	Mailboxes(includeEmpty, includeAllMail bool) ([]Mailbox, error)
}

Provider provides interface for common operation with provider.

type Rule

type Rule struct {
	Active          bool      `json:"active"`
	SourceMailbox   Mailbox   `json:"source"`
	TargetMailboxes []Mailbox `json:"targets"`
	FromTime        int64     `json:"from"`
	ToTime          int64     `json:"to"`
}

Rule is data holder of rule for one source mailbox used by `transferRules`.

func (*Rule) FromDate

func (r *Rule) FromDate() time.Time

FromDate returns time struct based on `FromTime`.

func (*Rule) HasTimeLimit

func (r *Rule) HasTimeLimit() bool

HasTimeLimit returns whether rule defines time limit.

func (*Rule) String

func (r *Rule) String() string

String returns textual representation for log purposes.

func (*Rule) TargetMailboxNames

func (r *Rule) TargetMailboxNames() (names []string)

TargetMailboxNames returns array of target mailbox names.

func (*Rule) ToDate

func (r *Rule) ToDate() time.Time

ToDate returns time struct based on `ToTime`.

type SourceProvider

type SourceProvider interface {
	Provider

	// TransferTo exports messages based on rules to channel.
	TransferTo(transferRules, *Progress, chan<- Message)
}

SourceProvider provides interface of provider with support of export.

type TargetProvider

type TargetProvider interface {
	Provider

	// DefaultMailboxes returns the default mailboxes for default rules if no other is found.
	DefaultMailboxes(sourceMailbox Mailbox) (targetMailboxes []Mailbox)

	// CreateMailbox creates new mailbox to be used as target in transfer rules.
	CreateMailbox(Mailbox) (Mailbox, error)

	// TransferFrom imports messages from channel.
	TransferFrom(transferRules, *Progress, <-chan Message)
}

TargetProvider provides interface of provider with support of import.

type Transfer

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

Transfer is facade on top of import rules, progress manager and source and target providers. This is the main object which should be used.

func New

func New(panicHandler PanicHandler, metrics MetricsManager, logDir, rulesDir string, source SourceProvider, target TargetProvider) (*Transfer, error)

New creates Transfer for specific source and target. Usage:

source := transfer.NewEMLProvider(...)
target := transfer.NewPMAPIProvider(...)
transfer.New(source, target, ...)

func (*Transfer) ChangeTarget

func (t *Transfer) ChangeTarget(target TargetProvider)

ChangeTarget changes the target. It is safe to change target for export, must not be changed for import. Do not set after you started transfer.

func (*Transfer) CreateTargetMailbox

func (t *Transfer) CreateTargetMailbox(mailbox Mailbox) (Mailbox, error)

CreateTargetMailbox creates mailbox in target provider.

func (*Transfer) GetRule

func (t *Transfer) GetRule(sourceMailbox Mailbox) *Rule

GetRule returns rule for given mailbox.

func (*Transfer) GetRules

func (t *Transfer) GetRules() []*Rule

GetRules returns all set transfer rules.

func (*Transfer) ResetRules

func (t *Transfer) ResetRules()

ResetRules unsets all rules.

func (*Transfer) SetGlobalMailbox

func (t *Transfer) SetGlobalMailbox(mailbox *Mailbox)

SetGlobalMailbox sets mailbox that is applied to every message in the import phase.

func (*Transfer) SetGlobalTimeLimit

func (t *Transfer) SetGlobalTimeLimit(fromTime, toTime int64)

SetGlobalTimeLimit sets time limit that is applied to rules without any specified time limit.

func (*Transfer) SetRule

func (t *Transfer) SetRule(sourceMailbox Mailbox, targetMailboxes []Mailbox, fromTime, toTime int64) error

SetRule sets sourceMailbox for transfer.

func (*Transfer) SetSkipEncryptedMessages

func (t *Transfer) SetSkipEncryptedMessages(skip bool)

SetSkipEncryptedMessages sets whether message which cannot be decrypted should be imported/exported or skipped.

func (*Transfer) SourceMailboxes

func (t *Transfer) SourceMailboxes() (m []Mailbox, err error)

SourceMailboxes returns mailboxes available at source side.

func (*Transfer) Start

func (t *Transfer) Start() *Progress

Start starts the transfer from source to target.

func (*Transfer) TargetMailboxes

func (t *Transfer) TargetMailboxes() (m []Mailbox, err error)

TargetMailboxes returns mailboxes available at target side.

func (*Transfer) UnsetRule

func (t *Transfer) UnsetRule(sourceMailbox Mailbox)

UnsetRule unsets sourceMailbox from transfer.

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