Commit 06e4b068 authored by Russ Cox's avatar Russ Cox

net/mail: allow us-ascii encoding

Fixes #6611.

LGTM=bradfitz
R=bradfitz
CC=golang-codereviews
https://golang.org/cl/14990045
parent a325f4f2
......@@ -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 {
......
......@@ -194,6 +194,16 @@ func TestAddressParsing(t *testing.T) {
},
},
},
// RFC 2047 "Q"-encoded US-ASCII address. Dumb but legal.
{
`=?us-ascii?q?J=6Frg_Doe?= <joerg@example.com>`,
[]*Address{
{
Name: `Jorg Doe`,
Address: "joerg@example.com",
},
},
},
// RFC 2047 "Q"-encoded UTF-8 address.
{
`=?utf-8?q?J=C3=B6rg_Doe?= <joerg@example.com>`,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment