How to get message flags like "seen" in Gmail API - gmail-api

I'm trying to get email messages from Gmail using the RESTful API and I don't see how can I get message flags (read / unread and etc.).
Is there any way to get message flags from the Gmail using the RESTful API?
Thanks.

What do you mean by "flags" and "folders"? are you used to using IMAP and referring to it in that sense? what you normally would want is to look at labels like "UNREAD". those labels are the hardcoded, system labels and are documented at:
https://developers.google.com/gmail/api/guides/labels
they are those exact values, never translated to other languages like the web user interface is.
gmail doesn't have "flags" or "folders" just labels. the flags and folder concepts are (somewhat hackily) provided to support IMAP. if you want to see all the unread message in the inbox just do something like:
>>> messages.list(labelIds=["INBOX", "UNREAD'])

Read/Unread status for a message is indicated by the presence of the UNREAD label. You can also see whether a message is starred. See Managing Labels.

You can do it as:
ListMessagesResponse emails = service.users().messages().list("me").setQ("label:UNREAD").execute();
// Getting my unread mails.
And it works with whatever language.

Related

Send multi-line signature to Metamask via web3js

Checked all the similar questions suggested and couldn't find an answer, unfortunately.
Is there a way to send a multi-line message to metamask via web3.eth.personal.sign as the first parameter? (The problem is how to get multiple lines, not how to actually send a message there)
A more eloquent example of my question can be seen in the image attached. There are multiple paragraphs on separate lines: 'Welcome to OpenSea!', 'Click "Sign" to sign in..." etc.
Thanks a lot!
You can either use \n or use instead of '' or "" when you send the message. The option with takes the spacing in the content into consideration (in js).

Problems with sorting emails

I am wresting to sort email messages which I got using this api
https://developers.google.com/gmail/api/v1/reference/users/messages/list
Does anybody know how gmail api send this messages?
Do they send messages in order?
Thanks
Go to Users.messages.list and Execute the Try-it. You will notice that the threadIds of messages appear in descending order with the newest one appearing on top. Also confirmed in this SO post.
I recently looked into the same issue and wrote a short python prototype - feel free to take a look, it is publicly available on Github: https://github.com/jan-janssen/pygmailsorter
As #reyanthonyrenacia already pointed out the key part is using Users.messages.list, I then combine this with Users.messages.get to receive the full message and finally add or remove the label using the Users.messages.modify action.

A Confusion about Raw query parameter

I am writing a simple migration tool in which I have to migrate gmail mailboxes to some other email provider. I am confused about raw string returned from gmail api.
In Google document, it says:
"raw": Returns the entire email message content in the raw field as a URL-safe base64 encoded string and the payload field is not used. This includes the identifiers, labels, metadata, MIME structure, and small body parts (typically less than 2KB).
So this means "raw" returns only small body parts less than 2kb and if the body parts are more than 2KB, there will be a problem. I have checked with some dummy emails containing email body(including inline attachments) more than 2KB, and it still works. It still returns the complete body without any problem. Sorry,if I missed something, please clear my confusion. If "raw" is working fine for all email body sizes , I will be using this approach in my project instead of "full" query parameter.
best regards,
messages.get(format=RAW) returns the entire email always. That document: https://developers.google.com/gmail/api/v1/reference/users/messages/get is incorrect and needs to be fixed.

Forward message using the Gmail API without using JavaMail

Is there a way to use the Gmail API based Message object to forward a message without using the JavaMail library (Javax)?
Thanks.
Looking for a way to bounce the Message object to another recipient WITHOUT using any JAVAMAIL classes (MimeMessage for instance)
So far no luck cause I'm pretty sure that the message's Raw will have to be re-encoded somehow.
Will love some help.
EDIT:
Found one solution which is equivalent to bouncing an message to another recipient. Thanks to Eric for the pointing me in the right direction. use the Gmail API get method for the specific email with "raw" format. decode the raw string from the parsed message->replace "To:" with new recipient address and re-encode the raw (base62url). Create a new message with newly encoded raw and send
Depends on what you mean by "Forward" I imagine. If you mean it in the "bounce message" of old mailers of yore (resend the exact same content to a new recipient without changing body or headers) then yeah should be trivial.
If, instead, you mean what more current mailers do when you forward it (set new From, To, Subject headers, include original To+Cc+From headers somewhere in the body below something like "Forwarded message" and your own user-added content) then you probably need to deal with something like javax.mail for those changes. If you're sure the emails are simple (e.g. just a text/plain part) you could attempt it without javax.mail and use the parsed Message object (format=FULL) to create a new email. But javax.mail is probably best.

Gmail API Users.Messages.get return some messages without any label

Trying to get messages from Gmail using RESTFul API using get operation and some messages are returned empty labels (other parts of the payload are ok).
What is the reason to get empty labels ?
Thanks
Messages without labels are archived messages.
This seems like expected behavior. If they don't have any labels (e.g. not even INBOX) then they are simply in All Mail (e.g. they have been archived and are in the mailbox, etc).

Resources