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
1 changed files with 2 additions and 27 deletions

View File

@ -2,7 +2,6 @@ package imap
import ( import (
"bufio" "bufio"
"bytes"
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io" "io"
@ -61,6 +60,7 @@ func (imapw *IMAPWorker) handleFetchFullMessages(
imapw.worker.Logger.Printf("Fetching full messages") imapw.worker.Logger.Printf("Fetching full messages")
section := &imap.BodySectionName{} section := &imap.BodySectionName{}
items := []imap.FetchItem{ items := []imap.FetchItem{
imap.FetchEnvelope,
imap.FetchFlags, imap.FetchFlags,
imap.FetchUid, imap.FetchUid,
section.FetchItem(), section.FetchItem(),
@ -103,16 +103,11 @@ func (imapw *IMAPWorker) handleFetchMessages(
done <- fmt.Errorf("could not get section %#v", section) done <- fmt.Errorf("could not get section %#v", section)
return return
} }
reader, err := fullReader(r)
if err != nil {
done <- fmt.Errorf("could not read mail %#v", section)
return
}
imapw.worker.PostMessage(&types.FullMessage{ imapw.worker.PostMessage(&types.FullMessage{
Message: types.RespondTo(msg), Message: types.RespondTo(msg),
Content: &models.FullMessage{ Content: &models.FullMessage{
Reader: reader, Reader: bufio.NewReader(r),
Uid: _msg.Uid, Uid: _msg.Uid,
}, },
}, nil) }, nil)
@ -191,26 +186,6 @@ func getDecodedPart(task *types.FetchMessageBodyPart, msg *imap.Message,
return r, err 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 { func encodingReader(encoding string, r io.Reader) io.Reader {
reader := r reader := r
// email parts are encoded as 7bit (plaintext), quoted-printable, or base64 // email parts are encoded as 7bit (plaintext), quoted-printable, or base64