Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmail API not returning correct emails compared to Gmail web UI for date queries

Tags:

gmail-api

The results differ between the Gmail api and Gmail web ui when using the standard query format as described here - https://support.google.com/mail/answer/7190.

The issue is specifically for the parameters after/before and newer/older. For example the following Gmail api query "after:2015/11/19 before:2015/11/20" returns different results compared with running that same query in the Gmail web ui. The web ui looks correct whereas the api returns emails from the next day (20th). Possibly a timezone conversation problem?

Checking past questions I see something similiar here how to use GMAIL API query filter for datetime (the server processes the queries as PST time). If this is the case it might be worth updating the docs or think about a possible solution.

Steps to reproduce the problem.

  1. Have some mail in a gmail account covering the dates below. Inc days after and before.
  2. Run after:2015/11/19 before:2015/11/20 in a Gmail web ui.
  3. Query the Gmail api with "after:2015/11/19 before:2015/11/20" for the q parameter using https://developers.google.com/gmail/api/v1/reference/users/messages/list
  4. Compare results. (I had differences when running these steps against a UK Gmail account)

Should only see emails from the 19th, but I see emails dated the 19th AND 20th when using the api. The web ui works as expected and only returns emails dated the 19th.

FYI: I was also using other query parameters such as "from: [email protected]" in conjuction with before/after or newer/older params. I wanted to simplify the bug report / question.

Also: The api queries I was making with a node module called node-gmail-api. Checking the code the endpoint being used is 'messages' code:

body: 'GET ' + api + '/gmail/v1/users/me/messages/' + m.id + fields + '\n'

Is the problem that 'messages' and not 'messages/list' endpoint is being called? As per answer to this question? - Why does search in gmail API return different result than search in gmail website?

Is this a bug / feature? Is there a workaround such as using epoch ms. (also not in the docs as I can see)

Thanks

like image 733
Dan Perry Avatar asked Nov 25 '15 09:11

Dan Perry


People also ask

How does Gmail API work?

The Gmail API is a RESTful API that can be used to access Gmail mailboxes and send mail. For most web applications the Gmail API is the best choice for authorized access to a user's Gmail data and is suitable for various applications, such as: Read-only mail extraction, indexing, and backup.


Video Answer


1 Answers

You can list the messages with second accuracy if you would like:

q = after:<start_of_day_in_seconds> AND before:<end_of_day_in_seconds>

So e.g. from Wed, 25 Nov 2015 00:00:00 GMT to Wed, 25 Nov 2015 23:59:59 GMT would be:

q = after:1448409600 AND before:1448495999
like image 150
Tholle Avatar answered Nov 15 '22 09:11

Tholle