I am trying to grab a list of messages that have a specific content e.g. billing emails and work on data in there. In order to get these messages, I run the following
service.users().messages().list(userId=user_id, page_token=page_token, q=query).execute()
which returns all the messages. I want to limit the messages that I get to confirm to the following criteria:
from:
address not in a list of email addresses i.e. blacklist e.g. notifications, facebookfrom:
address in a list of email addresses i.e. whitelistsubject:
matches a set of stringsI understand that I can create a query that would match the email address and subject (from:[email protected] AND subject:"Your bill for this month"
), but the blacklist and whitelist, as mentioned above, can become significantly large as the scope and the number of vendors I can accept increases, and similar is the case with subject. So my question is:
from:[email protected] AND NOT from:[email protected] AND subject:"Your bill" AND subject:"This month's bill"
)?Note: For project settings I mostly conform to https://developers.google.com/gmail/api/quickstart/python
There's no limit documented for the number of query terms you can use. Yes, you would have to create programmatically a long query string combining all the emails from the lists. Here [1] you can check the operators you can use, the best approach would be like this:
1) Use "after" or "newer" operators with a timestamp from 2 days before the current date.
2) -from:{[email protected] [email protected] ...}
3) from:{[email protected] [email protected] ...}
4) subject:{xxx xxx ...}