From bd0e445b573dc471324f3df7ada9e154d15b594c Mon Sep 17 00:00:00 2001 From: Alexandre Cesaro Date: Wed, 30 Mar 2016 19:05:19 +0200 Subject: [PATCH] Do not insert a newline as the first character of a header It is closer to Gmail behavior for example. See #53 --- message_test.go | 27 --------------------------- writeto.go | 7 ------- 2 files changed, 34 deletions(-) diff --git a/message_test.go b/message_test.go index 37aaa68..b147eab 100644 --- a/message_test.go +++ b/message_test.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "path/filepath" "regexp" - "runtime" "strconv" "strings" "testing" @@ -683,32 +682,6 @@ func mockCopyFileWithHeader(m *Message, name string, h map[string][]string) (str return name, f, SetHeader(h) } -func TestLineLength(t *testing.T) { - switch runtime.Version()[:5] { - case "go1.2", "go1.3", "go1.4", "go1.5": - t.Skip("Only pass with Go 1.6+") - } - - m := NewMessage() - m.SetAddressHeader("From", "from@example.com", "Señor From") - m.SetHeader("Subject", "{$firstname} Bienvendio a Apostólica, aquí inicia el camino de tu") - m.SetBody("text/plain", strings.Repeat("a", 100)) - - buf := new(bytes.Buffer) - m.WriteTo(buf) - n := 0 - for _, b := range buf.Bytes() { - if b == '\n' { - n = 0 - } else { - n++ - if n == 80 { - t.Errorf("A line is too long:\n%s", buf.Bytes()) - } - } - } -} - func BenchmarkFull(b *testing.B) { discardFunc := SendFunc(func(from string, to []string, m io.WriterTo) error { _, err := m.WriteTo(ioutil.Discard) diff --git a/writeto.go b/writeto.go index 7c05132..9fb6b86 100644 --- a/writeto.go +++ b/writeto.go @@ -219,13 +219,6 @@ func (w *messageWriter) writeLine(s string, charsLeft int) string { } } - // No space found so insert a newline if it was not the start of the - // line. - if charsLeft != 75 { - w.writeString("\r\n ") - return s - } - // 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++ {