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 <koni.marti@gmail.com>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-07-05 14:48:37 -05:00 committed by Robin Jarry
parent a8879d79c6
commit f0c76fad72
5 changed files with 34 additions and 0 deletions

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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)

View File

@ -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