aboutsummaryrefslogtreecommitdiffstats
path: root/worker/imap/checkmail.go
blob: 21f2e4bbd186e610fb3ff6becaf8c3055a72e3b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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,
	}
	for _, dir := range msg.Directories {
		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)
		}
	}
	w.worker.PostMessage(&types.Done{Message: types.RespondTo(msg)}, nil)
}