summary refs log tree commit diff stats
path: root/widgets/dirlist.go
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-06-12 08:31:51 +0200
committerDrew DeVault <sir@cmpwn.com>2019-06-14 10:42:24 -0400
commit626f91c4832c097b7036d5063b2f0491397a9c70 (patch)
tree786310a326cf120e1d4f630fe8ce74405579a9bb /widgets/dirlist.go
parentd3b5a76b4a8ad839991cb686711a0c0d24536d5e (diff)
downloadaerc-626f91c4832c097b7036d5063b2f0491397a9c70.tar.gz
imap: respect the folder config option
Diffstat (limited to 'widgets/dirlist.go')
-rw-r--r--widgets/dirlist.go42
1 files changed, 31 insertions, 11 deletions
diff --git a/widgets/dirlist.go b/widgets/dirlist.go
index 1240e56..d7c4874 100644
--- a/widgets/dirlist.go
+++ b/widgets/dirlist.go
@@ -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
+}