| Can't round trip through mime.WordEncoder / mime.WordDecoder? | Nate Finch | 02/03/16 11:11 | Am I missing something? mime.WordEncoder says: Encode returns the encoded-word form of s. If s is ASCII without special characters, it is returned unchanged. The problem is, that mime.WordDecoder can't handle non-encoded strings, it just returns an error if there's no format specified in the beginning of the string.... so how do I decode something that WordEncoder encoded? For now, if Decode fails, I try re-encoding to see if it returns the same string as the input. That's kind of horrible, but I don't really understand how else I should be using WordDecoder. |
| Re: [go-nuts] Can't round trip through mime.WordEncoder / mime.WordDecoder? | Nigel Tao | 02/03/16 15:43 | https://www.ietf.org/rfc/rfc2047.txt says that `Generally, an
"encoded-word" is a sequence of printable ASCII characters that begins with "=?", ends with "?=", and has two "?"s in between.` So you could check that before passing s to a WordDecoder. It is indeed the first thing that WordDecoder.Decode does. We can't change Go 1.6 now, but for Go 1.7, this should probably be provided by the library, instead of users of that library. I filed https://github.com/golang/go/issues/14608 |
| Re: [go-nuts] Can't round trip through mime.WordEncoder / mime.WordDecoder? | Nate Finch | 02/03/16 18:41 | Thanks, Nigel. |