Base64 decoding of MIME email not working (GMail API)

Andy Hin picture Andy Hin · Jul 17, 2014 · Viewed 11.5k times · Source

I'm using the GMail API to retrieve an email contents. I am getting the following base64 encoded data for the body: http://hastebin.com/ovucoranam.md

But when I run it through a base64 decoder, it either returns an empty string (error) or something that resembles the HTML data but with a bunch of weird characters.

Help?

Answer

urbanspr1nter picture urbanspr1nter · Jul 28, 2014

I'm not sure if you've solved it yet, but GmailGuy is correct. You need to convert the body to the Base64 RFC 4648 standard. The jist is you'll need to replace - with + and _ with /.

I've taken your original input and did the replacement: http://hastebin.com/ukanavudaz

And used base64decode.org to decode it, and it was fine.