srnd: avoid quoting in some cases
This commit is contained in:
parent
a1d11c594c
commit
af161968c8
@ -28,7 +28,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func DelFile(fname string) {
|
||||
@ -201,21 +200,15 @@ func isQtext(r rune) bool {
|
||||
}
|
||||
|
||||
func writeQuoted(b *strings.Builder, s string) {
|
||||
last := 0
|
||||
b.WriteByte('"')
|
||||
for i, r := range s {
|
||||
if !isQtext(r) && !isWSP(r) {
|
||||
if i > last {
|
||||
b.WriteString(s[last:i])
|
||||
}
|
||||
for _, r := range s {
|
||||
if isQtext(r) || isWSP(r) {
|
||||
b.WriteRune(r)
|
||||
} else {
|
||||
b.WriteByte('\\')
|
||||
b.WriteRune(r)
|
||||
last = i + utf8.RuneLen(r)
|
||||
}
|
||||
}
|
||||
if last < len(s) {
|
||||
b.WriteString(s[last:])
|
||||
}
|
||||
b.WriteByte('"')
|
||||
}
|
||||
|
||||
@ -227,14 +220,20 @@ func formatAddress(name, email string) string {
|
||||
if name != "" {
|
||||
needsEncoding := false
|
||||
needsQuoting := false
|
||||
for _, r := range name {
|
||||
for i, r := range name {
|
||||
if r >= 0x80 || (!isWSP(r) && !isVchar(r)) {
|
||||
needsEncoding = true
|
||||
break
|
||||
}
|
||||
if !isAtext(r) {
|
||||
needsQuoting = true
|
||||
if isAtext(r) {
|
||||
continue
|
||||
}
|
||||
if r == ' ' && i > 0 && name[i-1] != ' ' && i < len(name)-1 {
|
||||
// allow spaces but only surrounded by non-spaces
|
||||
// otherwise they will be removed by receiver
|
||||
continue
|
||||
}
|
||||
needsQuoting = true
|
||||
}
|
||||
|
||||
if needsEncoding {
|
||||
|
Reference in New Issue
Block a user