Add a 'folders-exclude' option
Added a 'folders-exclude' option that allows removing selected folders from the directory list sidebar. My motivating example was that removing a single folder from the list using Golang regexes seemed pretty hard, so this is a better way to do it. The excluded folders list is included in the man page.
This commit is contained in:
parent
bf16ccde48
commit
e1c2b596dc
3 changed files with 43 additions and 14 deletions
|
@ -76,6 +76,7 @@ type AccountConfig struct {
|
||||||
Source string
|
Source string
|
||||||
SourceCredCmd string
|
SourceCredCmd string
|
||||||
Folders []string
|
Folders []string
|
||||||
|
FoldersExclude []string
|
||||||
Params map[string]string
|
Params map[string]string
|
||||||
Outgoing string
|
Outgoing string
|
||||||
OutgoingCredCmd string
|
OutgoingCredCmd string
|
||||||
|
@ -186,6 +187,10 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
|
||||||
folders := strings.Split(val, ",")
|
folders := strings.Split(val, ",")
|
||||||
sort.Strings(folders)
|
sort.Strings(folders)
|
||||||
account.Folders = folders
|
account.Folders = folders
|
||||||
|
} else if key == "folders-exclude" {
|
||||||
|
folders := strings.Split(val, ",")
|
||||||
|
sort.Strings(folders)
|
||||||
|
account.FoldersExclude = folders
|
||||||
} else if key == "source-cred-cmd" {
|
} else if key == "source-cred-cmd" {
|
||||||
account.SourceCredCmd = val
|
account.SourceCredCmd = val
|
||||||
} else if key == "outgoing" {
|
} else if key == "outgoing" {
|
||||||
|
|
|
@ -376,6 +376,13 @@ Note that many of these configuration options are written for you, such as
|
||||||
|
|
||||||
Default: all folders
|
Default: all folders
|
||||||
|
|
||||||
|
*folders-exclude*
|
||||||
|
Specifies the comma separated list of folders to exclude from the sidebar.
|
||||||
|
Names prefixed with ~ are interpreted as regular expressions.
|
||||||
|
Note that this overrides anything from *folders*.
|
||||||
|
|
||||||
|
Default: no folders
|
||||||
|
|
||||||
*folders-sort*
|
*folders-sort*
|
||||||
Specifies a comma separated list of folders to be shown at the top of the
|
Specifies a comma separated list of folders to be shown at the top of the
|
||||||
list in the provided order. Remaining folders will be sorted alphabetically.
|
list in the provided order. Remaining folders will be sorted alphabetically.
|
||||||
|
|
|
@ -390,24 +390,41 @@ func (dirlist *DirectoryList) sortDirsByFoldersSortConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// filterDirsByFoldersConfig sets dirlist.dirs to the filtered subset of the
|
// filterDirsByFoldersConfig sets dirlist.dirs to the filtered subset of the
|
||||||
// dirstore, based on the AccountConfig.Folders option
|
// dirstore, based on AccountConfig.Folders (inclusion) and
|
||||||
|
// AccountConfig.FoldersExclude (exclusion), in that order.
|
||||||
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
|
func (dirlist *DirectoryList) filterDirsByFoldersConfig() {
|
||||||
dirlist.dirs = dirlist.store.List()
|
filterDirs := func(orig, filters []string, exclude bool) []string {
|
||||||
// config option defaults to show all if unset
|
if len(filters) == 0 {
|
||||||
configFolders := dirlist.acctConf.Folders
|
return orig
|
||||||
if len(configFolders) == 0 {
|
}
|
||||||
return
|
var dest []string
|
||||||
}
|
for _, folder := range orig {
|
||||||
var filtered []string
|
// When excluding, include things by default, and vice-versa
|
||||||
for _, folder := range dirlist.dirs {
|
include := exclude
|
||||||
for _, cfgfolder := range configFolders {
|
for _, f := range filters {
|
||||||
if folderMatches(folder, cfgfolder) {
|
if folderMatches(folder, f) {
|
||||||
filtered = append(filtered, folder)
|
// If matched an exclusion, don't include
|
||||||
break
|
// If matched an inclusion, do include
|
||||||
|
include = !exclude
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if include {
|
||||||
|
dest = append(dest, folder)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return dest
|
||||||
}
|
}
|
||||||
dirlist.dirs = filtered
|
|
||||||
|
dirlist.dirs = dirlist.store.List()
|
||||||
|
|
||||||
|
// 'folders' (if available) is used to make the initial list and
|
||||||
|
// 'folders-exclude' removes from that list.
|
||||||
|
configFolders := dirlist.acctConf.Folders
|
||||||
|
dirlist.dirs = filterDirs(dirlist.dirs, configFolders, false)
|
||||||
|
|
||||||
|
configFoldersExclude := dirlist.acctConf.FoldersExclude
|
||||||
|
dirlist.dirs = filterDirs(dirlist.dirs, configFoldersExclude, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dirlist *DirectoryList) SelectedMsgStore() (*lib.MessageStore, bool) {
|
func (dirlist *DirectoryList) SelectedMsgStore() (*lib.MessageStore, bool) {
|
||||||
|
|
Loading…
Reference in a new issue