gmail.js
gmail.js copied to clipboard
gmail.get.email_data() plain_content/content_html fields return truncated email body
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).
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.
this is working for me: https://github.com/KartikTalwar/gmail.js/pull/329
This also includes attachments data etc.
With this PR now merged, could you check if this is still an issue?
If not, this issue probably should be closed.
@davidsertillange-optimizely: Care to check if your issue is solved now?
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.
I seem to be getting a truncated content_html as well, similar to what @davidsertillange-optimizely initially reported. The email is not deleted.
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.
Yes, of course.
Steps To Reproduce:
- Open
mail.google.com
(account is @gmail.com) - Open devconsole and paste in the recommended JQuery
- Paste in gmail.js
- 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:
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).
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.
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.
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.
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.
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) === "...";
}
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.
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...)
Hey, am slightly busy these days, but I'll try working on a PR ASAP!
Aren't we all? Let us know if you have something you'd like reviewed :)
Old issue is old. Closing.