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
5b523880b4
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>
This commit is contained in:
parent
247c6c7438
commit
1aa32bf377
1 changed files with 15 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue