copycat

package
v0.0.0-...-39666eb Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2014 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MemcacheServer = "localhost:11211"
	NoopMinutes    = 15
)

Variables

View Source
var ErrNotFound = errors.New("not found")

our own so we dont have to include leveldb elsewhere

View Source
var NotFound = errors.New("message not found")

Functions

func AddDeletedFlag

func AddDeletedFlag(conn *imap.Client, uid uint32) error

func AppendMessage

func AppendMessage(conn *imap.Client, messageData MessageData) error

func CheckAndAppendMessages

func CheckAndAppendMessages(dstConn *imap.Client, storeRequests chan WorkRequest, fetchRequests chan fetchRequest, wg *sync.WaitGroup)

checkAndStoreMessages will wait for WorkRequests to come acorss the pipe. When it receives a request, it will search the given destination inbox for the message. If it is not found, this method will attempt to pull the messages data from fetchRequests and then append it to the destination.

func GetAllMessages

func GetAllMessages(conn *imap.Client) (*imap.Command, error)

func GetConnection

func GetConnection(info InboxInfo, readOnly bool) (*imap.Client, error)

func Idle

func Idle(src *imap.Client, appendRequests []chan WorkRequest, requestPurge chan bool) (err error)

Idle setup the processes to wait for notifications from the IMAP source connection. If an EXISTS or EXPUNGE command comes across the pipe, the appropriate actions will be taken to update the destinations. If the process decides the inboxes are out of sync, it will pass a bool to the requestPurge channel. It is expected that the requestPurge channel is setup to initiate a purge process when it receives the notificaiton.

func ResetConnection

func ResetConnection(conn *imap.Client, readOnly bool) error

func SearchAndPurge

func SearchAndPurge(src []*imap.Client, dsts map[string][]*imap.Client) error

SearchAndPurge will go through the destination inboxes and check if each message exists in the source inbox. If a message does not exist in the source, delete it from the destination.

func SearchAndStore

func SearchAndStore(src []*imap.Client, dsts map[string][]*imap.Client, dbFile string, quickSyncCount int) (err error)

SearchAndStore will check check if each message in the source inbox exists in the destinations. If it doesn't exist in a destination, the message info will be pulled and stored into the destination.

func Sync

func Sync(src []*imap.Client, dsts map[string][]*imap.Client, runPurge bool, dbFile string, quickSyncCount int) (err error)

Sync will make sure that the dst inbox looks exactly like the src.

Types

type Cache

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

func NewCache

func NewCache(dbPath string) (*Cache, error)

func (*Cache) Close

func (c *Cache) Close()

func (*Cache) Get

func (c *Cache) Get(id string) (MessageData, error)

func (*Cache) Put

func (c *Cache) Put(id string, data MessageData) error

type Config

type Config struct {
	Source InboxInfo
	Dest   []InboxInfo
}

type CopyCat

type CopyCat struct {
	SyncConns       conns
	IdleAppendConns conns
	IdlePurgeConns  conns
	IdleConn        *imap.Client
}

CopyCat represents a process waiting to copy

func NewCopyCat

func NewCopyCat(src InboxInfo, dsts []InboxInfo, connsPerInbox int, sync bool, idle bool) (cat *CopyCat, err error)

NewCopyCat will create a new CopyCat instance that has all of its expected connections for syncing and idling.

func (*CopyCat) Close

func (c *CopyCat) Close()

func (*CopyCat) Idle

func (c *CopyCat) Idle(runSync bool, runPurge bool, dbFile string) (err error)

Idle will optionally sync the mailboxes, wait for updates from the imap server and update the destinations appropriately.

func (*CopyCat) Sync

func (c *CopyCat) Sync(runPurge bool, dbFile string, quickSyncCount int) error

Sync will make sure that the dst inbox looks exactly like the src.

type InboxInfo

type InboxInfo struct {
	User string
	Pw   string
	Host string
}

func NewInboxInfo

func NewInboxInfo(id string, pw string, host string) (info InboxInfo, err error)

func (*InboxInfo) Validate

func (i *InboxInfo) Validate() error

type MessageData

type MessageData struct {
	InternalDate time.Time
	Body         []byte
}

func FetchMessage

func FetchMessage(conn *imap.Client, messageUID uint32) (msg MessageData, err error)

type WorkRequest

type WorkRequest struct {
	Value  string
	Header string
	UID    uint32
	Msg    MessageData
}

Jump to

Keyboard shortcuts

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