Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude specific label? #2

Open
nickchappell opened this issue Apr 28, 2017 · 2 comments
Open

Exclude specific label? #2

nickchappell opened this issue Apr 28, 2017 · 2 comments

Comments

@nickchappell
Copy link

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).

@danmarg
Copy link
Owner

danmarg commented May 7, 2017

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:

  1. This only allows positive filters, not (as you are requesting) exclusions.
  2. 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? ;)

@danmarg
Copy link
Owner

danmarg commented May 21, 2017

@nickchappell Does this do what you want? #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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants