From 82de08a8a3f55c438d8808e3c759e3d99261c4b8 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sun, 16 Apr 2023 09:53:37 -0500 Subject: imap: properly handle mailbox status updates Mailbox status updates received from the IMAP server do not come with the information being sent to the UI. Use the update signal to instead trigger a check-mail of the directory the status was sent for. The status update comes with the following data: - Messages in the mailbox - Recent messages in the mailbox - Sequence number of the first Unseen message - Flags in the mailbox The data we actually we want to send to the UI: - Messages in the mailbox - Recent messages in the mailbox - Unseen messages in the mailbox Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- worker/imap/checkmail.go | 9 +++++++++ worker/imap/worker.go | 17 ++--------------- 2 files changed, 11 insertions(+), 15 deletions(-) (limited to 'worker') diff --git a/worker/imap/checkmail.go b/worker/imap/checkmail.go index c1b6ec4c..9c1f14c1 100644 --- a/worker/imap/checkmail.go +++ b/worker/imap/checkmail.go @@ -12,6 +12,7 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) { imap.StatusMessages, imap.StatusRecent, imap.StatusUnseen, + imap.StatusUidNext, } var ( statuses []*imap.MailboxStatus @@ -48,6 +49,13 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) { } } for _, status := range statuses { + refetch := false + if status.Name == w.selected.Name { + if status.UidNext != w.selected.UidNext { + refetch = true + } + w.selected = status + } w.worker.PostMessage(&types.DirectoryInfo{ Info: &models.DirectoryInfo{ Flags: status.Flags, @@ -60,6 +68,7 @@ func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) { Unseen: int(status.Unseen), Caps: w.caps, }, + Refetch: refetch, }, nil) } if len(remaining) > 0 { diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 752eac52..8673c0ff 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -249,21 +249,8 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) { log.Tracef("(= %T", update) switch update := update.(type) { case *client.MailboxUpdate: - status := update.Mailbox - if w.selected.Name == status.Name { - w.selected = status - } - w.worker.PostMessage(&types.DirectoryInfo{ - Info: &models.DirectoryInfo{ - Flags: status.Flags, - Name: status.Name, - ReadOnly: status.ReadOnly, - - Exists: int(status.Messages), - Recent: int(status.Recent), - Unseen: int(status.Unseen), - Caps: w.caps, - }, + w.worker.PostAction(&types.CheckMail{ + Directories: []string{update.Mailbox.Name}, }, nil) case *client.MessageUpdate: msg := update.Message -- cgit