package mailer import ( "mime" "strings" "testing" ) func TestEncodeSubject(t *testing.T) { if got := encodeSubject("Minstrel: 2 updates"); got != "Minstrel: 2 updates" { t.Errorf("plain ASCII changed: %q", got) } enc := encodeSubject("Minstrel: Moe Shop – WWW") if !strings.HasPrefix(enc, "=?utf-8?q?") { t.Errorf("non-ASCII not RFC 2047 encoded: %q", enc) } if dec, err := new(mime.WordDecoder).DecodeHeader(enc); err != nil || dec != "Minstrel: Moe Shop – WWW" { t.Errorf("round trip = %q, %v", dec, err) } if got := encodeSubject("Hi\r\nBcc: everyone@example.com"); strings.ContainsAny(got, "\r\n") { t.Errorf("a line break survived into the header: %q", got) } }