Sometimes your API returns data encoded in RFC 2047 format. This basically defines the following:
encoded-word = "=?" charset "?" encoding "?" encoded-text "?="
This means that your encoding is UTF-8 (very convenient, since it is Go's own character set), and your Base64 encoding. The text you must decode is the number between "B?" and "? =". So all you have to do is take this text and call:
base64.StdEncoding.DecodeString(text)
to get the original string of UTF-8.
There is a decodeRFC2047Word() function in the net/mail package Go stdlib that supports B and Q encodings and UTF-8 , US-ASCII and ISO-8859-1 . Unfortunately, it is not exported, but you can extract as much inspiration from it as you need;)
BTW: I just noticed that in your examples the character string is UTF 8 , which is a bit odd, since the official name of the encoding is UTF-8 .
rob74 source share