UberAlex
UberAlex

Reputation: 3547

Query string for messages list returns inconsistent results compared to web interface

When I use code similar to the example code from the api documentation, the query strings which in the web interface return results don't work. This is listing messages, not retrieving them, so I don't think full vs raw helps. The scope granted is gmail.readonly

  1. Is it possible to search on message body with this function?
  2. Is there a way to search on domain name (i.e. all messages from or to *@example.com)
  3. Is the search case-sensitive?

service.users().messages().list(userId=user_id, pageToken=page_token, q=query).execute()

I use 'me' for the user_id, and I checked that it's certainly the same email. A Query for in:anywhere on its own returns the full mail list.

Thanks for the help!

EDIT: The query in question is a single word like a name. Some of them sometimes work with 'name is:anywhere' but not consistently.

Upvotes: 1

Views: 69

Answers (1)

Jay Lee
Jay Lee

Reputation: 13528

  1. Yes, message body is searched.
  2. Try: "from:example.com OR to:example.com"
  3. No, Gmail UI and API search is not case-sensitive.

Be aware that service.users().threads().list() would be more consistent with Gmail UI search assuming the user has conversations enabled which is the Gmail UI default.

in:anywhere expands the search to Trash and Spam which is not normally included. Archived messages are normally included.

Upvotes: 2

Related Questions