gmail.js icon indicating copy to clipboard operation
gmail.js copied to clipboard

gmail.get.email_data() plain_content/content_html fields return truncated email body

Open davidsertillange-optimizely opened this issue 8 years ago • 19 comments

Hi there,

When getting the email content using gmail.get.email_data(email_id), the body of the emails (obtained through the plain_content or content_html fields) are truncated. Three dots (...) are added after the first 75 characters or so.

Is this expected behavior?

Best, David

We have been experiencing this issue as well. It appears the truncation is correlated with the is_deleted flag (true results in truncation).

sandfield-andy avatar Aug 16 '16 22:08 sandfield-andy

Check pull request #296 for a fix to this issue.

Unfortunately it doesn't seem to have fixed my issue. I have tried calling get.email_data_full both with and without specifying an email id and it returns an identical object to get.email_data (with the same emails truncated to 77 characters followed by three dots(...)). As mentioned earlier it seems to have some association with the is_deleted flag. I have also found that if you star the email and call the method again it returns the full content.

sandfield-andy avatar Aug 24 '16 02:08 sandfield-andy

this is working for me: https://github.com/KartikTalwar/gmail.js/pull/329

This also includes attachments data etc.

michi88 avatar Nov 17 '16 18:11 michi88

With this PR now merged, could you check if this is still an issue?

If not, this issue probably should be closed.

josteink avatar Nov 19 '16 10:11 josteink

@davidsertillange-optimizely: Care to check if your issue is solved now?

josteink avatar Nov 19 '16 17:11 josteink

Since I haven't heard anything new on this issue, I'm closing it.

Please re-open it if you still have an issue you need resolved.

josteink avatar Feb 10 '17 19:02 josteink

I seem to be getting a truncated content_html as well, similar to what @davidsertillange-optimizely initially reported. The email is not deleted.

image

ShivanKaul avatar May 04 '17 02:05 ShivanKaul

Can you provide any more details on how to reproduce this? Things which could help:

  • Sample code
  • Gmail account-type (@gmail.com, Google Apps/GSuite-account, Grandfathered account from Google apps beta, etc)
  • Use-case scenario (In a email-thread, or outside?)

Unless we can find a way to reproduce it, chances of getting it fixed is effectively zero.

josteink avatar May 04 '17 11:05 josteink

Yes, of course.

Steps To Reproduce:

  1. Open mail.google.com (account is @gmail.com)
  2. Open devconsole and paste in the recommended JQuery
  3. Paste in gmail.js
  4. Try sanity command:
var gmail = Gmail();
gmail.get.user_email();

Outputs correctly: [email protected] 5. Open up thread with 12 messages. Execute gmail.get.displayed_email_data() 6. Get Object with some messages that are truncated: image

I tried with a couple of longish email threads and get similar results. When truncation happens, the html_content is plaintext (no embedded HTML tags etc).

ShivanKaul avatar May 04 '17 19:05 ShivanKaul

I also see (like @andy-sal) that if I star the message then it does not get truncated. If I unstar it then it goes back to being truncated. I get truncated at 77 chars (+'...' makes it a round 80) as well.

ShivanKaul avatar May 04 '17 22:05 ShivanKaul

It's not a problem with the data parsing - the response we get from the Gmail server itself on hitting it with the https://mail.google.com/mail/u/0/?ui=2&ik=blah&rid=blah&view=blah&th=blah&msgs=etc request in api.get.email_data() is truncated.

@ShivanKaul: This comment which you wrote was deleted. Was this intentional or a mistake?

Is the information represented by this message correct? Because if it is, I'm afraid I don't know any easy fix for this problem.

josteink avatar May 05 '17 07:05 josteink

I was analyzing the raw data from the request, and thought I saw that the full message was in fact there, so to not mislead I deleted my comment about the problem being with the response we get from server. On looking further though, I realized that the "full" message was in fact just bits from the forwarded section of another message in the thread.

So the comment still stands, and should not have been deleted; sorry for the confusion.

ShivanKaul avatar May 05 '17 13:05 ShivanKaul

My guess would be that on long threads with multiple messages, the server makes an optimization and only sends a truncated version of a message. When you click on the collapsed message in the UI, another request is made to get the full message.

ShivanKaul avatar May 05 '17 13:05 ShivanKaul

That sounds absolutely plausible. Especially how the default is that many messages get collapsed when there are lots of email in a thread.

Again... I'm not sure what the best solution here would be.

Could we detect the the contents are truncated, and report that as part of email_data (and then API-users can decide on how to best respond to that) or do you have any better suggestions?

This detection could be pretty basic... Something like:

function isTruncatedEmailContents(str) {
    return str.length === 80 && str.subString(77,3) === "...";
}

josteink avatar May 05 '17 13:05 josteink

That's what my thought was -- to detect (somehow) that the message has been truncated, preferably through checking something in the raw email data we get... Failing that, we can use a detection heuristic like you suggested. I'd add str.isPlainText() as a condition to that, based on what I've been seeing (or better: data.content_html == data.plaintext).

The first approach would need some trawling through the raw response.

ShivanKaul avatar May 05 '17 15:05 ShivanKaul

If you think that would be a OK approach, would you be willing to write a PR for that which matches your use-cases?

I'd love to help out, but since I cannot reproduce this, I think it would be beneficial if someone actually experiencing the issue did it.

I'll do my best to help out, review and merge (and without another 2 week delay...)

josteink avatar May 19 '17 06:05 josteink

Hey, am slightly busy these days, but I'll try working on a PR ASAP!

ShivanKaul avatar May 23 '17 23:05 ShivanKaul

Aren't we all? Let us know if you have something you'd like reviewed :)

josteink avatar May 24 '17 07:05 josteink

Old issue is old. Closing.

josteink avatar Oct 11 '23 08:10 josteink