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 ¶
- func LeastUsedColor(mailboxes []Mailbox) string
- type EMLProvider
- func (p *EMLProvider) CreateMailbox(mailbox Mailbox) (Mailbox, error)
- func (p *EMLProvider) DefaultMailboxes(sourceMailbox Mailbox) []Mailbox
- func (p *EMLProvider) ID() string
- func (p *EMLProvider) Mailboxes(includeEmpty, includeAllMail bool) (mailboxes []Mailbox, err error)
- func (p *EMLProvider) TransferFrom(rules transferRules, progress *Progress, ch <-chan Message)
- func (p *EMLProvider) TransferTo(rules transferRules, progress *Progress, ch chan<- Message)
- type ErrIMAPAuth
- type ErrIMAPAuthMethod
- type ErrIMAPConnection
- type IMAPClientProvider
- type IMAPProvider
- type LocalProvider
- type MBOXProvider
- func (p *MBOXProvider) CreateMailbox(mailbox Mailbox) (Mailbox, error)
- func (p *MBOXProvider) DefaultMailboxes(sourceMailbox Mailbox) []Mailbox
- func (p *MBOXProvider) ID() string
- func (p *MBOXProvider) Mailboxes(includeEmpty, includeAllMail bool) ([]Mailbox, error)
- func (p *MBOXProvider) TransferFrom(rules transferRules, progress *Progress, ch <-chan Message)
- func (p *MBOXProvider) TransferTo(rules transferRules, progress *Progress, ch chan<- Message)
- type Mailbox
- type Message
- type MessageStatus
- type MetricsManager
- type PMAPIProvider
- func (p *PMAPIProvider) CreateMailbox(mailbox Mailbox) (Mailbox, error)
- func (p *PMAPIProvider) DefaultMailboxes(_ Mailbox) []Mailbox
- func (p *PMAPIProvider) ID() string
- func (p *PMAPIProvider) Mailboxes(includeEmpty, includeAllMail bool) ([]Mailbox, error)
- func (p *PMAPIProvider) SetConnectionDown()
- func (p *PMAPIProvider) SetConnectionUp()
- func (p *PMAPIProvider) TransferFrom(rules transferRules, progress *Progress, ch <-chan Message)
- func (p *PMAPIProvider) TransferTo(rules transferRules, progress *Progress, ch chan<- Message)
- type PanicHandler
- type Progress
- func (p *Progress) FileReport() string
- func (p *Progress) GenerateBugReport() []byte
- func (p *Progress) GetCounts() ProgressCounts
- func (p *Progress) GetFailedMessages() []*MessageStatus
- func (p *Progress) GetFatalError() error
- func (p *Progress) GetUpdateChannel() chan struct{}
- func (p *Progress) IsPaused() bool
- func (p *Progress) IsStopped() bool
- func (p *Progress) Pause(reason string)
- func (p *Progress) PauseReason() string
- func (p *Progress) Resume()
- func (p *Progress) Stop()
- type ProgressCounts
- type Provider
- type Rule
- type SourceProvider
- type TargetProvider
- type Transfer
- func (t *Transfer) ChangeTarget(target TargetProvider)
- func (t *Transfer) CreateTargetMailbox(mailbox Mailbox) (Mailbox, error)
- func (t *Transfer) GetRule(sourceMailbox Mailbox) *Rule
- func (t *Transfer) GetRules() []*Rule
- func (t *Transfer) ResetRules()
- func (t *Transfer) SetGlobalMailbox(mailbox *Mailbox)
- func (t *Transfer) SetGlobalTimeLimit(fromTime, toTime int64)
- func (t *Transfer) SetRule(sourceMailbox Mailbox, targetMailboxes []Mailbox, fromTime, toTime int64) error
- func (t *Transfer) SetSkipEncryptedMessages(skip bool)
- func (t *Transfer) SourceMailboxes() (m []Mailbox, err error)
- func (t *Transfer) Start() *Progress
- func (t *Transfer) TargetMailboxes() (m []Mailbox, err error)
- func (t *Transfer) UnsetRule(sourceMailbox Mailbox)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LeastUsedColor ¶
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) Is ¶
func (e ErrIMAPAuth) Is(target error) bool
type ErrIMAPAuthMethod ¶
type ErrIMAPAuthMethod struct {
// contains filtered or unexported fields
}
ErrIMAPAuthMethod is error representing wrong auth method.
func (ErrIMAPAuthMethod) Is ¶
func (e ErrIMAPAuthMethod) Is(target error) bool
type ErrIMAPConnection ¶
type ErrIMAPConnection struct {
// contains filtered or unexported fields
}
ErrIMAPConnection is error representing connection issues.
func (ErrIMAPConnection) Is ¶
func (e ErrIMAPConnection) Is(target error) bool
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 ¶
Mailbox is universal data holder of mailbox details for every provider.
func (Mailbox) IsSystemFolder ¶
IsSystemFolder returns true when ID corresponds to PM system folder.
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 ¶
FileReport returns path to generated defailed file report.
func (*Progress) GenerateBugReport ¶
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 ¶
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) PauseReason ¶
PauseReason returns pause reason.
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) HasTimeLimit ¶
HasTimeLimit returns whether rule defines time limit.
func (*Rule) TargetMailboxNames ¶
TargetMailboxNames returns array of target mailbox names.
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 ¶
CreateTargetMailbox creates mailbox in target provider.
func (*Transfer) SetGlobalMailbox ¶
SetGlobalMailbox sets mailbox that is applied to every message in the import phase.
func (*Transfer) SetGlobalTimeLimit ¶
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 ¶
SetSkipEncryptedMessages sets whether message which cannot be decrypted should be imported/exported or skipped.
func (*Transfer) SourceMailboxes ¶
SourceMailboxes returns mailboxes available at source side.
func (*Transfer) TargetMailboxes ¶
TargetMailboxes returns mailboxes available at target side.
Source Files ¶
- mailbox.go
- message.go
- progress.go
- progress_counts.go
- provider.go
- provider_eml.go
- provider_eml_source.go
- provider_eml_target.go
- provider_imap.go
- provider_imap_errors.go
- provider_imap_source.go
- provider_imap_utils.go
- provider_local.go
- provider_local_source.go
- provider_mbox.go
- provider_mbox_gmail_labels.go
- provider_mbox_source.go
- provider_mbox_target.go
- provider_pmapi.go
- provider_pmapi_source.go
- provider_pmapi_target.go
- provider_pmapi_utils.go
- report.go
- rules.go
- timeit.go
- transfer.go
- types.go
- utils.go