forked from Silverfish/proton-bridge
refactor: don't reconstruct mimeBody
This commit is contained in:
@ -1,11 +1,28 @@
|
||||
// Copyright (c) 2020 Proton Technologies AG
|
||||
//
|
||||
// This file is part of ProtonMail Bridge.
|
||||
//
|
||||
// ProtonMail Bridge is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ProtonMail Bridge is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package parser
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/emersion/go-message"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Parser struct {
|
||||
@ -13,10 +30,10 @@ type Parser struct {
|
||||
root *Part
|
||||
}
|
||||
|
||||
func New(r io.Reader) (*Parser, error) {
|
||||
func New(b []byte) (*Parser, error) {
|
||||
p := new(Parser)
|
||||
|
||||
entity, err := message.Read(r)
|
||||
entity, err := message.Read(bytes.NewReader(b))
|
||||
if err != nil && !message.IsUnknownCharset(err) {
|
||||
return nil, err
|
||||
}
|
||||
@ -70,12 +87,6 @@ func (p *Parser) endPart() {
|
||||
} else {
|
||||
p.root = part
|
||||
}
|
||||
|
||||
if !part.isUTF8() {
|
||||
if err := part.convertToUTF8(); err != nil {
|
||||
logrus.WithError(err).Error("failed to convert part to utf-8")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Parser) top() *Part {
|
||||
|
||||
Reference in New Issue
Block a user