imap: respect the folder config option

This commit is contained in:
Reto Brunner 2019-06-12 08:31:51 +02:00 committed by Drew DeVault
parent d3b5a76b4a
commit 626f91c483
4 changed files with 48 additions and 13 deletions

View File

@ -141,7 +141,7 @@ func (acct *AccountView) connected(msg types.WorkerMessage) {
break
}
}
if dir == "" {
if dir == "" && len(dirs) > 0 {
dir = dirs[0]
}
acct.dirlist.Select(dir)

View File

@ -47,17 +47,6 @@ func (dirlist *DirectoryList) UpdateList(done func(dirs []string)) {
case *types.Directory:
dirs = append(dirs, msg.Name)
case *types.Done:
// There is always an INBOX, RFC-guaranteed
// However, for some reason Dovecot doesn't always send it.
inbox := false
for _, dir := range dirs {
if dir == "INBOX" {
inbox = true
}
}
if !inbox {
dirs = append(dirs, "INBOX")
}
sort.Strings(dirs)
dirlist.dirs = dirs
dirlist.spinner.Stop()
@ -78,6 +67,18 @@ func (dirlist *DirectoryList) Select(name string) {
dirlist.selecting = ""
case *types.Done:
dirlist.selected = dirlist.selecting
dirlist.filterDirsByFoldersConfig()
hasSelected := false
for _, d := range dirlist.dirs {
if d == dirlist.selected {
hasSelected = true
break
}
}
if !hasSelected && dirlist.selected != "" {
dirlist.dirs = append(dirlist.dirs, dirlist.selected)
}
sort.Strings(dirlist.dirs)
}
dirlist.Invalidate()
})
@ -158,3 +159,22 @@ func (dirlist *DirectoryList) Next() {
func (dirlist *DirectoryList) Prev() {
dirlist.nextPrev(-1)
}
// filterDirsByFoldersConfig filters a folders list to only contain folders
// present in the account.folders config option
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
// config option defaults to show all if unset
if len(dirlist.conf.Folders) == 0 {
return
}
var filtered []string
for _, folder := range dirlist.dirs {
for _, cfgfolder := range dirlist.conf.Folders {
if folder == cfgfolder {
filtered = append(filtered, folder)
break
}
}
}
dirlist.dirs = filtered
}

View File

@ -17,6 +17,19 @@ func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) {
// no need to pass this to handlers if it can't be opened
continue
}
if len(imapw.config.folders) > 0 {
// apply user filter
found := false
for _, folder := range imapw.config.folders {
if folder == mbox.Name || imapw.selected.Name == mbox.Name {
found = true
break
}
}
if !found {
continue
}
}
imapw.worker.PostMessage(&types.Directory{
Message: types.RespondTo(msg),
Name: mbox.Name,

View File

@ -7,7 +7,7 @@ import (
"strings"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap-idle"
idle "github.com/emersion/go-imap-idle"
"github.com/emersion/go-imap/client"
"git.sr.ht/~sircmpwn/aerc/worker/types"
@ -26,6 +26,7 @@ type IMAPWorker struct {
insecure bool
addr string
user *url.Userinfo
folders []string
}
client *imapClient
@ -75,6 +76,7 @@ func (w *IMAPWorker) handleMessage(msg types.WorkerMessage) error {
}
w.config.user = u.User
w.config.folders = msg.Config.Folders
case *types.Connect:
var (
c *client.Client