summary refs log tree commit diff stats
path: root/commands
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
parent13a6a3fa7109ce6dcff79ea9ed2a012226386fad (diff)
downloadaerc-cff4476f3bb61510acefd567deb39f58351de215.tar.gz
msg/reply: fix encoding issues for quoted reply.
Diffstat (limited to 'commands')
-rw-r--r--commands/msg/recall.go5
-rw-r--r--commands/msg/reply.go38
2 files changed, 32 insertions, 11 deletions
diff --git a/commands/msg/recall.go b/commands/msg/recall.go
index ef7e859..7c9ac19 100644
--- a/commands/msg/recall.go
+++ b/commands/msg/recall.go
@@ -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}
 	}
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
 }