diff options
author | Robin Jarry <robin@jarry.cc> | 2023-03-07 00:29:20 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-03-31 21:02:26 +0200 |
commit | aec90650f63ff0195599dae817016db137964bcb (patch) | |
tree | 6510fb8b209819a71e3dcf3d21e48c7d382015b7 | |
parent | 2f46f64b0b0b93e99b4754a566c84a08d4563078 (diff) | |
download | aerc-aec90650f63ff0195599dae817016db137964bcb.tar.gz |
config: remove subject contextual ui sections
We have been wanting to remove this for a while now. The only use case
is styleset and changing the whole styleset based on an email subject
does not make much sense. The same feature can be achieve with dynamic
msglist* styles based on any email header value in the stylesets now.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | config/ui.go | 104 | ||||
-rw-r--r-- | doc/aerc-config.5.scd | 10 | ||||
-rw-r--r-- | widgets/msglist.go | 5 |
4 files changed, 57 insertions, 63 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f126d485..cf3c7067 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). of the (now deprecated) `index-format` placeholders. - `[statusline].render-format` has been replaced by `status-columns`. - Removed support for go < 1.17. +- Removed support for `[ui:subject...]` contextual sections in `aerc.conf`. ## [0.14.0](https://git.sr.ht/~rjarry/aerc/refs/0.14.0) - 2023-01-04 diff --git a/config/ui.go b/config/ui.go index 56a59e74..dfd66224 100644 --- a/config/ui.go +++ b/config/ui.go @@ -1,6 +1,7 @@ package config import ( + "bytes" "fmt" "path" "regexp" @@ -87,7 +88,6 @@ type uiContextType int const ( uiContextFolder uiContextType = iota uiContextAccount - uiContextSubject ) type UiConfigContext struct { @@ -108,62 +108,80 @@ var Ui = &UIConfig{ contextualCache: make(map[uiContextKey]*UIConfig), } +var uiContextualSectionRe = regexp.MustCompile(`^ui:(account|folder|subject)([~=])(.+)$`) + func parseUi(file *ini.File) error { if err := Ui.parse(file.Section("ui")); err != nil { return err } - for _, sectionName := range file.SectionStrings() { - if !strings.Contains(sectionName, "ui:") { + var ctxSubjectSections []*ini.Section + + for _, section := range file.Sections() { + var err error + groups := uiContextualSectionRe.FindStringSubmatch(section.Name()) + if groups == nil { continue } - - uiSection, err := file.GetSection(sectionName) - if err != nil { - return err + ctx, separator, value := groups[1], groups[2], groups[3] + if ctx == "subject" { + log.Warnf( + "%s contextual subject config has been replaced by dynamic msglist_* styles.", + section.Name()) + ctxSubjectSections = append(ctxSubjectSections, section) + continue } + uiSubConfig := UIConfig{} - if err := uiSubConfig.parse(uiSection); err != nil { + if err = uiSubConfig.parse(section); err != nil { return err } contextualUi := UiConfigContext{ UiConfig: &uiSubConfig, } - var index int - switch { - case strings.Contains(sectionName, "~"): - index = strings.Index(sectionName, "~") - regex := string(sectionName[index+1:]) - contextualUi.Regex, err = regexp.Compile(regex) - if err != nil { - return err - } - case strings.Contains(sectionName, "="): - index = strings.Index(sectionName, "=") - value := string(sectionName[index+1:]) - contextualUi.Regex, err = regexp.Compile(regexp.QuoteMeta(value)) - if err != nil { - return err - } - default: - return fmt.Errorf("Invalid Ui Context regex in %s", sectionName) - } - - switch sectionName[3:index] { + switch ctx { case "account": contextualUi.ContextType = uiContextAccount case "folder": contextualUi.ContextType = uiContextFolder - case "subject": - contextualUi.ContextType = uiContextSubject - default: - return fmt.Errorf("Unknown Contextual Ui Section: %s", sectionName) } + if separator == "=" { + value = "^" + regexp.QuoteMeta(value) + "$" + } + contextualUi.Regex, err = regexp.Compile(value) + if err != nil { + return err + } + Ui.contextualUis = append(Ui.contextualUis, &contextualUi) Ui.contextualCounts[contextualUi.ContextType]++ } + if len(ctxSubjectSections) > 0 { + f := ini.Empty() + for _, sec := range ctxSubjectSections { + s, _ := f.NewSection(sec.Name()) + for k, v := range sec.KeysHash() { + s.NewKey(k, v) //nolint:errcheck // who cares? + } + } + var buf bytes.Buffer + f.WriteTo(&buf) //nolint:errcheck // who cares? + w := Warning{ + Title: "DEPRECATION WARNING: SUBJECT UI SECTIONS", + Body: fmt.Sprintf(` +Contextual UI configuration based on subject value has been deprecated and +replaced by dynamic msglist_* styles in stylesets. + +The following configuration sections from aerc.conf have been ignored: + +%sYou should remove them to get rid of that warning and update your styleset(s) +accordingly. See aerc-stylesets(7) for more details.`, buf.String()), + } + Warnings = append(Warnings, w) + } + // append default paths to styleset-dirs for _, dir := range SearchDirs { Ui.StyleSetDirs = append( @@ -521,16 +539,11 @@ func (uiConfig *UIConfig) StyleSetPath() string { return uiConfig.style.path } -func (base *UIConfig) contextual( - ctxType uiContextType, value string, useCache bool, -) *UIConfig { +func (base *UIConfig) contextual(ctxType uiContextType, value string) *UIConfig { if base.contextualCounts[ctxType] == 0 { // shortcut if no contextual ui for that type return base } - if !useCache { - return base.mergeContextual(ctxType, value) - } key := uiContextKey{ctxType: ctxType, value: value} c, found := base.contextualCache[key] if !found { @@ -541,18 +554,9 @@ func (base *UIConfig) contextual( } func (base *UIConfig) ForAccount(account string) *UIConfig { - return base.contextual(uiContextAccount, account, true) + return base.contextual(uiContextAccount, account) } func (base *UIConfig) ForFolder(folder string) *UIConfig { - return base.contextual(uiContextFolder, folder, true) -} - -func (base *UIConfig) ForSubject(subject string) *UIConfig { - // TODO: this [ui:subject] contextual config should be dropped and - // replaced by another solution. Possibly something in the stylesets. - // Do not use a cache for contextual subject config as this - // could consume all available memory given enough time and - // enough messages. - return base.contextual(uiContextSubject, subject, false) + return base.contextual(uiContextFolder, folder) } diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd index faa79cad..54c7df7f 100644 --- a/doc/aerc-config.5.scd +++ b/doc/aerc-config.5.scd @@ -385,8 +385,7 @@ directories and message subjects. The specializations are added using contextual config sections based on the context. The contextual UI configuration is merged to the base UiConfig in the -following order: -*Base UIConfig > Account Context > Folder Context > Subject Context.* +following order: *Base UIConfig > Account Context > Folder Context*. *[ui:account=*_AccountName_*]* Adds account specific configuration with the account name. @@ -398,10 +397,6 @@ following order: Add folder specific configuration for folders whose names match the regular expression. -*[ui:subject~*_Regex_*]* - Add specialized ui configuration for messages that match a given regular - expression. - Example: ``` [ui:account=Work] @@ -412,9 +407,6 @@ index-format=... [ui:folder~Archive/\d+/.*] index-format=... - -[ui:subject~^\[PATCH] -index-format=... ``` # STATUSLINE diff --git a/widgets/msglist.go b/widgets/msglist.go index 0937b786..161dcadc 100644 --- a/widgets/msglist.go +++ b/widgets/msglist.go @@ -222,7 +222,7 @@ func addMessage( msg := store.Messages[uid] cells := make([]string, len(table.Columns)) - params := messageRowParams{uid: uid} + params := messageRowParams{uid: uid, uiConfig: uiConfig} if msg == nil || msg.Envelope == nil { params.needsHeaders = true @@ -267,9 +267,6 @@ func addMessage( } } - // TODO deprecate subject contextual UIs? Only related setting is - // styleset, should implement a better per-message styling method - params.uiConfig = uiConfig.ForSubject(msg.Envelope.Subject) params.headers = msg.RFC822Headers return table.AddRow(cells, params) |