mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
net/mail: allow us-ascii encoding
Fixes #6611. LGTM=bradfitz R=bradfitz CC=golang-codereviews https://golang.org/cl/14990045
This commit is contained in:
parent
a325f4f2b3
commit
06e4b06893
2 changed files with 22 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var debug = debugT(false)
|
||||
|
|
@ -445,7 +446,7 @@ func decodeRFC2047Word(s string) (string, error) {
|
|||
return "", errors.New("address not RFC 2047 encoded")
|
||||
}
|
||||
charset, enc := strings.ToLower(fields[1]), strings.ToLower(fields[2])
|
||||
if charset != "iso-8859-1" && charset != "utf-8" {
|
||||
if charset != "us-ascii" && charset != "iso-8859-1" && charset != "utf-8" {
|
||||
return "", fmt.Errorf("charset not supported: %q", charset)
|
||||
}
|
||||
|
||||
|
|
@ -466,6 +467,16 @@ func decodeRFC2047Word(s string) (string, error) {
|
|||
}
|
||||
|
||||
switch charset {
|
||||
case "us-ascii":
|
||||
b := new(bytes.Buffer)
|
||||
for _, c := range dec {
|
||||
if c >= 0x80 {
|
||||
b.WriteRune(unicode.ReplacementChar)
|
||||
} else {
|
||||
b.WriteRune(rune(c))
|
||||
}
|
||||
}
|
||||
return b.String(), nil
|
||||
case "iso-8859-1":
|
||||
b := new(bytes.Buffer)
|
||||
for _, c := range dec {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue