aboutsummaryrefslogtreecommitdiffstats
path: root/config/compose.go
blob: 70533453b52aa8e45edf4c7a5918aa3cfe362e87 (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
package config

import (
	"regexp"

	"git.sr.ht/~rjarry/aerc/log"
	"github.com/go-ini/ini"
)

type ComposeConfig struct {
	Editor              string         `ini:"editor"`
	HeaderLayout        [][]string     `ini:"header-layout" parse:"ParseLayout" default:"To|From,Subject"`
	AddressBookCmd      string         `ini:"address-book-cmd"`
	ReplyToSelf         bool           `ini:"reply-to-self" default:"true"`
	NoAttachmentWarning *regexp.Regexp `ini:"no-attachment-warning" parse:"ParseNoAttachmentWarning"`
	FilePickerCmd       string         `ini:"file-picker-cmd"`
	FormatFlowed        bool           `ini:"format-flowed"`
}

var Compose = new(ComposeConfig)

func parseCompose(file *ini.File) error {
	if err := MapToStruct(file.Section("compose"), Compose, true); err != nil {
		return err
	}
	log.Debugf("aerc.conf: [compose] %#v", Compose)
	return nil
}

func (c *ComposeConfig) ParseLayout(sec *ini.Section, key *ini.Key) ([][]string, error) {
	layout := parseLayout(key.String())
	return layout, nil
}

func (c *ComposeConfig) ParseNoAttachmentWarning(sec *ini.Section, key *ini.Key) (*regexp.Regexp, error) {
	return regexp.Compile(`(?im)` + key.String())
}