1package message
2
3import (
4 "strings"
5)
6
7// NeedsQuotedPrintable returns whether text, with crlf-separated lines, should be
8// encoded with quoted-printable, based on line lengths and any bare carriage
9// return or bare newline. If not, it can be included as 7bit or 8bit encoding in a
10// new message.
11func NeedsQuotedPrintable(text string) bool {
12 // ../rfc/2045:1025
13 for _, line := range strings.Split(text, "\r\n") {
14 // 78 should be fine too, qp itself has a requirement of 76 bytes on a line, but
15 // using qp for anything longer than 76 is safer.
16 if len(line) > 76 || strings.Contains(line, "\r") || strings.Contains(line, "\n") {
17 return true
18 }
19 }
20 return false
21}
22