Skip to content

Commit

Permalink
Make sure to only add one of INBOX, SPAM, TRASH labels
Browse files Browse the repository at this point in the history
The gmail API fails with an error otherwise.

fixes gauteh#26
  • Loading branch information
julian-klode committed Jun 6, 2017
1 parent 9d03eea commit 98b35d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ You can get an [api key](https://console.developers.google.com/flows/enableapi?a
The GMail API does not let you sync `muted` messages. Until the [Google
bug](https://issuetracker.google.com/issues/36759067) is fixed, the `mute` and `muted` tags are not synchronized with the remote.

Only one of the tags `inbox`, `spam`, and `trash` may be added to an email. For
the time being, `trash` will be prefered over `spam`, and `spam` over inbox.
12 changes: 12 additions & 0 deletions lieer/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,18 @@ def update (self, gmsg, nmsg, last_hist, force):
self.all_updated = False
return None

if 'TRASH' in add:
if 'SPAM' in add:
print ("update: %s: Trying to add both TRASH and SPAM, dropping SPAM (add: %s, rem: %s)" % (mid, add, rem))
add.remove('SPAM')
if 'INBOX' in add:
print ("update: %s: Trying to add both TRASH and INBOX, dropping INBOX (add: %s, rem: %s)" % (mid, add, rem))
add.remove('INBOX')
elif 'SPAM' in add:
if 'INBOX' in add:
print ("update: %s: Trying to add both SPAM and INBOX, dropping INBOX (add: %s, rem: %s)" % (mid, add, rem))
add.remove('INBOX')

if self.dry_run:
print ("(dry-run) mid: %s: add: %s, remove: %s" % (mid, str(add), str(rem)))
return None
Expand Down

0 comments on commit 98b35d0

Please sign in to comment.