gmail.js
gmail.js copied to clipboard
Another issue in getting emails_data given new style thread id
I understand that old style thread ids, that is those of the form data-legacy-thread-id
are deprecated and probably shouldn't be used for new code. So I am trying to use the new style thread id, those of the form data-thread-id="#thread-f:1639328810092166278"
and I am using it this way: gmail.new.get.email_data("thread-f:1639328810092166278")
and this returns null because as I read in https://github.com/KartikTalwar/gmail.js/issues/558, this method will only return non-null when the email has already been seen and hence been held in a cache.
This doesn't work for my use cases and I am not sure what is the proper way to go forward but here are some ideas:
-
Find a way to force download the email, that is what the old style seems to be doing in a sync way (hence the warnings and deprecation). Perhaps there is an async version that will be okay given new style thread ids?
-
Pass the new style thread id to a backend server and there download the email, but this way opens up 100x more potential issues because I am not sure how to provide authorization for the backend to access email accounts other than my own (OAuth2 would add a lot of complexity to my project)
-
Somehow do open the email but do it in a shadow DOM along with some CSS, perhaps with z-index -1, so that there is no visual but the act of opening will trigger the appropriate code that forces the downloading of email content.
Appreciate guidance about what the best way forward would be, I am leaning towards 1, but in any case would like a code sample showing how: given new style thread id, get email content of a never before opened email.
I am using it this way: gmail.new.get.email_data("thread-f:1639328810092166278")
Use gmail.get.new.thread_data(id)
instead. If you want the thread-data, that should solve your issues. Note: This will return a thread-object which is slightly different (contains the entire thread, not just a single email).
Edit: Is there any reason you are using the thread-id instead of the new style email-id (msg:236432678
, etc)? To me it sounds like that's what you are really interested in.
gmail.new.get.email_data("thread-f:1639328810092166278") and this returns null
This method fails silently when the ID email-id can't be found and returns null. For your case it will always return null, because you are not providing an email-id.
Maybe we should add code to explicitly error out if we detect a case like yours, where a non-email-id is incorrectly provided.
Does that sound reasonable? Any opinions?
Thanks for the reply. Indeed, looks like the new style message id is what I want. However, getting the new style message id works for read emails. Is there a way to get the new style message id on never opened emails? If so, how do I pass an unread email node to api.new.get.email_id() ?
Gmail aggressively preloads email-data. If it’s listed in the inbox-view, it’s probably available in the cache.
How to decide what email ids to get sounds like something which emerges from the extension-design, and not gmail.js.
Old issue is old. Closing.