Q:

Displaying Mail Content using Gmail API using javascript

I am trying to connect GMAIL API for my web app,i am able to connect successfully to gmail account and able to retrieve all mails.The next level is on click of the mail i need to display the mail details just like gmail does.I am able to retrieve the particular mail using GMAIL API using Mail thread-ID and i tried to display the mail Content using snippet data from response the new line are missing but when i view the same mail using gmail it display the new line correctly What am i missing here thought the type of snippet is plain text still gmail able to display properly so what should I do to make the same in my app.

    {id: "172ac2ce0f73c58e", threadId: "172ac2ce0f73c58e", labelIds: Array(2), snippet: "DEar, his djknejkn ;medmek dckmeklmdkelm ekmcelkmckl elkmcklem lkmekcmel lmeklcme Thanks,", payload: {…}, …}
historyId: "10454530"
id: "172ac2ce0f73c58e"
internalDate: "1592026521000"
labelIds: (2) ["SENT", "INBOX"]
payload: {partId: "", mimeType: "multipart/alternate", filename: "", headers: Array(10), body: {…}, …}
result: {id: "172ac2ce0f73c58e", threadId: "172ac2ce0f73c58e", labelIds: Array(2), snippet: "DEar, his djknejkn ;medmek dckmeklmdkelm ekmcelkmckl elkmcklem lkmekcmel lmeklcme Thanks,", payload: {…}, …}
sizeEstimate: 644
snippet: "DEar, his djknejkn ;medmek dckmeklmdkelm ekmcelkmckl elkmcklem lkmekcmel lmeklcme Thanks,"
threadId: "172ac2ce0f73c58e"
__proto__: Object

[Updated] Thanks it worked but now the when i view the mail in gmail app it looks like the below image how to avoid these line breaks i even tried to change the Content-Transfer-Encoding but still hard line breaks happens when i view mail in the gmail how to avoid these line breaks.

A:

The snippet is only a one-liner preview of the message and contains only the few words, just as displayed in gmail web interface.
The full email text is nested under payload.parts, and encoded in base 64.
One way to do this is described in this answer:
var part = message.parts.filter(function(part) {
  return part.mimeType == 'text/html';
});
var html = urlSafeBase64Decode(part.body.data);

N.B.: this answer warns that the data structure may vary between emails, and your code should take this into account.
Another possible solution is to request the message in raw format, as described here. The API should then respond with a raw property, also base64 encoded.

