1
votes

I need to read messages from user's inbox using gmail API client. And what I want is to get only new messages since last time I read them. Sure, I don't want to read all messages and check which of them are new, I want to get just new messages in a query. The best solution I could figure out so far is to star messages I have read and get not starred messages like this:

$gmail->users_messages->listUsersMessages('me',['maxResults' => 10, 'q' => "in:inbox AND -in:starred"]);

What I don't like in this solution is that this affects message some way and assuming this email is used to read and send messages in common way (using web browser) I'm not sure if user can't star messages himself so my application consider it as read. I need to do something like read all messages, which were received after some time or may be where id is greater than id of last read message. Is there a way to do it?

1
Please clarify your question. How is a message new if you've already read it? - noogui
I mean I want to query only messages which were received since last time messages was fetched. Now it is done this way: fetched all not starred messages and after processing they are starred. So next time will be fetched not starred messages and those already starred won't be fetched. But I don't like this solution very much as use may star message manually too. - Vasya

1 Answers

0
votes

You could store seconds from the epoch last time your checked for new messages, and then use that next time you get new messages.

Let's say you checked for new messages at Fri, 27 Apr 2018 12:00:00 GMT, you would then write this in the next request:

$gmail->users_messages->listUsersMessages('me',['maxResults' => 10, 'q' => "in:inbox after:1524830400"]);