about summary refs log tree commit diff stats
path: root/commands/account
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-06-01 19:47:09 -0400
committerDrew DeVault <sir@cmpwn.com>2019-06-01 19:47:09 -0400
commitcf50b987681d00a37f9457ddfa6f8bffb962af3b (patch)
tree396c91eff25f70c60874acffe78b8ce2fb423854 /commands/account
parent56b84d3da5db01c97ec201390dadef2191dda7f4 (diff)
downloadaerc-cf50b987681d00a37f9457ddfa6f8bffb962af3b.tar.gz
Fetch plaintext part when replying
Diffstat (limited to 'commands/account')
-rw-r--r--commands/account/reply.go40
1 files changed, 34 insertions, 6 deletions
diff --git a/commands/account/reply.go b/commands/account/reply.go
index 0e43b88..b0bd346 100644
--- a/commands/account/reply.go
+++ b/commands/account/reply.go
@@ -180,14 +180,24 @@ func Reply(aerc *widgets.Aerc, args []string) error {
 		})
 	} else {
 		if quote {
-			// TODO: something more intelligent than fetching the 1st part
-			store.FetchBodyPart(msg.Uid, []int{1}, func(reader io.Reader) {
+			var (
+				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.SetText(
-					"Content-Transfer-Encoding", msg.BodyStructure.Encoding)
-				header.SetContentType(
-					msg.BodyStructure.MIMEType, msg.BodyStructure.Params)
-				header.SetText("Content-Description", msg.BodyStructure.Description)
+					"Content-Transfer-Encoding", part.Encoding)
+				header.SetContentType(part.MIMEType, part.Params)
+				header.SetText("Content-Description", part.Description)
 				entity, err := message.New(header, reader)
 				if err != nil {
 					// TODO: Do something with the error
@@ -223,3 +233,21 @@ func Reply(aerc *widgets.Aerc, args []string) error {
 
 	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
+}
32efd179005e2ac1f6c60e38'>^
8fa87054 ^


a66c4a26 ^

f027adc0 ^
08f08fb9 ^
d8084b41 ^
08f08fb9 ^
d8084b41 ^

08f08fb9 ^





cba63cf3 ^
3de15ddd ^

d8084b41 ^
24e68318 ^
d8084b41 ^

d36c43ff ^
d8084b41 ^

cba63cf3 ^
b4250dbc ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59