9c0e54f9d9
Pass message containing remaining directories to check. Account widget will recursively call CheckMail with the remaining directories until a Done message is returned. Only needed for IMAP worker as other workers run check-mail-cmd in a separate goroutine. Suggested-By: Tim Culverhouse <tim@timculverhouse.com> Signed-off-by: kt programs <ktprograms@gmail.com> Tested-by: Tim Culverhouse <tim@timculverhouse.com>
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package imap
|
|
|
|
import (
|
|
"git.sr.ht/~rjarry/aerc/logging"
|
|
"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,
|
|
}
|
|
var remaining []string
|
|
for _, dir := range msg.Directories {
|
|
if len(w.worker.Actions) > 0 {
|
|
remaining = append(remaining, dir)
|
|
continue
|
|
}
|
|
|
|
logging.Debugf("Getting status of directory %s", dir)
|
|
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),
|
|
Caps: w.caps,
|
|
},
|
|
SkipSort: true,
|
|
}, nil)
|
|
}
|
|
}
|
|
if len(remaining) > 0 {
|
|
w.worker.PostMessage(&types.CheckMailDirectories{
|
|
Message: types.RespondTo(msg),
|
|
Directories: remaining,
|
|
}, nil)
|
|
return
|
|
}
|
|
w.worker.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil)
|
|
}
|