mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 05:40:50 +01:00
v0.1.6b: writeHeader() was producing double spaces at line breaks
This commit is contained in:
parent
b852a5281a
commit
d448f0566b
1 changed files with 12 additions and 8 deletions
20
msgwriter.go
20
msgwriter.go
|
@ -199,31 +199,35 @@ func (mw *msgWriter) writeString(s string) {
|
|||
|
||||
// writeHeader writes a header into the msgWriter's io.Writer
|
||||
func (mw *msgWriter) writeHeader(k Header, vl ...string) {
|
||||
// Chars left: MaxHeaderLength - "<Headername>: " - "CRLF"
|
||||
wbuf := bytes.Buffer{}
|
||||
cl := MaxHeaderLength - 2
|
||||
mw.writeString(string(k))
|
||||
wbuf.WriteString(string(k))
|
||||
cl -= len(k)
|
||||
if len(vl) == 0 {
|
||||
mw.writeString(":\r\n")
|
||||
wbuf.WriteString(":\r\n")
|
||||
return
|
||||
}
|
||||
mw.writeString(": ")
|
||||
wbuf.WriteString(": ")
|
||||
cl -= 2
|
||||
|
||||
fs := strings.Join(vl, ", ")
|
||||
sfs := strings.Split(fs, " ")
|
||||
for i, v := range sfs {
|
||||
if cl-len(v) <= 1 {
|
||||
mw.writeString("\r\n ")
|
||||
wbuf.WriteString("\r\n ")
|
||||
cl = MaxHeaderLength - 3
|
||||
}
|
||||
mw.writeString(v)
|
||||
if i < len(sfs) {
|
||||
mw.writeString(" ")
|
||||
wbuf.WriteString(v)
|
||||
if i < len(sfs)-1 {
|
||||
wbuf.WriteString(" ")
|
||||
cl -= 1
|
||||
}
|
||||
cl -= len(v)
|
||||
}
|
||||
|
||||
bufs := wbuf.String()
|
||||
bufs = strings.ReplaceAll(bufs, " \r\n", "\r\n")
|
||||
mw.writeString(bufs)
|
||||
mw.writeString("\r\n")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue