msg/reply: fix encoding issues for quoted reply.

This commit is contained in:
Reto Brunner 2020-05-17 12:08:17 +02:00
parent 13a6a3fa71
commit cff4476f3b
2 changed files with 33 additions and 12 deletions

View file

@ -107,9 +107,10 @@ func (Recall) Execute(aerc *widgets.Aerc, args []string) error {
part *models.BodyStructure
)
if len(msgInfo.BodyStructure.Parts) != 0 {
part, path = findPlaintext(msgInfo.BodyStructure, path)
path = findPlaintext(msgInfo.BodyStructure, path)
}
if part == nil {
part, err = msgInfo.BodyStructure.PartAtIndex(path)
if part == nil || err != nil {
part = msgInfo.BodyStructure
path = []int{1}
}

View file

@ -165,7 +165,16 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
template = aerc.Config().Templates.QuotedReply
}
store.FetchBodyPart(msg.Uid, []int{1}, func(reader io.Reader) {
part := findPlaintext(msg.BodyStructure, nil)
if part == nil {
//mkey... let's get the first thing that isn't a container
part := findFirstNonMultipart(msg.BodyStructure, nil)
if part == nil {
// give up, use whatever is first
part = []int{1}
}
}
store.FetchBodyPart(msg.Uid, part, func(reader io.Reader) {
buf := new(bytes.Buffer)
buf.ReadFrom(reader)
original.Text = buf.String()
@ -188,22 +197,33 @@ func (reply) Execute(aerc *widgets.Aerc, args []string) error {
}
}
//TODO (RPB): unused function
func findPlaintext(bs *models.BodyStructure,
path []int) (*models.BodyStructure, []int) {
func findPlaintext(bs *models.BodyStructure, path []int) []int {
for i, part := range bs.Parts {
cur := append(path, i+1)
if strings.ToLower(part.MIMEType) == "text" &&
strings.ToLower(part.MIMESubType) == "plain" {
return part, cur
return cur
}
if strings.ToLower(part.MIMEType) == "multipart" {
if part, path := findPlaintext(part, cur); path != nil {
return part, path
if path := findPlaintext(part, cur); path != nil {
return path
}
}
}
return nil
}
return nil, nil
func findFirstNonMultipart(bs *models.BodyStructure, path []int) []int {
for i, part := range bs.Parts {
cur := append(path, i+1)
mimetype := strings.ToLower(part.MIMEType)
if mimetype != "multipart" {
return path
} else if mimetype == "multipart" {
if path := findPlaintext(part, cur); path != nil {
return path
}
}
}
return nil
}