aboutsummaryrefslogtreecommitdiffstats
path: root/config/compose.go
blob: 14a3087b6a8ff94762f83842e15e3a8d8ad57f1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package config

import (
	"fmt"
	"regexp"

	"git.sr.ht/~rjarry/aerc/log"
	"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:"-"`
	FilePickerCmd       string         `ini:"file-picker-cmd"`
	FormatFlowed        bool           `ini:"format-flowed"`
}

func defaultComposeConfig() *ComposeConfig {
	return &ComposeConfig{
		HeaderLayout: [][]string{
			{"To", "From"},
			{"Subject"},
		},
		ReplyToSelf: true,
	}
}

var Compose = defaultComposeConfig()

func parseCompose(file *ini.File) error {
	compose, err := file.GetSection("compose")
	if err != nil {
		goto end
	}

	if err := compose.MapTo(&Compose); err != nil {
		return err
	}
	for key, val := range compose.KeysHash() {
		if key == "header-layout" {
			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,
				)
			}

			Compose.NoAttachmentWarning = re
		}
	}

end:
	log.Debugf("aerc.conf: [compose] %#v", Compose)
	return nil
}