peroxide: Sanitize the quoted printable input before parsing for encryption

Some clients add a single = at the end of the message part causing the parser
to fail.
create-reload-action
Lukasz Janyst 4 years ago
parent f239bca3b1
commit ff91fef274
No known key found for this signature in database
GPG Key ID: 32DE641041F17A9A
  1. 40
      pkg/message/encrypt.go

@ -247,6 +247,40 @@ func (c *Base64Cleaner) Read(b []byte) (int, error) {
return c.r.Read(b)
}
type QuotedPrintableCleaner struct {
r io.Reader
}
func NewQuotedPrintableCleaner(r io.Reader) (*QuotedPrintableCleaner, error) {
reader := bufio.NewReader(r)
var data []byte
for {
line, err := reader.ReadBytes('\n')
if len(line) != 0 {
if len(line) == 1 && line[0] == '=' {
continue
}
data = append(data, line...)
}
if err != nil {
if errors.Is(err, io.EOF) {
break
}
return nil, err
}
}
return &QuotedPrintableCleaner{bytes.NewReader(data)}, nil
}
func (c *QuotedPrintableCleaner) Read(b []byte) (int, error) {
return c.r.Read(b)
}
func getTransferDecoder(r io.Reader, encoding string) (io.Reader, error) {
switch strings.ToLower(encoding) {
case "base64":
@ -257,7 +291,11 @@ func getTransferDecoder(r io.Reader, encoding string) (io.Reader, error) {
return base64.NewDecoder(base64.StdEncoding, cleaner), nil
case "quoted-printable":
return quotedprintable.NewReader(r), nil
cleaner, err := NewQuotedPrintableCleaner(r)
if err != nil {
return nil, err
}
return quotedprintable.NewReader(cleaner), nil
default:
return r, nil

Loading…
Cancel
Save