diff options
author | Reto Brunner <reto@labrat.space> | 2020-01-04 21:13:51 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-01-05 16:02:45 -0500 |
commit | 9096049f757ca0a43ac5cbad7eb27db8c1897d91 (patch) | |
tree | a60080179514c9862b75a16deaf6dc7c82e65baf /widgets/msgviewer.go | |
parent | 19dfc49481c6c8271115658c46ea68a1c977f1d0 (diff) |
FetchBodyParts: decode source in the workers
Previously the workers returned a mixture of decoded / encoded parts.
This lead to a whole bunch of issues.
This commit changes the msgviewer and the commands to assume parts to already
be decoded
Diffstat (limited to 'widgets/msgviewer.go')
-rw-r--r-- | widgets/msgviewer.go | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/widgets/msgviewer.go b/widgets/msgviewer.go index cc883fc..32368ef 100644 --- a/widgets/msgviewer.go +++ b/widgets/msgviewer.go @@ -10,9 +10,6 @@ import ( "strings" "github.com/danwakefield/fnmatch" - message "github.com/emersion/go-message" - _ "github.com/emersion/go-message/charset" - "github.com/emersion/go-message/mail" "github.com/gdamore/tcell" "github.com/google/shlex" "github.com/mattn/go-runewidth" @@ -549,10 +546,6 @@ func (pv *PartViewer) SetSource(reader io.Reader) { func (pv *PartViewer) attemptCopy() { if pv.source != nil && pv.pager != nil && pv.pager.Process != nil { - header := message.Header{} - header.SetText("Content-Transfer-Encoding", pv.part.Encoding) - header.SetContentType(fmt.Sprintf("%s/%s", pv.part.MIMEType, pv.part.MIMESubType), pv.part.Params) - header.SetText("Content-Description", pv.part.Description) if pv.filter != nil { stdout, _ := pv.filter.StdoutPipe() stderr, _ := pv.filter.StderrPipe() @@ -608,28 +601,15 @@ func (pv *PartViewer) attemptCopy() { pv.pagerin.Write([]byte{'\n'}) } - entity, err := message.New(header, pv.source) - if err != nil { - pv.err = err - pv.Invalidate() - return - } - reader := mail.NewReader(entity) - part, err := reader.NextPart() - if err != nil { - pv.err = err - pv.Invalidate() - return - } if pv.part.MIMEType == "text" { - scanner := bufio.NewScanner(part.Body) + scanner := bufio.NewScanner(pv.source) for scanner.Scan() { text := scanner.Text() text = ansi.ReplaceAllString(text, "") io.WriteString(pv.sink, text+"\n") } } else { - io.Copy(pv.sink, part.Body) + io.Copy(pv.sink, pv.source) } pv.sink.Close() }() @@ -653,7 +633,7 @@ func (pv *PartViewer) Draw(ctx *ui.Context) { return } if !pv.fetched { - pv.store.FetchBodyPart(pv.msg.Uid, pv.index, pv.SetSource) + pv.store.FetchBodyPart(pv.msg.Uid, pv.msg.BodyStructure, pv.index, pv.SetSource) pv.fetched = true } if pv.err != nil { |