diff options
author | Robin Jarry <robin@jarry.cc> | 2022-12-20 20:29:12 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-01-04 22:57:31 +0100 |
commit | 37e9a924894db7e5f232e82066155a60827c339b (patch) | |
tree | 48deeeea33113bbc9e6fcbcb8973a3ba1d62a06d /config/accounts.go | |
parent | c56027b2e69ec198e41394e5cf906273d80baf79 (diff) | |
download | aerc-37e9a924894db7e5f232e82066155a60827c339b.tar.gz |
config: parse account from and aliases once
Instead of accepting any garbage for these configuration fields, parse
them when parsing accounts.conf and store mail.Address objects. Reuse
these objects everywhere.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
Diffstat (limited to 'config/accounts.go')
-rw-r--r-- | config/accounts.go | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/config/accounts.go b/config/accounts.go index aa4bde29..6cd30098 100644 --- a/config/accounts.go +++ b/config/accounts.go @@ -15,6 +15,7 @@ import ( "time" "git.sr.ht/~rjarry/aerc/log" + "github.com/emersion/go-message/mail" "github.com/go-ini/ini" ) @@ -73,8 +74,8 @@ type AccountConfig struct { CopyTo string `ini:"copy-to"` Default string `ini:"default"` Postpone string `ini:"postpone"` - From string `ini:"from"` - Aliases string `ini:"aliases"` + From *mail.Address `ini:"-"` + Aliases []*mail.Address `ini:"-"` Name string `ini:"-"` Source string `ini:"-"` Folders []string `ini:"folders" delim:","` @@ -163,6 +164,18 @@ func parseAccounts(root string, accts []string) error { return fmt.Errorf("%s=%s %w", key, val, err) } account.Outgoing.CacheCmd = cache + case "from": + addr, err := mail.ParseAddress(val) + if err != nil { + return fmt.Errorf("%s=%s %w", key, val, err) + } + account.From = addr + case "aliases": + addrs, err := mail.ParseAddressList(val) + if err != nil { + return fmt.Errorf("%s=%s %w", key, val, err) + } + account.Aliases = addrs case "subject-re-pattern": re, err := regexp.Compile(val) if err != nil { @@ -205,7 +218,7 @@ func parseAccounts(root string, accts []string) error { if account.Source == "" { return fmt.Errorf("Expected source for account %s", _sec) } - if account.From == "" { + if account.From == nil { return fmt.Errorf("Expected from for account %s", _sec) } |