Fetch plaintext part when replying
This commit is contained in:
parent
56b84d3da5
commit
cf50b98768
1 changed files with 34 additions and 6 deletions
|
@ -180,14 +180,24 @@ func Reply(aerc *widgets.Aerc, args []string) error {
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if quote {
|
if quote {
|
||||||
// TODO: something more intelligent than fetching the 1st part
|
var (
|
||||||
store.FetchBodyPart(msg.Uid, []int{1}, func(reader io.Reader) {
|
path []int
|
||||||
|
part *imap.BodyStructure
|
||||||
|
)
|
||||||
|
if len(msg.BodyStructure.Parts) != 0 {
|
||||||
|
part, path = findPlaintext(msg.BodyStructure, path)
|
||||||
|
}
|
||||||
|
if part == nil {
|
||||||
|
part = msg.BodyStructure
|
||||||
|
path = []int{1}
|
||||||
|
}
|
||||||
|
|
||||||
|
store.FetchBodyPart(msg.Uid, path, func(reader io.Reader) {
|
||||||
header := message.Header{}
|
header := message.Header{}
|
||||||
header.SetText(
|
header.SetText(
|
||||||
"Content-Transfer-Encoding", msg.BodyStructure.Encoding)
|
"Content-Transfer-Encoding", part.Encoding)
|
||||||
header.SetContentType(
|
header.SetContentType(part.MIMEType, part.Params)
|
||||||
msg.BodyStructure.MIMEType, msg.BodyStructure.Params)
|
header.SetText("Content-Description", part.Description)
|
||||||
header.SetText("Content-Description", msg.BodyStructure.Description)
|
|
||||||
entity, err := message.New(header, reader)
|
entity, err := message.New(header, reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: Do something with the error
|
// TODO: Do something with the error
|
||||||
|
@ -223,3 +233,21 @@ func Reply(aerc *widgets.Aerc, args []string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findPlaintext(bs *imap.BodyStructure,
|
||||||
|
path []int) (*imap.BodyStructure, []int) {
|
||||||
|
|
||||||
|
for i, part := range bs.Parts {
|
||||||
|
cur := append(path, i+1)
|
||||||
|
if part.MIMEType == "text" && part.MIMESubType == "plain" {
|
||||||
|
return part, cur
|
||||||
|
}
|
||||||
|
if part.MIMEType == "multipart" {
|
||||||
|
if part, path := findPlaintext(bs, cur); path != nil {
|
||||||
|
return part, path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue