peroxide: Account for long filnames when performing header line unfolding

create-reload-action
Lukasz Janyst 4 years ago
parent 502d4f59bf
commit 08cc3fea46
No known key found for this signature in database
GPG Key ID: 32DE641041F17A9A
  1. 14
      pkg/message/header.go

@ -32,14 +32,23 @@ import (
func HeaderLines(header []byte) [][]byte {
var (
lines [][]byte
quote int
)
forEachLine(bufio.NewReader(bytes.NewReader(header)), func(line []byte) {
l := bytes.SplitN(line, []byte(`: `), 2)
isLineContinuation := !bytes.Equal(bytes.TrimLeftFunc(l[0], unicode.IsSpace), l[0]) // has whitespace indent at beginning
// has whitespace indent at beginning
isLineContinuation := !bytes.Equal(bytes.TrimLeftFunc(l[0], unicode.IsSpace), l[0])
// no quotes opened and we're dealing with MS Word
if quote%2 != 0 && bytes.HasPrefix(lines[len(lines)-1], []byte("Content")) {
isLineContinuation = true
}
switch {
case len(bytes.TrimSpace(line)) == 0:
quote = 0
lines = append(lines, line)
case isLineContinuation:
@ -50,8 +59,11 @@ func HeaderLines(header []byte) [][]byte {
}
default:
quote = 0
lines = append(lines, line)
}
quote += bytes.Count(line, []byte(`"`))
})
return lines

Loading…
Cancel
Save