diff options
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/connect.go | 4 | ||||
-rw-r--r-- | worker/imap/fetch.go | 15 | ||||
-rw-r--r-- | worker/imap/list.go | 1 | ||||
-rw-r--r-- | worker/imap/movecopy.go | 1 | ||||
-rw-r--r-- | worker/imap/observer.go | 3 | ||||
-rw-r--r-- | worker/imap/open.go | 10 | ||||
-rw-r--r-- | worker/lib/parse.go | 4 | ||||
-rw-r--r-- | worker/lib/search.go | 4 | ||||
-rw-r--r-- | worker/lib/sort.go | 12 | ||||
-rw-r--r-- | worker/maildir/container.go | 12 | ||||
-rw-r--r-- | worker/maildir/search.go | 3 | ||||
-rw-r--r-- | worker/maildir/worker.go | 10 | ||||
-rw-r--r-- | worker/mbox/create.go | 1 | ||||
-rw-r--r-- | worker/mbox/worker.go | 6 | ||||
-rw-r--r-- | worker/notmuch/lib/database.go | 19 | ||||
-rw-r--r-- | worker/notmuch/message.go | 12 | ||||
-rw-r--r-- | worker/notmuch/worker.go | 39 | ||||
-rw-r--r-- | worker/types/thread.go | 4 | ||||
-rw-r--r-- | worker/types/thread_test.go | 2 | ||||
-rw-r--r-- | worker/types/worker.go | 5 |
20 files changed, 97 insertions, 70 deletions
diff --git a/worker/imap/connect.go b/worker/imap/connect.go index 5f8cd1c0..bfd95d82 100644 --- a/worker/imap/connect.go +++ b/worker/imap/connect.go @@ -16,7 +16,6 @@ import ( // selects the default inbox. If no error is returned, the imap client will be // in the imap.SelectedState. func (w *IMAPWorker) connect() (*client.Client, error) { - var ( conn *net.TCPConn err error @@ -98,8 +97,7 @@ func (w *IMAPWorker) connect() (*client.Client, error) { // but a valid connection is eventually returned, ensure that it is properly // closed. func newTCPConn(addr string, timeout time.Duration) (*net.TCPConn, error) { - - var errTCPTimeout = fmt.Errorf("tcp connection timeout") + errTCPTimeout := fmt.Errorf("tcp connection timeout") type tcpConn struct { conn *net.TCPConn diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index 6ef0baca..b6a5509e 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -16,7 +16,8 @@ import ( ) func (imapw *IMAPWorker) handleFetchMessageHeaders( - msg *types.FetchMessageHeaders) { + msg *types.FetchMessageHeaders, +) { toFetch := msg.Uids if imapw.config.cacheEnabled && imapw.cache != nil { toFetch = imapw.getCachedHeaders(msg) @@ -76,8 +77,8 @@ func (imapw *IMAPWorker) handleFetchMessageHeaders( } func (imapw *IMAPWorker) handleFetchMessageBodyPart( - msg *types.FetchMessageBodyPart) { - + msg *types.FetchMessageBodyPart, +) { logging.Infof("Fetching message %d part: %v", msg.Uid, msg.Part) var partHeaderSection imap.BodySectionName @@ -146,8 +147,8 @@ func (imapw *IMAPWorker) handleFetchMessageBodyPart( } func (imapw *IMAPWorker) handleFetchFullMessages( - msg *types.FetchFullMessages) { - + msg *types.FetchFullMessages, +) { logging.Infof("Fetching full messages: %v", msg.Uids) section := &imap.BodySectionName{} items := []imap.FetchItem{ @@ -205,8 +206,8 @@ func (imapw *IMAPWorker) handleFetchMessageFlags(msg *types.FetchMessageFlags) { func (imapw *IMAPWorker) handleFetchMessages( msg types.WorkerMessage, uids []uint32, items []imap.FetchItem, - procFunc func(*imap.Message) error) { - + procFunc func(*imap.Message) error, +) { messages := make(chan *imap.Message) done := make(chan error) diff --git a/worker/imap/list.go b/worker/imap/list.go index 51f4d3e6..67d4c33d 100644 --- a/worker/imap/list.go +++ b/worker/imap/list.go @@ -79,5 +79,4 @@ func (imapw *IMAPWorker) handleSearchDirectory(msg *types.SearchDirectory) { Message: types.RespondTo(msg), Uids: uids, }, nil) - } diff --git a/worker/imap/movecopy.go b/worker/imap/movecopy.go index f1f2b45d..1d25c08c 100644 --- a/worker/imap/movecopy.go +++ b/worker/imap/movecopy.go @@ -38,7 +38,6 @@ func (imapw *IMAPWorker) handleAppendMessage(msg *types.AppendMessage) { Reader: msg.Reader, Length: msg.Length, }); err != nil { - imapw.worker.PostMessage(&types.Error{ Message: types.RespondTo(msg), Error: err, diff --git a/worker/imap/observer.go b/worker/imap/observer.go index 448128c7..866fac62 100644 --- a/worker/imap/observer.go +++ b/worker/imap/observer.go @@ -140,7 +140,8 @@ func (o *observer) DelayedReconnect() error { func (o *observer) emit(errMsg string) { o.log("disconnect done->") o.worker.PostMessage(&types.Done{ - Message: types.RespondTo(&types.Disconnect{})}, nil) + Message: types.RespondTo(&types.Disconnect{}), + }, nil) o.log("connection error->") o.worker.PostMessage(&types.ConnError{ Error: fmt.Errorf(errMsg), diff --git a/worker/imap/open.go b/worker/imap/open.go index 2d76f43e..7abebea4 100644 --- a/worker/imap/open.go +++ b/worker/imap/open.go @@ -25,8 +25,8 @@ func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) { } func (imapw *IMAPWorker) handleFetchDirectoryContents( - msg *types.FetchDirectoryContents) { - + msg *types.FetchDirectoryContents, +) { logging.Infof("Fetching UID list") searchCriteria, err := parseSearch(msg.FilterCriteria) @@ -88,7 +88,8 @@ var sortFieldMap sortFieldMapT = sortFieldMapT{ } func translateSortCriterions( - cs []*types.SortCriterion) []sortthread.SortCriterion { + cs []*types.SortCriterion, +) []sortthread.SortCriterion { result := make([]sortthread.SortCriterion, 0, len(cs)) for _, c := range cs { if f, ok := sortFieldMap[c.Field]; ok { @@ -99,7 +100,8 @@ func translateSortCriterions( } func (imapw *IMAPWorker) handleDirectoryThreaded( - msg *types.FetchDirectoryThreaded) { + msg *types.FetchDirectoryThreaded, +) { logging.Infof("Fetching threaded UID list") searchCriteria, err := parseSearch(msg.FilterCriteria) diff --git a/worker/lib/parse.go b/worker/lib/parse.go index bdd927f9..d92eeda7 100644 --- a/worker/lib/parse.go +++ b/worker/lib/parse.go @@ -46,7 +46,7 @@ func FetchEntityPartReader(e *message.Entity, index []int) (io.Reader, error) { return nil, fmt.Errorf("FetchEntityPartReader: unexpected code reached") } -//TODO: the UI doesn't seem to like readers which aren't buffers +// TODO: the UI doesn't seem to like readers which aren't buffers func bufReader(e *message.Entity) (io.Reader, error) { var buf bytes.Buffer if _, err := io.Copy(&buf, e.Body); err != nil { @@ -157,7 +157,7 @@ func parseEnvelope(h *mail.Header) (*models.Envelope, error) { } msgID, err := h.MessageID() if err != nil { - //proper parsing failed, so fall back to whatever is there + // proper parsing failed, so fall back to whatever is there msgID, err = h.Text("message-id") if err != nil { return nil, err diff --git a/worker/lib/search.go b/worker/lib/search.go index c7d3bee7..dc29a66f 100644 --- a/worker/lib/search.go +++ b/worker/lib/search.go @@ -97,8 +97,8 @@ func Search(messages []RawMessage, criteria *searchCriteria) ([]uint32, error) { // searchMessage executes the search criteria for the given RawMessage, // returns true if search succeeded func searchMessage(message RawMessage, criteria *searchCriteria, - parts MsgParts) (bool, error) { - + parts MsgParts, +) (bool, error) { // setup parts of the message to use in the search // this is so that we try to minimise reading unnecessary parts var ( diff --git a/worker/lib/sort.go b/worker/lib/sort.go index 958cbed7..3bfd7d41 100644 --- a/worker/lib/sort.go +++ b/worker/lib/sort.go @@ -10,7 +10,8 @@ import ( ) func Sort(messageInfos []*models.MessageInfo, - criteria []*types.SortCriterion) ([]uint32, error) { + criteria []*types.SortCriterion, +) ([]uint32, error) { // loop through in reverse to ensure we sort by non-primary fields first for i := len(criteria) - 1; i >= 0; i-- { criterion := criteria[i] @@ -62,7 +63,8 @@ func Sort(messageInfos []*models.MessageInfo, } func sortAddresses(messageInfos []*models.MessageInfo, criterion *types.SortCriterion, - getValue func(*models.MessageInfo) []*mail.Address) { + getValue func(*models.MessageInfo) []*mail.Address, +) { sortSlice(criterion, messageInfos, func(i, j int) bool { addressI, addressJ := getValue(messageInfos[i]), getValue(messageInfos[j]) var firstI, firstJ *mail.Address @@ -92,7 +94,8 @@ func sortAddresses(messageInfos []*models.MessageInfo, criterion *types.SortCrit } func sortFlags(messageInfos []*models.MessageInfo, criterion *types.SortCriterion, - testFlag models.Flag) { + testFlag models.Flag, +) { var slice []*boolStore for _, msgInfo := range messageInfos { flagPresent := false @@ -116,7 +119,8 @@ func sortFlags(messageInfos []*models.MessageInfo, criterion *types.SortCriterio } func sortStrings(messageInfos []*models.MessageInfo, criterion *types.SortCriterion, - getValue func(*models.MessageInfo) string) { + getValue func(*models.MessageInfo) string, +) { var slice []*lexiStore for _, msgInfo := range messageInfos { slice = append(slice, &lexiStore{ diff --git a/worker/maildir/container.go b/worker/maildir/container.go index 83f850ab..1d971a4d 100644 --- a/worker/maildir/container.go +++ b/worker/maildir/container.go @@ -35,8 +35,10 @@ func NewContainer(dir string, maildirpp bool) (*Container, error) { if !s.IsDir() { return nil, fmt.Errorf("Given maildir '%s' not a directory", dir) } - return &Container{dir: dir, uids: uidstore.NewStore(), - recentUIDS: make(map[uint32]struct{}), maildirpp: maildirpp}, nil + return &Container{ + dir: dir, uids: uidstore.NewStore(), + recentUIDS: make(map[uint32]struct{}), maildirpp: maildirpp, + }, nil } // ListFolders returns a list of maildir folders in the container @@ -183,7 +185,8 @@ func (c *Container) DeleteAll(d maildir.Dir, uids []uint32) ([]uint32, error) { } func (c *Container) CopyAll( - dest maildir.Dir, src maildir.Dir, uids []uint32) error { + dest maildir.Dir, src maildir.Dir, uids []uint32, +) error { for _, uid := range uids { if err := c.copyMessage(dest, src, uid); err != nil { return fmt.Errorf("could not copy message %d: %v", uid, err) @@ -193,7 +196,8 @@ func (c *Container) CopyAll( } func (c *Container) copyMessage( - dest maildir.Dir, src maildir.Dir, uid uint32) error { + dest maildir.Dir, src maildir.Dir, uid uint32, +) error { key, ok := c.uids.GetKey(uid) if !ok { return fmt.Errorf("could not find key for message id %d", uid) diff --git a/worker/maildir/search.go b/worker/maildir/search.go index b8e91df0..7a8ba0e0 100644 --- a/worker/maildir/search.go +++ b/worker/maildir/search.go @@ -111,7 +111,8 @@ func (w *Worker) search(criteria *searchCriteria) ([]uint32, error) { // Execute the search criteria for the given key, returns true if search succeeded func (w *Worker) searchKey(key uint32, criteria *searchCriteria, - parts MsgParts) (bool, error) { + parts MsgParts, +) (bool, error) { message, err := w.c.Message(*w.selected, key) if err != nil { return false, err diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index d60315b8..838a3b7f 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -406,7 +406,8 @@ func (w *Worker) handleOpenDirectory(msg *types.OpenDirectory) error { } func (w *Worker) handleFetchDirectoryContents( - msg *types.FetchDirectoryContents) error { + msg *types.FetchDirectoryContents, +) error { var ( uids []uint32 err error @@ -482,7 +483,8 @@ func (w *Worker) handleRemoveDirectory(msg *types.RemoveDirectory) error { } func (w *Worker) handleFetchMessageHeaders( - msg *types.FetchMessageHeaders) error { + msg *types.FetchMessageHeaders, +) error { for _, uid := range msg.Uids { info, err := w.msgInfoFromUid(uid) if err != nil { @@ -500,8 +502,8 @@ func (w *Worker) handleFetchMessageHeaders( } func (w *Worker) handleFetchMessageBodyPart( - msg *types.FetchMessageBodyPart) error { - + msg *types.FetchMessageBodyPart, +) error { // get reader m, err := w.c.Message(*w.selected, msg.Uid) if err != nil { diff --git a/worker/mbox/create.go b/worker/mbox/create.go index 7c4d9f7b..266398ab 100644 --- a/worker/mbox/create.go +++ b/worker/mbox/create.go @@ -8,7 +8,6 @@ import ( ) func createMailboxContainer(path string) (*mailboxContainer, error) { - file, err := os.Open(path) if err != nil { return nil, err diff --git a/worker/mbox/worker.go b/worker/mbox/worker.go index 4c0a1271..6ba886ae 100644 --- a/worker/mbox/worker.go +++ b/worker/mbox/worker.go @@ -99,7 +99,8 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { if !ok { w.folder = w.data.Create(w.name) w.worker.PostMessage(&types.Done{ - Message: types.RespondTo(&types.CreateDirectory{})}, nil) + Message: types.RespondTo(&types.CreateDirectory{}), + }, nil) } w.worker.PostMessage(&types.DirectoryInfo{ Info: w.data.DirectoryInfo(msg.Directory), @@ -338,7 +339,8 @@ func (w *mboxWorker) handleMessage(msg types.WorkerMessage) error { if !ok { folder = w.data.Create(msg.Destination) w.worker.PostMessage(&types.Done{ - Message: types.RespondTo(&types.CreateDirectory{})}, nil) + Message: types.RespondTo(&types.CreateDirectory{}), + }, nil) } if err := folder.Append(msg.Reader, msg.Flags); err != nil { diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go index 801f122a..ac1a28ed 100644 --- a/worker/notmuch/lib/database.go +++ b/worker/notmuch/lib/database.go @@ -61,9 +61,9 @@ func (db *DB) connect(writable bool) error { return nil } -//withConnection calls callback on the DB object, cleaning up upon return. -//the error returned is from the connection attempt, if not successful, -//or from the callback otherwise. +// withConnection calls callback on the DB object, cleaning up upon return. +// the error returned is from the connection attempt, if not successful, +// or from the callback otherwise. func (db *DB) withConnection(writable bool, cb func(*notmuch.DB) error) error { too_old := time.Now().After(db.lastOpenTime.Add(MAX_DB_AGE)) if db.db == nil || writable || too_old { @@ -104,8 +104,8 @@ func (db *DB) ListTags() ([]string, error) { return result, err } -//getQuery returns a query based on the provided query string. -//It also configures the query as specified on the worker +// getQuery returns a query based on the provided query string. +// It also configures the query as specified on the worker func (db *DB) newQuery(ndb *notmuch.DB, query string) (*notmuch.Query, error) { q := ndb.NewQuery(query) q.SetExcludeScheme(notmuch.EXCLUDE_ALL) @@ -225,7 +225,8 @@ func (db *DB) MsgTags(key string) ([]string, error) { } func (db *DB) msgModify(key string, - cb func(*notmuch.Message) error) error { + cb func(*notmuch.Message) error, +) error { err := db.withConnection(true, func(ndb *notmuch.DB) error { msg, err := ndb.FindMessage(key) if err != nil { @@ -281,7 +282,8 @@ func (db *DB) KeyFromUid(uid uint32) (string, bool) { } func (db *DB) enumerateThread(nt *notmuch.Threads, - valid map[string]struct{}) ([]*types.Thread, error) { + valid map[string]struct{}, +) ([]*types.Thread, error) { var res []*types.Thread var thread *notmuch.Thread for nt.Next(&thread) { @@ -292,7 +294,8 @@ func (db *DB) enumerateThread(nt *notmuch.Threads, } func (db *DB) makeThread(parent *types.Thread, msgs *notmuch.Messages, - valid map[string]struct{}) *types.Thread { + valid map[string]struct{}, +) *types.Thread { var lastSibling *types.Thread var msg *notmuch.Message for msgs.Next(&msg) { diff --git a/worker/notmuch/message.go b/worker/notmuch/message.go index e39fb17a..fe82700e 100644 --- a/worker/notmuch/message.go +++ b/worker/notmuch/message.go @@ -160,16 +160,16 @@ func (m *Message) Filename() (string, error) { return m.db.MsgFilename(m.key) } -//AddTag adds a single tag. -//Consider using *Message.ModifyTags for multiple additions / removals -//instead of looping over a tag array +// AddTag adds a single tag. +// Consider using *Message.ModifyTags for multiple additions / removals +// instead of looping over a tag array func (m *Message) AddTag(tag string) error { return m.ModifyTags([]string{tag}, nil) } -//RemoveTag removes a single tag. -//Consider using *Message.ModifyTags for multiple additions / removals -//instead of looping over a tag array +// RemoveTag removes a single tag. +// Consider using *Message.ModifyTags for multiple additions / removals +// instead of looping over a tag array func (m *Message) RemoveTag(tag string) error { return m.ModifyTags(nil, []string{tag}) } diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 36ef10f6..2c80dbd4 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -51,8 +51,10 @@ type worker struct { // NewWorker creates a new notmuch worker with the provided worker. func NewWorker(w *types.Worker) (types.Backend, error) { events := make(chan eventType, 20) - return &worker{w: w, - nmEvents: events}, nil + return &worker{ + w: w, + nmEvents: events, + }, nil } // Run starts the worker's message handling loop. @@ -92,6 +94,7 @@ func (w *worker) err(msg types.WorkerMessage, err error) { Error: err, }, nil) } + func (w *worker) handleMessage(msg types.WorkerMessage) error { if w.setupErr != nil { // only configure can recover from a config error, bail for everything else @@ -211,12 +214,14 @@ func (w *worker) handleListDirectories(msg *types.ListDirectories) error { } func (w *worker) gatherDirectoryInfo(name string, query string) ( - *types.DirectoryInfo, error) { + *types.DirectoryInfo, error, +) { return w.buildDirInfo(name, query, false) } func (w *worker) buildDirInfo(name string, query string, skipSort bool) ( - *types.DirectoryInfo, error) { + *types.DirectoryInfo, error, +) { count, err := w.db.QueryCountMessages(query) if err != nil { return nil, err @@ -254,8 +259,8 @@ func (w *worker) emitDirectoryInfo(name string) error { return nil } -//queryFromName either returns the friendly ID if aliased or the name itself -//assuming it to be the query +// queryFromName either returns the friendly ID if aliased or the name itself +// assuming it to be the query func (w *worker) queryFromName(name string) string { // try the friendly name first, if that fails assume it's a query q, ok := w.nameQueryMap[name] @@ -281,7 +286,8 @@ func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error { } func (w *worker) handleFetchDirectoryContents( - msg *types.FetchDirectoryContents) error { + msg *types.FetchDirectoryContents, +) error { w.currentSortCriteria = msg.SortCriteria err := w.emitDirectoryContents(msg) if err != nil { @@ -292,7 +298,8 @@ func (w *worker) handleFetchDirectoryContents( } func (w *worker) handleFetchDirectoryThreaded( - msg *types.FetchDirectoryThreaded) error { + msg *types.FetchDirectoryThreaded, +) error { // w.currentSortCriteria = msg.SortCriteria err := w.emitDirectoryThreaded(msg) if err != nil { @@ -303,7 +310,8 @@ func (w *worker) handleFetchDirectoryThreaded( } func (w *worker) handleFetchMessageHeaders( - msg *types.FetchMessageHeaders) error { + msg *types.FetchMessageHeaders, +) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { @@ -350,8 +358,8 @@ func (w *worker) msgFromUid(uid uint32) (*Message, error) { } func (w *worker) handleFetchMessageBodyPart( - msg *types.FetchMessageBodyPart) error { - + msg *types.FetchMessageBodyPart, +) error { m, err := w.msgFromUid(msg.Uid) if err != nil { logging.Errorf("could not get message %d: %v", msg.Uid, err) @@ -542,7 +550,8 @@ func (w *worker) loadQueryMap(acctConfig *config.AccountConfig) error { } func (w *worker) loadExcludeTags( - acctConfig *config.AccountConfig) []string { + acctConfig *config.AccountConfig, +) []string { raw, ok := acctConfig.Params["exclude-tags"] if !ok { // nothing to do @@ -598,7 +607,8 @@ func (w *worker) emitDirectoryThreaded(parent types.WorkerMessage) error { } func (w *worker) emitMessageInfo(m *Message, - parent types.WorkerMessage) error { + parent types.WorkerMessage, +) error { info, err := m.MessageInfo() if err != nil { return fmt.Errorf("could not get MessageInfo: %v", err) @@ -620,7 +630,8 @@ func (w *worker) emitLabelList() { } func (w *worker) sort(uids []uint32, - criteria []*types.SortCriterion) ([]uint32, error) { + criteria []*types.SortCriterion, +) ([]uint32, error) { if len(criteria) == 0 { return uids, nil } diff --git a/worker/types/thread.go b/worker/types/thread.go index 7c0cc5b8..705b3e4e 100644 --- a/worker/types/thread.go +++ b/worker/types/thread.go @@ -94,7 +94,7 @@ var ErrSkipThread = errors.New("skip this Thread") type NewThreadWalkFn func(t *Thread, level int, currentErr error) error -//Implement interface to be able to sort threads by newest (max UID) +// Implement interface to be able to sort threads by newest (max UID) type ByUID []*Thread func getMaxUID(thread *Thread) uint32 { @@ -113,9 +113,11 @@ func getMaxUID(thread *Thread) uint32 { func (s ByUID) Len() int { return len(s) } + func (s ByUID) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + func (s ByUID) Less(i, j int) bool { maxUID_i := getMaxUID(s[i]) maxUID_j := getMaxUID(s[j]) diff --git a/worker/types/thread_test.go b/worker/types/thread_test.go index e79dddd1..803f7ba9 100644 --- a/worker/types/thread_test.go +++ b/worker/types/thread_test.go @@ -85,7 +85,7 @@ func TestNewWalk(t *testing.T) { prefix = append(prefix, " ") } } else if lvl < lastLevel { - //ascended, need to trim the prefix layers + // ascended, need to trim the prefix layers diff := lastLevel - lvl prefix = prefix[:len(prefix)-diff] } diff --git a/worker/types/worker.go b/worker/types/worker.go index 8f179df6..9e247982 100644 --- a/worker/types/worker.go +++ b/worker/types/worker.go @@ -36,7 +36,6 @@ func (worker *Worker) setId(msg WorkerMessage) { } func (worker *Worker) PostAction(msg WorkerMessage, cb func(msg WorkerMessage)) { - worker.setId(msg) if resp := msg.InResponseTo(); resp != nil { @@ -52,8 +51,8 @@ func (worker *Worker) PostAction(msg WorkerMessage, cb func(msg WorkerMessage)) } func (worker *Worker) PostMessage(msg WorkerMessage, - cb func(msg WorkerMessage)) { - + cb func(msg WorkerMessage), +) { worker.setId(msg) if resp := msg.InResponseTo(); resp != nil { |