aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-03-31 13:36:37 -0400
committerDrew DeVault <sir@cmpwn.com>2019-03-31 13:36:37 -0400
commit711d22891bd50646d1cf925fbf0b8a760c638fd0 (patch)
tree3a233f54977043c3601939507c1ac8c80b5319e5
parent56ea7f0e430bc44f8b652ef88bedb186b6b3e0df (diff)
downloadaerc-711d22891bd50646d1cf925fbf0b8a760c638fd0.tar.gz
Decode messages before rendering them
-rw-r--r--widgets/msgviewer.go24
1 files changed, 22 insertions, 2 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go
index c7ac44c3..ab42ee04 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()
}()
}