diff options
author | Evan Gates <evan.gates@gmail.com> | 2022-04-05 08:54:58 -0600 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-04-06 15:37:13 +0200 |
commit | 1aa32bf37742770a3243460ca4445256fe4273a7 (patch) | |
tree | 4b06ddf5dbf16bf7af3272115bb357ddaf513e55 /commands/account/compose.go | |
parent | 247c6c74380a9e56527ec0a87965a39142ffc213 (diff) | |
download | aerc-1aa32bf37742770a3243460ca4445256fe4273a7.tar.gz |
compose: parse headers correctly from -H
By using :compose -H <header> a user should be able to add
arbitrary headers to an email. The existing implementation from
5b523880b4b4cd2abd9457b4b09c384af33be14b added the headers as lines
to the beginning of the body. These lines were not interpreted as
headers anywhere and ended up as plain text in the body of the email.
Fix the code to parse and add the headers correctly.
Signed-off-by: Evan Gates <evan.gates@gmail.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'commands/account/compose.go')
-rw-r--r-- | commands/account/compose.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/commands/account/compose.go b/commands/account/compose.go index 4884b113..fc7617ec 100644 --- a/commands/account/compose.go +++ b/commands/account/compose.go @@ -2,9 +2,14 @@ package account import ( "errors" + "fmt" + "io" + gomail "net/mail" "regexp" "strings" + "github.com/emersion/go-message/mail" + "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" "git.sr.ht/~rjarry/aerc/widgets" @@ -38,9 +43,17 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error { template = aerc.Config().Templates.NewMessage } + msg, err := gomail.ReadMessage(strings.NewReader(body)) + if errors.Is(err, io.EOF) { // completely empty + msg = &gomail.Message{Body: strings.NewReader("")} + } else if err != nil { + return fmt.Errorf("mail.ReadMessage: %w", err) + } + headers := mail.HeaderFromMap(msg.Header) + composer, err := widgets.NewComposer(aerc, acct, aerc.Config(), acct.AccountConfig(), acct.Worker(), - template, nil, models.OriginalMail{}) + template, &headers, models.OriginalMail{}) if err != nil { return err } @@ -56,7 +69,7 @@ func (Compose) Execute(aerc *widgets.Aerc, args []string) error { go func() { defer logging.PanicHandler() - composer.AppendContents(strings.NewReader(body)) + composer.AppendContents(msg.Body) }() return nil } |