From f0c76fad7299c2c43f5891becd4f0327e0e26df5 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 5 Jul 2022 14:48:37 -0500 Subject: threading: add backend capabilities to workers This patch provides a method to report backend capabilities to the UI. The intial capabilities included in the report are Sort and Thread. Having these available to the UI enables the client to better handle server side threading. Signed-off-by: Koni Marti Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- models/models.go | 9 +++++++++ worker/imap/checkmail.go | 1 + worker/imap/worker.go | 14 ++++++++++++++ worker/maildir/worker.go | 5 +++++ worker/notmuch/worker.go | 5 +++++ 5 files changed, 34 insertions(+) diff --git a/models/models.go b/models/models.go index 96683f2..e7325d2 100644 --- a/models/models.go +++ b/models/models.go @@ -51,6 +51,15 @@ type DirectoryInfo struct { // set to true if the value counts are accurate AccurateCounts bool + + // Caps contains the backend capabilities + Caps *Capabilities +} + +// Capabilities provides the backend capabilities +type Capabilities struct { + Sort bool + Thread bool } // A MessageInfo holds information about the structure of a message diff --git a/worker/imap/checkmail.go b/worker/imap/checkmail.go index d9dcfd3..57af3af 100644 --- a/worker/imap/checkmail.go +++ b/worker/imap/checkmail.go @@ -31,6 +31,7 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) { Exists: int(status.Messages), Recent: int(status.Recent), Unseen: int(status.Unseen), + Caps: w.caps, }, SkipSort: true, }, nil) diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 7debd88..3ed646d 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -66,6 +66,8 @@ type IMAPWorker struct { idler *idler observer *observer cache *leveldb.DB + + caps *models.Capabilities } func NewIMAPWorker(worker *types.Worker) (types.Backend, error) { @@ -75,6 +77,7 @@ func NewIMAPWorker(worker *types.Worker) (types.Backend, error) { selected: &imap.MailboxStatus{}, idler: newIdler(imapConfig{}, worker), observer: newObserver(imapConfig{}, worker), + caps: &models.Capabilities{}, }, nil } @@ -83,6 +86,16 @@ func (w *IMAPWorker) newClient(c *client.Client) { w.client = &imapClient{c, sortthread.NewThreadClient(c), sortthread.NewSortClient(c)} w.idler.SetClient(w.client) w.observer.SetClient(w.client) + sort, err := w.client.sort.SupportSort() + if err == nil && sort { + w.caps.Sort = true + w.worker.Logger.Println("Server Capability found: Sort") + } + thread, err := w.client.thread.SupportThread() + if err == nil && thread { + w.caps.Thread = true + w.worker.Logger.Println("Server Capability found: Thread") + } } func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error { @@ -226,6 +239,7 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) { Exists: int(status.Messages), Recent: int(status.Recent), Unseen: int(status.Unseen), + Caps: w.caps, }, }, nil) case *client.MessageUpdate: diff --git a/worker/maildir/worker.go b/worker/maildir/worker.go index cf2970e..0862838 100644 --- a/worker/maildir/worker.go +++ b/worker/maildir/worker.go @@ -186,6 +186,11 @@ func (w *Worker) getDirectoryInfo(name string) *models.DirectoryInfo { Unseen: 0, AccurateCounts: false, + + Caps: &models.Capabilities{ + Sort: true, + Thread: false, + }, } dir := w.c.Dir(name) diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 51e8298..35e6840 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -228,6 +228,11 @@ func (w *worker) gatherDirectoryInfo(name string, query string) ( // total unread Unseen: count.Unread, AccurateCounts: true, + + Caps: &models.Capabilities{ + Sort: true, + Thread: true, + }, }, } return info, nil -- cgit v1.2.3