I use the new Gmail API and am absolutely fixated on how to properly handle the encoding of the [body] [data] part in Ruby / Rails for a text / plain message and text / html message.
Say data = part of an encoded message.
A call Base64.decode64(data).unpack("M")on it returns a US-ASCII encoded text body with a large number of missing characters displayed on the web page.
The call Base64.decode64(data).encode('UTF-8')causes a conversion error from US-ASCII to UTF-8
But if I do Base64.decode64(data).encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => '?'}), I still see a ton of question marks.
Can someone point me in the right direction how to get the message body to be correctly encoded and displayed in UTF-8?
The formatting of the JSON email response is as follows:
"parts": [
{
"partId": "0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=UTF-8"
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
source
share