Archived
1
0

Merge pull request #170 from cathugger/master

srnd: avoid quoting name in some cases
This commit is contained in:
Jeff 2018-12-12 14:02:01 -05:00 committed by GitHub
commit 34be78da8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 {