summaryrefslogtreecommitdiff
path: root/commands/msg/reply.go
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-05-17 12:08:17 +0200
committerReto Brunner <reto@labrat.space>2020-05-17 12:08:17 +0200
commitcff4476f3bb61510acefd567deb39f58351de215 (patch)
treeb319b346445ca18dae980db19e290ac54b25c03f /commands/msg/reply.go
parent13a6a3fa7109ce6dcff79ea9ed2a012226386fad (diff)
downloadaerc-cff4476f3bb61510acefd567deb39f58351de215.zip
msg/reply: fix encoding issues for quoted reply.
Diffstat (limited to 'commands/msg/reply.go')
-rw-r--r--commands/msg/reply.go38
1 files changed, 29 insertions, 9 deletions
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 72c992e..e4c4577 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -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
}