aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-04-16 09:53:37 -0500
committerRobin Jarry <robin@jarry.cc>2023-04-22 22:40:12 +0200
commit82de08a8a3f55c438d8808e3c759e3d99261c4b8 (patch)
treeea658d1524029a3a8e32b1c64570dc5d1281f6e0
parent91ac21ac615582e2dd5e36f4b36bde1bc0bf38d8 (diff)
downloadaerc-82de08a8a3f55c438d8808e3c759e3d99261c4b8.tar.gz
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 <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--worker/imap/checkmail.go9
-rw-r--r--worker/imap/worker.go17
2 files changed, 11 insertions, 15 deletions
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