summary refs log tree commit diff stats
path: root/worker
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-01-04 21:13:53 +0100
committerDrew DeVault <sir@cmpwn.com>2020-01-05 16:02:46 -0500
commitda6fb1a1551767609e1d5a97631bdaffdc301f4c (patch)
treecff4182395d046c219ebb6171a65ce03044ed4c8 /worker
parent3d85f75d9c38d2ddd34325ea4343423c9f3431fb (diff)
downloadaerc-da6fb1a1551767609e1d5a97631bdaffdc301f4c.tar.gz
maildir/notmuch: don't re-encode readers
Diffstat (limited to 'worker')
-rw-r--r--worker/lib/parse.go41
1 files changed, 4 insertions, 37 deletions
diff --git a/worker/lib/parse.go b/worker/lib/parse.go
index eed39cb..288dade 100644
--- a/worker/lib/parse.go
+++ b/worker/lib/parse.go
@@ -2,10 +2,8 @@ package lib
 
 import (
 	"bytes"
-	"encoding/base64"
 	"fmt"
 	"io"
-	"mime/quotedprintable"
 	"strings"
 
 	"git.sr.ht/~sircmpwn/aerc/models"
@@ -29,7 +27,7 @@ func FetchEntityPartReader(e *message.Entity, index []int) (io.Reader, error) {
 			if idx == index[0] {
 				rest := index[1:]
 				if len(rest) < 1 {
-					return fetchEntityReader(part)
+					return bufReader(part)
 				}
 				return FetchEntityPartReader(part, index[1:])
 			}
@@ -38,46 +36,15 @@ func FetchEntityPartReader(e *message.Entity, index []int) (io.Reader, error) {
 	if index[0] != 1 {
 		return nil, fmt.Errorf("cannont return non-first part of non-multipart")
 	}
-	return fetchEntityReader(e)
+	return bufReader(e)
 }
 
-// fetchEntityReader makes an io.Reader for the given entity. Since the
-// go-message package decodes the body for us, and the UI expects to deal with
-// a reader whose bytes are encoded with the part's encoding, we are in the
-// interesting position of needing to re-encode the reader before sending it
-// off to the UI layer.
-//
-// TODO: probably change the UI to expect an already-decoded reader and decode
-// in the IMAP worker.
-func fetchEntityReader(e *message.Entity) (io.Reader, error) {
-	enc := e.Header.Get("content-transfer-encoding")
+//TODO: the UI doesn't seem to like readers which aren't buffers
+func bufReader(e *message.Entity) (io.Reader, error) {
 	var buf bytes.Buffer
-
-	// base64
-	if strings.EqualFold(enc, "base64") {
-		wc := base64.NewEncoder(base64.StdEncoding, &buf)
-		defer wc.Close()
-		if _, err := io.Copy(wc, e.Body); err != nil {
-			return nil, fmt.Errorf("could not base64 encode: %v", err)
-		}
-		return &buf, nil
-	}
-
-	// quoted-printable
-	if strings.EqualFold(enc, "quoted-printable") {
-		wc := quotedprintable.NewWriter(&buf)
-		defer wc.Close()
-		if _, err := io.Copy(wc, e.Body); err != nil {
-			return nil, fmt.Errorf("could not quoted-printable encode: %v", err)
-		}
-		return &buf, nil
-	}
-
-	// other general encoding
 	if _, err := io.Copy(&buf, e.Body); err != nil {
 		return nil, err
 	}
-
 	return &buf, nil
 }