From 0abafa60e159f87595148c0d0fc4f5f46be2d400 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 31 Mar 2019 12:35:51 -0400 Subject: Make message viewer real, part two --- widgets/account.go | 2 +- widgets/msgviewer.go | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) (limited to 'widgets') diff --git a/widgets/account.go b/widgets/account.go index f26d8389..f8abdc94 100644 --- a/widgets/account.go +++ b/widgets/account.go @@ -173,7 +173,7 @@ func (acct *AccountView) onMessage(msg types.WorkerMessage) { case *types.DirectoryContents: store := acct.msgStores[acct.dirlist.selected] store.Update(msg) - case *types.MessageBody: + case *types.FullMessage: store := acct.msgStores[acct.dirlist.selected] store.Update(msg) case *types.MessageInfo: diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index 2c77aeb4..c7ac44c3 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -16,10 +16,11 @@ import ( ) type MessageViewer struct { - mail io.Reader - pipe io.Writer - grid *ui.Grid - term *Terminal + cmd *exec.Cmd + source io.Reader + sink io.WriteCloser + grid *ui.Grid + term *Terminal } func formatAddresses(addrs []*imap.Address) string { @@ -92,22 +93,33 @@ func NewMessageViewer(store *lib.MessageStore, grid.AddChild(body).At(1, 0) viewer := &MessageViewer{ - pipe: pipe, + cmd: cmd, + sink: pipe, grid: grid, term: term, } store.FetchBodyPart(msg.Uid, 0, func(reader io.Reader) { - viewer.mail = reader - go func() { - io.Copy(pipe, reader) - pipe.Close() - }() + viewer.source = reader + viewer.attemptCopy() }) + term.OnStart = func() { + viewer.attemptCopy() + } + return viewer } +func (mv *MessageViewer) attemptCopy() { + if mv.source != nil && mv.cmd.Process != nil { + go func() { + io.Copy(mv.sink, mv.source) + mv.sink.Close() + }() + } +} + func (mv *MessageViewer) Draw(ctx *ui.Context) { mv.grid.Draw(ctx) } -- cgit