aboutsummaryrefslogtreecommitdiffstats
path: root/config/compose.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2022-11-15 00:36:56 +0100
committerRobin Jarry <robin@jarry.cc>2022-11-16 16:12:05 +0100
commitf96172f5064b7245dfdb766163ceee856e2ee51b (patch)
tree3eed51fd23255ca310ecfb3d9e988d914fe5b2b0 /config/compose.go
parent17bb9387c4a3ecab17ace3dc78694c2236a1024f (diff)
downloadaerc-f96172f5064b7245dfdb766163ceee856e2ee51b.tar.gz
config: move [compose] parsing in separate file
The config.go file is getting too big. Move the aerc.conf [compose] section parsing logic into a dedicated compose.go file. No functional change. Signed-off-by: Robin Jarry <robin@jarry.cc> Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'config/compose.go')
-rw-r--r--config/compose.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/config/compose.go b/config/compose.go
new file mode 100644
index 00000000..31ee0a8b
--- /dev/null
+++ b/config/compose.go
@@ -0,0 +1,59 @@
+package config
+
+import (
+ "fmt"
+ "regexp"
+
+ "git.sr.ht/~rjarry/aerc/logging"
+ "github.com/go-ini/ini"
+)
+
+type ComposeConfig struct {
+ Editor string `ini:"editor"`
+ HeaderLayout [][]string `ini:"-"`
+ AddressBookCmd string `ini:"address-book-cmd"`
+ ReplyToSelf bool `ini:"reply-to-self"`
+ NoAttachmentWarning *regexp.Regexp `ini:"-"`
+}
+
+func defaultComposeConfig() ComposeConfig {
+ return ComposeConfig{
+ HeaderLayout: [][]string{
+ {"To", "From"},
+ {"Subject"},
+ },
+ ReplyToSelf: true,
+ }
+}
+
+func (config *AercConfig) parseCompose(file *ini.File) error {
+ compose, err := file.GetSection("compose")
+ if err != nil {
+ goto end
+ }
+
+ if err := compose.MapTo(&config.Compose); err != nil {
+ return err
+ }
+ for key, val := range compose.KeysHash() {
+ if key == "header-layout" {
+ config.Compose.HeaderLayout = parseLayout(val)
+ }
+
+ if key == "no-attachment-warning" && len(val) > 0 {
+ re, err := regexp.Compile("(?im)" + val)
+ if err != nil {
+ return fmt.Errorf(
+ "Invalid no-attachment-warning '%s': %w",
+ val, err,
+ )
+ }
+
+ config.Compose.NoAttachmentWarning = re
+ }
+ }
+
+end:
+ logging.Debugf("aerc.conf: [compose] %#v", config.Compose)
+ return nil
+}