1
0
mirror of https://git.sr.ht/~sircmpwn/aerc synced 2024-11-23 08:32:12 +01:00

worker/imap: don't decode in FetchFullMessage.

Doing that breaks `git am` as it expected the encoded variant.
Same is probably true for any sort of signature validation (gpg / dkim)
This commit is contained in:
Reto Brunner 2020-01-19 00:59:20 +01:00 committed by Drew DeVault
parent 686ca24405
commit 472c421e85

@ -2,7 +2,6 @@ package imap
import (
"bufio"
"bytes"
"encoding/base64"
"fmt"
"io"
@ -61,6 +60,7 @@ func (imapw *IMAPWorker) handleFetchFullMessages(
imapw.worker.Logger.Printf("Fetching full messages")
section := &imap.BodySectionName{}
items := []imap.FetchItem{
imap.FetchEnvelope,
imap.FetchFlags,
imap.FetchUid,
section.FetchItem(),
@ -103,16 +103,11 @@ func (imapw *IMAPWorker) handleFetchMessages(
done <- fmt.Errorf("could not get section %#v", section)
return
}
reader, err := fullReader(r)
if err != nil {
done <- fmt.Errorf("could not read mail %#v", section)
return
}
imapw.worker.PostMessage(&types.FullMessage{
Message: types.RespondTo(msg),
Content: &models.FullMessage{
Reader: reader,
Reader: bufio.NewReader(r),
Uid: _msg.Uid,
},
}, nil)
@ -191,26 +186,6 @@ func getDecodedPart(task *types.FetchMessageBodyPart, msg *imap.Message,
return r, err
}
func fullReader(r io.Reader) (io.Reader, error) {
// parse the header for the encoding and also return it in the reader
br := bufio.NewReader(r)
textprotoHeader, err := textproto.ReadHeader(br)
if err != nil {
return nil, err
}
header := &mail.Header{message.Header{textprotoHeader}}
enc := header.Get("Content-Transfer-Encoding")
var buf bytes.Buffer
err = textproto.WriteHeader(&buf, textprotoHeader)
if err != nil {
return nil, err
}
er := encodingReader(enc, br)
full := io.MultiReader(&buf, er)
return full, nil
}
func encodingReader(encoding string, r io.Reader) io.Reader {
reader := r
// email parts are encoded as 7bit (plaintext), quoted-printable, or base64