From 08cc3fea46c74b91bee8d2c12cfe8a4d25ab43c0 Mon Sep 17 00:00:00 2001 From: Lukasz Janyst Date: Thu, 26 May 2022 17:12:00 +0200 Subject: [PATCH] peroxide: Account for long filnames when performing header line unfolding --- pkg/message/header.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/message/header.go b/pkg/message/header.go index c89ebb7..5edef4f 100644 --- a/pkg/message/header.go +++ b/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