GODT-1193: Don't doubly encode parts

This commit is contained in:
James Houlahan
2021-06-15 15:01:11 +02:00
parent fb98a797ba
commit ef1223391b
5 changed files with 116 additions and 24 deletions

View File

@ -85,11 +85,14 @@ func readHeaderBody(b []byte) (*textproto.Header, []byte, error) {
return nil, nil, err
}
lines := HeaderLines(rawHeader)
var header textproto.Header
for _, line := range HeaderLines(rawHeader) {
if len(bytes.TrimSpace(line)) > 0 {
header.AddRaw(line)
// We add lines in reverse so that calling textproto.WriteHeader later writes with the correct order.
for i := len(lines) - 1; i >= 0; i-- {
if len(bytes.TrimSpace(lines[i])) > 0 {
header.AddRaw(lines[i])
}
}