From 96eab1202717e073782ec399a4e0820cae15b1bb Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Thu, 17 Aug 2017 17:19:06 -0700 Subject: Updating server dependancies. (#7246) --- vendor/gopkg.in/gomail.v2/writeto.go | 96 ++++++------------------------------ 1 file changed, 16 insertions(+), 80 deletions(-) (limited to 'vendor/gopkg.in/gomail.v2/writeto.go') diff --git a/vendor/gopkg.in/gomail.v2/writeto.go b/vendor/gopkg.in/gomail.v2/writeto.go index 9fb6b86e8..57a1dd7f1 100644 --- a/vendor/gopkg.in/gomail.v2/writeto.go +++ b/vendor/gopkg.in/gomail.v2/writeto.go @@ -7,7 +7,6 @@ import ( "mime" "mime/multipart" "path/filepath" - "strings" "time" ) @@ -39,7 +38,8 @@ func (w *messageWriter) writeMessage(m *Message) { w.openMultipart("alternative") } for _, part := range m.parts { - w.writePart(part, m.charset) + w.writeHeaders(part.header) + w.writeBody(part.copier, m.encoding) } if m.hasAlternativePart() { w.closeMultipart() @@ -79,7 +79,7 @@ type messageWriter struct { func (w *messageWriter) openMultipart(mimeType string) { mw := multipart.NewWriter(w) - contentType := "multipart/" + mimeType + ";\r\n boundary=" + mw.Boundary() + contentType := "multipart/" + mimeType + "; boundary=" + mw.Boundary() w.writers[w.depth] = mw if w.depth == 0 { @@ -104,14 +104,6 @@ func (w *messageWriter) closeMultipart() { } } -func (w *messageWriter) writePart(p *part, charset string) { - w.writeHeaders(map[string][]string{ - "Content-Type": {p.contentType + "; charset=" + charset}, - "Content-Transfer-Encoding": {string(p.encoding)}, - }) - w.writeBody(p.copier, p.encoding) -} - func (w *messageWriter) addFiles(files []*file, isAttachment bool) { for _, f := range files { if _, ok := f.Header["Content-Type"]; !ok { @@ -162,80 +154,24 @@ func (w *messageWriter) writeString(s string) { w.n += int64(n) } -func (w *messageWriter) writeHeader(k string, v ...string) { - w.writeString(k) - if len(v) == 0 { - w.writeString(":\r\n") - return - } - w.writeString(": ") - - // Max header line length is 78 characters in RFC 5322 and 76 characters - // in RFC 2047. So for the sake of simplicity we use the 76 characters - // limit. - charsLeft := 76 - len(k) - len(": ") - - for i, s := range v { - // If the line is already too long, insert a newline right away. - if charsLeft < 1 { - if i == 0 { - w.writeString("\r\n ") - } else { - w.writeString(",\r\n ") - } - charsLeft = 75 - } else if i != 0 { - w.writeString(", ") - charsLeft -= 2 - } - - // While the header content is too long, fold it by inserting a newline. - for len(s) > charsLeft { - s = w.writeLine(s, charsLeft) - charsLeft = 75 +func (w *messageWriter) writeStrings(a []string, sep string) { + if len(a) > 0 { + w.writeString(a[0]) + if len(a) == 1 { + return } + } + for _, s := range a[1:] { + w.writeString(sep) w.writeString(s) - if i := lastIndexByte(s, '\n'); i != -1 { - charsLeft = 75 - (len(s) - i - 1) - } else { - charsLeft -= len(s) - } } - w.writeString("\r\n") } -func (w *messageWriter) writeLine(s string, charsLeft int) string { - // If there is already a newline before the limit. Write the line. - if i := strings.IndexByte(s, '\n'); i != -1 && i < charsLeft { - w.writeString(s[:i+1]) - return s[i+1:] - } - - for i := charsLeft - 1; i >= 0; i-- { - if s[i] == ' ' { - w.writeString(s[:i]) - w.writeString("\r\n ") - return s[i+1:] - } - } - - // We could not insert a newline cleanly so look for a space or a newline - // even if it is after the limit. - for i := 75; i < len(s); i++ { - if s[i] == ' ' { - w.writeString(s[:i]) - w.writeString("\r\n ") - return s[i+1:] - } - if s[i] == '\n' { - w.writeString(s[:i+1]) - return s[i+1:] - } - } - - // Too bad, no space or newline in the whole string. Just write everything. - w.writeString(s) - return "" +func (w *messageWriter) writeHeader(k string, v ...string) { + w.writeString(k) + w.writeString(": ") + w.writeStrings(v, ", ") + w.writeString("\r\n") } func (w *messageWriter) writeHeaders(h map[string][]string) { -- cgit v1.2.3-1-g7c22