I'm using the new Gmail API and am absolutely stuck on how to correctly handle the encoding of the [body][data] portion in Ruby/Rails for both the text/plain message and the text/html message.
Let's say data = the encoded message portion.
Calling Base64.decode64(data).unpack("M")
on it returns an US-ASCII encoded text body with lots of missing characters as displayed on a web page.
Calling Base64.decode64(data).encode('UTF-8')
throws a conversion error from US-ASCII to UTF-8
Yet if I do Base64.decode64(data).encode('UTF-8', {:invalid => :replace, :undef => :replace, :replace => '?'})
, I'm still seeing a ton of question marks.
Can someone point me in the right direction on how to get the message body to be properly encoded and displayed in UTF-8?
The formatting of the email JSON 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"