2022-05-30 14:34:18 +02:00
|
|
|
package imap
|
|
|
|
|
|
|
|
import (
|
2022-07-19 22:31:51 +02:00
|
|
|
"git.sr.ht/~rjarry/aerc/logging"
|
2022-05-30 14:34:18 +02:00
|
|
|
"git.sr.ht/~rjarry/aerc/models"
|
|
|
|
"git.sr.ht/~rjarry/aerc/worker/types"
|
|
|
|
"github.com/emersion/go-imap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (w *IMAPWorker) handleCheckMailMessage(msg *types.CheckMail) {
|
|
|
|
items := []imap.StatusItem{
|
|
|
|
imap.StatusMessages,
|
|
|
|
imap.StatusRecent,
|
|
|
|
imap.StatusUnseen,
|
|
|
|
}
|
2022-09-25 03:55:21 +02:00
|
|
|
var remaining []string
|
2022-05-30 14:34:18 +02:00
|
|
|
for _, dir := range msg.Directories {
|
2022-09-25 03:55:21 +02:00
|
|
|
if len(w.worker.Actions) > 0 {
|
|
|
|
remaining = append(remaining, dir)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2022-07-19 22:31:51 +02:00
|
|
|
logging.Debugf("Getting status of directory %s", dir)
|
2022-05-30 14:34:18 +02:00
|
|
|
status, err := w.client.Status(dir, items)
|
|
|
|
if err != nil {
|
|
|
|
w.worker.PostMessage(&types.Error{
|
|
|
|
Message: types.RespondTo(msg),
|
|
|
|
Error: err,
|
|
|
|
}, nil)
|
|
|
|
} else {
|
|
|
|
w.worker.PostMessage(&types.DirectoryInfo{
|
|
|
|
Info: &models.DirectoryInfo{
|
|
|
|
Flags: status.Flags,
|
|
|
|
Name: status.Name,
|
|
|
|
ReadOnly: status.ReadOnly,
|
|
|
|
AccurateCounts: true,
|
|
|
|
|
|
|
|
Exists: int(status.Messages),
|
|
|
|
Recent: int(status.Recent),
|
|
|
|
Unseen: int(status.Unseen),
|
2022-07-05 21:48:37 +02:00
|
|
|
Caps: w.caps,
|
2022-05-30 14:34:18 +02:00
|
|
|
},
|
|
|
|
SkipSort: true,
|
|
|
|
}, nil)
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 03:55:21 +02:00
|
|
|
if len(remaining) > 0 {
|
|
|
|
w.worker.PostMessage(&types.CheckMailDirectories{
|
|
|
|
Message: types.RespondTo(msg),
|
|
|
|
Directories: remaining,
|
|
|
|
}, nil)
|
|
|
|
return
|
|
|
|
}
|
2022-05-30 14:34:18 +02:00
|
|
|
w.worker.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil)
|
|
|
|
}
|