Skip to content

Commit 8d65d23

Browse files
author
frederic.leist
committed
fixed chunking of long messages
1 parent 27312db commit 8d65d23

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

mail.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ func (m *mailer) Boundary() string {
6565

6666
// chunk e mail into parts of 998 characters due to
6767
// RFC5322 2.1.1 Line Length Limits
68-
func (m *mailer) chunkMessage(message string) string {
68+
func (m *mailer) chunkString(s string) string {
6969
var chunks []string
70-
for len(message) > 998 {
71-
chunks = append(chunks, message[:998])
72-
message = message[998:]
70+
for len(s) > 998 {
71+
chunks = append(chunks, s[:998])
72+
s = s[998:]
7373
}
74-
chunks = append(chunks, message)
74+
chunks = append(chunks, s)
7575
return strings.Join(chunks, "\n")
7676
}
7777

@@ -108,7 +108,7 @@ func (m *mailer) writeMessage() []byte {
108108

109109
}
110110
buf.WriteString(fmt.Sprintf("Content-Type: %s\n\n", http.DetectContentType([]byte(msg.Body()))))
111-
buf.WriteString(msg.Body())
111+
buf.WriteString(m.chunkString(msg.Body()))
112112
if withAttachments {
113113
for k, v := range msg.Attachments() {
114114
buf.WriteString(fmt.Sprintf("\n--%s\n", boundary))
@@ -118,11 +118,11 @@ func (m *mailer) writeMessage() []byte {
118118

119119
b := make([]byte, base64.StdEncoding.EncodedLen(len(v)))
120120
base64.StdEncoding.Encode(b, v)
121-
buf.Write(b)
121+
buf.Write([]byte(m.chunkString(string(b))))
122122
buf.WriteString(fmt.Sprintf("\n--%s", boundary))
123123
}
124124

125125
buf.WriteString("--")
126126
}
127-
return []byte(m.chunkMessage(buf.String()))
127+
return buf.Bytes()
128128
}

0 commit comments

Comments
 (0)