diff options
Diffstat (limited to 'libgo/go/mime/encodedword.go')
-rw-r--r-- | libgo/go/mime/encodedword.go | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/libgo/go/mime/encodedword.go b/libgo/go/mime/encodedword.go index 58f60da..e6b470b 100644 --- a/libgo/go/mime/encodedword.go +++ b/libgo/go/mime/encodedword.go @@ -203,35 +203,25 @@ func (d *WordDecoder) Decode(word string) (string, error) { } word = word[2 : len(word)-2] - // split delimits the first 2 fields - split := strings.IndexByte(word, '?') - - // split word "UTF-8?q?ascii" into "UTF-8", 'q', and "ascii" - charset := word[:split] - if len(charset) == 0 { - return "", errInvalidWord - } - if len(word) < split+3 { + // split word "UTF-8?q?text" into "UTF-8", 'q', and "text" + charset, text, _ := strings.Cut(word, "?") + if charset == "" { return "", errInvalidWord } - encoding := word[split+1] - // the field after split must only be one byte - if word[split+2] != '?' { + encoding, text, _ := strings.Cut(text, "?") + if len(encoding) != 1 { return "", errInvalidWord } - text := word[split+3:] - content, err := decode(encoding, text) + content, err := decode(encoding[0], text) if err != nil { return "", err } var buf strings.Builder - if err := d.convert(&buf, charset, content); err != nil { return "", err } - return buf.String(), nil } |