outtake
outtake copied to clipboard
Exclude specific label?
Is there a way to exclude a specific label or set of labels from being downloaded? My use case is to download all of my email, but not with the All label (I'd also like to exclude Trash/, Drafts/, Spam and some others).
Hmm. Oddly, I'm not sure that's trivial--worse, now that I think about how the API works, I think the whole label feature (which I don't use myself; I can't remember why I added it) may not even work right!
It's been a while since I even looked at this code, but what we do is call history.list(labels): https://developers.google.com/gmail/api/v1/reference/users/history/list.
There are two problems here:
- This only allows positive filters, not (as you are requesting) exclusions.
- To be clever, we try to sync label changes as well. (That is, outtake preserves message labels on the synced mail.)
The latter makes me wonder: if we only sync history for messages with a given label, what happens if we have a label filter ("X"), we sync a message with label "X", and then label "X" is removed from the message on the server side? What happens next time we sync?
One possible behavior (which is not clear to me from the documentation) is that we would not see the "remove label Y" action (#3) when we sync in step #4. Which may or may not be desirable behavior.
Anyway, to solve #1 and implement negative filters, we could easily just add a filter about here https://github.com/danmarg/outtake/blob/master/lib/gmail/gmail.go#L299 which would apply an "exclusion" filter. This is a bit less efficient than filtering on the server-side, but since the API seems not to support that...
So something like:
for _, el := range o.excludeLabels {
for _, hl := range o.Labels{
if hl == el {
o.Operation = NONE
return o
}
}
}
Wanna send me a PR? ;)
@nickchappell Does this do what you want? https://github.com/danmarg/outtake/pull/3
I haven't tried running it, to be honest. Maybe you'd be willing to try it out so I don't have to. :)