diff options
-rw-r--r-- | config/accounts.go | 93 | ||||
-rw-r--r-- | config/binds.go | 2 | ||||
-rw-r--r-- | config/config.go | 2 | ||||
-rw-r--r-- | widgets/account-wizard.go | 18 |
4 files changed, 56 insertions, 59 deletions
diff --git a/config/accounts.go b/config/accounts.go index eec6ca44..a8c2b9bf 100644 --- a/config/accounts.go +++ b/config/accounts.go @@ -146,27 +146,11 @@ func parseAccounts(root string, accts []string) error { continue } sec := file.Section(_sec) - account := AccountConfig{ - Name: _sec, - Params: make(map[string]string), - } - if err = MapToStruct(sec, &account, true); err != nil { + + account, err := ParseAccountConfig(_sec, sec) + if err != nil { return err } - for key, val := range sec.KeysHash() { - backendSpecific := true - typ := reflect.TypeOf(account) - for i := 0; i < typ.NumField(); i++ { - field := typ.Field(i) - if field.Tag.Get("ini") == key { - backendSpecific = false - break - } - } - if backendSpecific { - account.Params[key] = val - } - } if _, ok := account.Params["smtp-starttls"]; ok && !starttls_warned { Warnings = append(Warnings, Warning{ Title: "accounts.conf: smtp-starttls is deprecated", @@ -178,31 +162,9 @@ If you want to disable STARTTLS, append +insecure to the schema. }) starttls_warned = true } - if account.Source == "" { - return fmt.Errorf("Expected source for account %s", _sec) - } - if account.From == nil { - return fmt.Errorf("Expected from for account %s", _sec) - } - if len(account.Headers) > 0 { - defaults := []string{ - "date", - "subject", - "from", - "sender", - "reply-to", - "to", - "cc", - "bcc", - "in-reply-to", - "message-id", - "references", - } - account.Headers = append(account.Headers, defaults...) - } log.Debugf("accounts.conf: [%s] from = %s", account.Name, account.From) - Accounts = append(Accounts, &account) + Accounts = append(Accounts, account) } if len(accts) > 0 { // Sort accounts struct to match the specified order, if we @@ -218,6 +180,53 @@ If you want to disable STARTTLS, append +insecure to the schema. return nil } +func ParseAccountConfig(name string, section *ini.Section) (*AccountConfig, error) { + account := AccountConfig{ + Name: name, + Params: make(map[string]string), + } + if err := MapToStruct(section, &account, true); err != nil { + return nil, err + } + for key, val := range section.KeysHash() { + backendSpecific := true + typ := reflect.TypeOf(account) + for i := 0; i < typ.NumField(); i++ { + field := typ.Field(i) + if field.Tag.Get("ini") == key { + backendSpecific = false + break + } + } + if backendSpecific { + account.Params[key] = val + } + } + if account.Source == "" { + return nil, fmt.Errorf("Expected source for account %s", name) + } + if account.From == nil { + return nil, fmt.Errorf("Expected from for account %s", name) + } + if len(account.Headers) > 0 { + defaults := []string{ + "date", + "subject", + "from", + "sender", + "reply-to", + "to", + "cc", + "bcc", + "in-reply-to", + "message-id", + "references", + } + account.Headers = append(account.Headers, defaults...) + } + return &account, nil +} + func (a *AccountConfig) ParseSource(sec *ini.Section, key *ini.Key) (string, error) { var remote RemoteConfig remote.Value = key.String() diff --git a/config/binds.go b/config/binds.go index 55814cd2..b219adad 100644 --- a/config/binds.go +++ b/config/binds.go @@ -101,7 +101,7 @@ var Binds = defaultBindsConfig() func parseBinds(root string) error { filename := path.Join(root, "binds.conf") if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { - fmt.Printf("%s not found, installing the system default", filename) + fmt.Printf("%s not found, installing the system default\n", filename) if err := installTemplate(root, "binds.conf"); err != nil { return err } diff --git a/config/config.go b/config/config.go index d70bcfe0..4ace7d26 100644 --- a/config/config.go +++ b/config/config.go @@ -98,7 +98,7 @@ func LoadConfigFromFile(root *string, accts []string) error { // if it doesn't exist copy over the template, then load if _, err := os.Stat(filename); errors.Is(err, os.ErrNotExist) { - fmt.Printf("%s not found, installing the system default", filename) + fmt.Printf("%s not found, installing the system default\n", filename) if err := installTemplate(*root, "aerc.conf"); err != nil { return err } diff --git a/widgets/account-wizard.go b/widgets/account-wizard.go index 9ad814b5..8c9739e6 100644 --- a/widgets/account-wizard.go +++ b/widgets/account-wizard.go @@ -13,7 +13,6 @@ import ( "sync" "time" - "github.com/emersion/go-message/mail" "github.com/gdamore/tcell/v2" "github.com/go-ini/ini" "github.com/kyoh86/xdg" @@ -531,25 +530,14 @@ func (wizard *AccountWizard) finish(tutorial bool) { } } - from, err := mail.ParseAddress(sec.Key("from").String()) + account, err := config.ParseAccountConfig(sec.Name(), sec) if err != nil { wizard.errorFor(nil, err) return } + config.Accounts = append(config.Accounts, account) - account := config.AccountConfig{ - Name: sec.Name(), - Default: "INBOX", - From: from, - Source: sec.Key("source").String(), - Outgoing: config.RemoteConfig{Value: sec.Key("outgoing").String()}, - } - if wizard.copySent { - account.CopyTo = "Sent" - } - config.Accounts = append(config.Accounts, &account) - - view, err := NewAccountView(wizard.aerc, &account, wizard.aerc, nil) + view, err := NewAccountView(wizard.aerc, account, wizard.aerc, nil) if err != nil { wizard.aerc.NewTab(errorScreen(err.Error()), account.Name) return |