twenty
twenty copied to clipboard
Make gmail filters work for partial sync
Make gmail filters work for partial sync
We are currently using search params to filter the emails we want to import (relevant emails, blocklist, filter out events ...).
We pass these filters to the q
parameter of method users.messages.list during the full sync.
Unfortunately, the method users.history.list that we use for the partial sync doesn't provide this q
param. And we would like to leverage the power of the gmail filters even in partial sync.
Solution 1
The filter rfc822msgid
allows us to filter messages with a certain message-id header.
In gmail-fetch-message-content-from-cache.service
, call users.messages.list with the filter rfc822msgid
for the message ids to save, and the other filters, and save the returned messages.
Solution 2
Create a label inside our users' mailbox called imported by twenty
defined by our filters, and filter on this label for full-sync and partial-sync.
This method will also allow us to receive a push notification only for the relevant emails with users.watch when we will implement webhooks.
Solution 3 (The one we will implement after reflexion)
- Use only the google smart filters (promotion, social, forums), which are the only one which work for full-sync, partial sync and webhooks.
- Do the rest of the filtering on our side (noreply, blocklist, filter out events ...)
This is easier to maintain and allows us to share a common behavior between services.
Thanks! I prefer option 1 for now, option 2 will impact user mailboxes since labels are visible on gmail and I don't think we want to do that.
@Weiko I agree, maybe we can discuss the second option again when we will introduce webhooks