summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--widgets/msgviewer.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index c7ac44c..ab42ee0 100644
--- a/widgets/msgviewer.go
+++ b/widgets/msgviewer.go
@@ -7,6 +7,8 @@ import (
 	"os/exec"
 
 	"github.com/emersion/go-imap"
+	"github.com/emersion/go-message"
+	"github.com/emersion/go-message/mail"
 	"github.com/gdamore/tcell"
 	"github.com/mattn/go-runewidth"
 
@@ -17,6 +19,7 @@ import (
 
 type MessageViewer struct {
 	cmd    *exec.Cmd
+	msg    *types.MessageInfo
 	source io.Reader
 	sink   io.WriteCloser
 	grid   *ui.Grid
@@ -94,8 +97,9 @@ func NewMessageViewer(store *lib.MessageStore,
 
 	viewer := &MessageViewer{
 		cmd:  cmd,
-		sink: pipe,
 		grid: grid,
+		msg:  msg,
+		sink: pipe,
 		term: term,
 	}
 
@@ -113,8 +117,24 @@ func NewMessageViewer(store *lib.MessageStore,
 
 func (mv *MessageViewer) attemptCopy() {
 	if mv.source != nil && mv.cmd.Process != nil {
+		header := make(message.Header)
+		header.Set("Content-Transfer-Encoding", mv.msg.BodyStructure.Encoding)
+		header.SetContentType(
+			mv.msg.BodyStructure.MIMEType, mv.msg.BodyStructure.Params)
+		header.SetContentDescription(mv.msg.BodyStructure.Description)
 		go func() {
-			io.Copy(mv.sink, mv.source)
+			entity, err := message.New(header, mv.source)
+			if err != nil {
+				io.WriteString(mv.sink, err.Error())
+				return
+			}
+			reader := mail.NewReader(entity)
+			part, err := reader.NextPart()
+			if err != nil {
+				io.WriteString(mv.sink, err.Error())
+				return
+			}
+			io.Copy(mv.sink, part.Body)
 			mv.sink.Close()
 		}()
 	}
gt; 2015-09-30 01:57:23 -0700 2221' href='/akkartik/mu/commit/023boolean.cc?h=main&id=4e49b29e63b0d369b81318ac822dc06ce06786b5'>4e49b29e ^
9dcbec39 ^
4e49b29e ^


bff0fa45 ^
acc4792d ^
bff0fa45 ^


9dcbec39 ^
bff0fa45 ^

4e49b29e ^

98f7918b ^

0487a30e ^
b24eb476 ^
0487a30e ^
0487a30e ^
827898fc ^
98f7918b ^


88be3dbc ^
1ead3562 ^
bc643692 ^

0487a30e ^
98f7918b ^
57699011 ^
98f7918b ^
051c4738 ^
1ead3562 ^
bc643692 ^
0487a30e ^



1ead3562 ^
bc643692 ^
0487a30e ^


051c4738 ^
1ead3562 ^
bc643692 ^
0487a30e ^


1848b18f ^

98f7918b ^
795f5244 ^
e236973b ^
4e49b29e ^
b24eb476 ^
4e49b29e ^
9dcbec39 ^
4e49b29e ^


bff0fa45 ^
acc4792d ^
bff0fa45 ^


9dcbec39 ^
bff0fa45 ^

4e49b29e ^

98f7918b ^

0487a30e ^
b24eb476 ^
0487a30e ^
0487a30e ^
827898fc ^
98f7918b ^


88be3dbc ^
1ead3562 ^
bc643692 ^

0487a30e ^
98f7918b ^
57699011 ^
d7e11237 ^
051c4738 ^
1ead3562 ^
bc643692 ^
0487a30e ^



1ead3562 ^
bc643692 ^
0487a30e ^


051c4738 ^
1ead3562 ^
bc643692 ^
0487a30e ^


1848b18f ^

d7e11237 ^
795f5244 ^
e236973b ^
4e49b29e ^
67a180e3 ^

4e49b29e ^

b24eb476 ^
4e49b29e ^
9dcbec39 ^
4e49b29e ^


b24eb476 ^
bff0fa45 ^

9dcbec39 ^
bff0fa45 ^


4e49b29e ^

d7e11237 ^

e4630643 ^
b24eb476 ^
827898fc ^
0487a30e ^
d7e11237 ^


88be3dbc ^
1ead3562 ^
bc643692 ^
0487a30e ^
d7e11237 ^
57699011 ^
0487a30e ^

1ead3562 ^
bc643692 ^
0487a30e ^



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166