aboutsummaryrefslogtreecommitdiffstats
path: root/worker
diff options
context:
space:
mode:
Diffstat (limited to 'worker')
-rw-r--r--worker/imap/cache.go4
-rw-r--r--worker/imap/idler.go14
-rw-r--r--worker/imap/search.go7
-rw-r--r--worker/lib/search.go7
-rw-r--r--worker/lib/sort.go10
-rw-r--r--worker/maildir/container.go4
-rw-r--r--worker/maildir/search.go7
-rw-r--r--worker/maildir/worker.go8
-rw-r--r--worker/notmuch/lib/database.go7
9 files changed, 36 insertions, 32 deletions
diff --git a/worker/imap/cache.go b/worker/imap/cache.go
index 863b0714..62d450e6 100644
--- a/worker/imap/cache.go
+++ b/worker/imap/cache.go
@@ -165,9 +165,9 @@ func (w *IMAPWorker) cleanCache() {
logging.Errorf("cannot clean database %d: %v", w.selected.UidValidity, err)
continue
}
- removed = removed + 1
+ removed++
}
- scanned = scanned + 1
+ scanned++
}
iter.Release()
elapsed := time.Since(start)
diff --git a/worker/imap/idler.go b/worker/imap/idler.go
index a658521a..4c2ce6e8 100644
--- a/worker/imap/idler.go
+++ b/worker/imap/idler.go
@@ -61,7 +61,8 @@ func (i *idler) isReady() bool {
}
func (i *idler) Start() {
- if i.isReady() {
+ switch {
+ case i.isReady():
i.stop = make(chan struct{})
go func() {
@@ -87,16 +88,17 @@ func (i *idler) Start() {
}
}()
- } else if i.isWaiting() {
+ case i.isWaiting():
i.log("not started: wait for idle to exit")
- } else {
+ default:
i.log("not started: client not ready")
}
}
func (i *idler) Stop() error {
var reterr error
- if i.isReady() {
+ switch {
+ case i.isReady():
close(i.stop)
select {
case err := <-i.done:
@@ -118,10 +120,10 @@ func (i *idler) Stop() error {
reterr = errIdleTimeout
}
- } else if i.isWaiting() {
+ case i.isWaiting():
i.log("not stopped: still idleing/hanging")
reterr = errIdleModeHangs
- } else {
+ default:
i.log("not stopped: client not ready")
reterr = nil
}
diff --git a/worker/imap/search.go b/worker/imap/search.go
index 46a25c7c..adbc6b90 100644
--- a/worker/imap/search.go
+++ b/worker/imap/search.go
@@ -49,11 +49,12 @@ func parseSearch(args []string) (*imap.SearchCriteria, error) {
text = true
}
}
- if text {
+ switch {
+ case text:
criteria.Text = args[optind:]
- } else if body {
+ case body:
criteria.Body = args[optind:]
- } else {
+ default:
for _, arg := range args[optind:] {
criteria.Header.Add("Subject", arg)
}
diff --git a/worker/lib/search.go b/worker/lib/search.go
index dc29a66f..551d33cd 100644
--- a/worker/lib/search.go
+++ b/worker/lib/search.go
@@ -53,11 +53,12 @@ func GetSearchCriteria(args []string) (*searchCriteria, error) {
text = true
}
}
- if text {
+ switch {
+ case text:
criteria.Text = args[optind:]
- } else if body {
+ case body:
criteria.Body = args[optind:]
- } else {
+ default:
for _, arg := range args[optind:] {
criteria.Header.Add("Subject", arg)
}
diff --git a/worker/lib/sort.go b/worker/lib/sort.go
index 3bfd7d41..1a1bb47f 100644
--- a/worker/lib/sort.go
+++ b/worker/lib/sort.go
@@ -74,13 +74,7 @@ func sortAddresses(messageInfos []*models.MessageInfo, criterion *types.SortCrit
if len(addressJ) > 0 {
firstJ = addressJ[0]
}
- if firstI == nil && firstJ == nil {
- return false
- } else if firstI == nil && firstJ != nil {
- return false
- } else if firstI != nil && firstJ == nil {
- return true
- } else /* firstI != nil && firstJ != nil */ {
+ if firstI != nil && firstJ != nil {
getName := func(addr *mail.Address) string {
if addr.Name != "" {
return addr.Name
@@ -89,6 +83,8 @@ func sortAddresses(messageInfos []*models.MessageInfo, criterion *types.SortCrit
}
}
return getName(firstI) < getName(firstJ)
+ } else {
+ return firstI != nil && firstJ == nil
}
})
}
diff --git a/worker/maildir/container.go b/worker/maildir/container.go
index 1d971a4d..35125775 100644
--- a/worker/maildir/container.go
+++ b/worker/maildir/container.go
@@ -80,7 +80,7 @@ func (c *Container) ListFolders() ([]string, error) {
return filepath.SkipDir
}
dirPath = strings.TrimPrefix(dirPath, ".")
- dirPath = strings.Replace(dirPath, ".", "/", -1)
+ dirPath = strings.ReplaceAll(dirPath, ".", "/")
folders = append(folders, dirPath)
// Since all mailboxes are stored in a single directory, don't
@@ -124,7 +124,7 @@ func (c *Container) Dir(name string) maildir.Dir {
if name == "INBOX" {
return maildir.Dir(c.dir)
}
- return maildir.Dir(filepath.Join(c.dir, "."+strings.Replace(name, "/", ".", -1)))
+ return maildir.Dir(filepath.Join(c.dir, "."+strings.ReplaceAll(name, "/", ".")))
}
return maildir.Dir(filepath.Join(c.dir, name))
}
diff --git a/worker/maildir/search.go b/worker/maildir/search.go
index 7a8ba0e0..6260deb4 100644
--- a/worker/maildir/search.go
+++ b/worker/maildir/search.go
@@ -61,11 +61,12 @@ func parseSearch(args []string) (*searchCriteria, error) {
text = true
}
}
- if text {
+ switch {
+ case text:
criteria.Text = args[optind:]
- } else if body {
+ case body:
criteria.Body = args[optind:]
- } else {
+ default:
for _, arg := range args[optind:] {
criteria.Header.Add("Subject", arg)
}
diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go
index 838a3b7f..a770b2f4 100644
--- a/worker/maildir/worker.go
+++ b/worker/maildir/worker.go
@@ -81,16 +81,18 @@ func (w *Worker) handleAction(action types.WorkerMessage) {
go w.handleCheckMail(msg)
default:
// Default handling, will be performed synchronously
- if err := w.handleMessage(msg); err == errUnsupported {
+ err := w.handleMessage(msg)
+ switch {
+ case errors.Is(err, errUnsupported):
w.worker.PostMessage(&types.Unsupported{
Message: types.RespondTo(msg),
}, nil)
- } else if err != nil {
+ case err != nil:
w.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),
Error: err,
}, nil)
- } else {
+ default:
w.done(msg)
}
}
diff --git a/worker/notmuch/lib/database.go b/worker/notmuch/lib/database.go
index 780e7ab3..e8a581c6 100644
--- a/worker/notmuch/lib/database.go
+++ b/worker/notmuch/lib/database.go
@@ -351,11 +351,12 @@ func (db *DB) makeThread(parent *types.Thread, msgs *notmuch.Messages,
// We want to return the root node
var root *types.Thread
- if parent != nil {
+ switch {
+ case parent != nil:
root = parent
- } else if lastSibling != nil {
+ case lastSibling != nil:
root = lastSibling // first iteration has no parent
- } else {
+ default:
return nil // we don't have any messages at all
}