From 8dcb58c81782a30f06794227cf9a1b54928134e3 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 29 Jun 2023 09:21:04 +0200 Subject: wizard: properly initialize configuration The wizard constructs an AccountConfig object by hand without initializing default values. This causes a crash when replying to an email (rr) just after completing the account creation: ~/.config/aerc/aerc.conf not found, installing the system default~/.config/aerc/binds.conf not found, installing the system defaultpanic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x90 pc=0x5d1550] ... regexp.(*Regexp).doExecute(0x7fc1089aa108?, {0x0?, 0x0?}, {0x0?, 0x0?, 0xc000fe5408?}, {0xc000698120?, 0x10?}, 0xad3a40?, 0x2, ...) regexp/exec.go:527 +0x90 regexp.(*Regexp).FindString(0x44e372?, {0xc000698120, 0x27}) regexp/regexp.go:852 +0x6c git.sr.ht/~rjarry/aerc/commands/msg.trimLocalizedRe({0xc000698120, 0x27}, 0xc00003e420?) git.sr.ht/~rjarry/aerc/commands/msg/reply.go:332 +0x36 git.sr.ht/~rjarry/aerc/commands/msg.reply.Execute({}, 0xc0002ba180, {0xc0002f8800?, 0x2, 0x2}) git.sr.ht/~rjarry/aerc/commands/msg/reply.go:157 +0x765 ... Extract the account parsing and initialization into a function. Reuse that function in both accounts.conf parsing and the wizard. Fixes: 40cc540357d9 ("reply: allow to override localized Re regexp in configuration") Reported-by: Mechiel Lukkien Signed-off-by: Robin Jarry Tested-by: Andrew Yu --- widgets/account-wizard.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'widgets') 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 -- cgit