From 20ec2c8eeb2e071f28358814935a0f56672a9f49 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Tue, 10 Nov 2020 20:27:30 +0100 Subject: compose: use a proper header instead of a string map Prior to this commit, the composer was based on a map[string]string. While this approach was very versatile, it lead to a constant encoding / decoding of addresses and other headers. This commit switches to a different model, where the composer is based on a header. Commands which want to interact with it can simply set some defaults they would like to have. Users can overwrite them however they like. In order to get access to the functions generating / getting the msgid go-message was upgraded. --- widgets/aerc.go | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'widgets/aerc.go') diff --git a/widgets/aerc.go b/widgets/aerc.go index acdd8b4..b4b4e28 100644 --- a/widgets/aerc.go +++ b/widgets/aerc.go @@ -9,6 +9,7 @@ import ( "strings" "time" + "github.com/emersion/go-message/mail" "github.com/gdamore/tcell" "github.com/google/shlex" "golang.org/x/crypto/openpgp" @@ -496,27 +497,38 @@ func (aerc *Aerc) Mailto(addr *url.URL) error { if acct == nil { return errors.New("No account selected") } - defaults := make(map[string]string) - defaults["To"] = addr.Opaque - headerMap := map[string]string{ - "cc": "Cc", - "in-reply-to": "In-Reply-To", - "subject": "Subject", - } + + var subject string + h := &mail.Header{} + h.SetAddressList("to", []*mail.Address{&mail.Address{Address: addr.Opaque}}) for key, vals := range addr.Query() { - if header, ok := headerMap[strings.ToLower(key)]; ok { - defaults[header] = strings.Join(vals, ",") + switch strings.ToLower(key) { + case "cc": + list, err := mail.ParseAddressList(strings.Join(vals, ",")) + if err != nil { + break + } + h.SetAddressList("Cc", list) + case "in-reply-to": + h.SetMsgIDList("In-Reply-To", vals) + case "subject": + subject = strings.Join(vals, ",") + h.SetText("Subject", subject) + default: + // any other header gets ignored on purpose to avoid control headers + // being injected } } + composer, err := NewComposer(aerc, acct, aerc.Config(), - acct.AccountConfig(), acct.Worker(), "", defaults, models.OriginalMail{}) + acct.AccountConfig(), acct.Worker(), "", h, models.OriginalMail{}) if err != nil { return nil } composer.FocusSubject() title := "New email" - if subj, ok := defaults["Subject"]; ok { - title = subj + if subject != "" { + title = subject composer.FocusTerminal() } tab := aerc.NewTab(composer, title) -- cgit 1.4.1-2-gfad0