diff options
author | Reto Brunner <reto@labrat.space> | 2020-11-10 20:27:30 +0100 |
---|---|---|
committer | Reto Brunner <reto@labrat.space> | 2020-11-14 15:40:13 +0100 |
commit | 20ec2c8eeb2e071f28358814935a0f56672a9f49 (patch) | |
tree | 501b43a39a4152872bb6f08221da9c37fc75559c /widgets/aerc.go | |
parent | 3ad3a5ede07c1248ae8176bdc19a623731c64056 (diff) | |
download | aerc-20ec2c8eeb2e071f28358814935a0f56672a9f49.tar.gz |
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.
Diffstat (limited to 'widgets/aerc.go')
-rw-r--r-- | widgets/aerc.go | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/widgets/aerc.go b/widgets/aerc.go index acdd8b4a..b4b4e28f 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) |