Skip to content

Commit

Permalink
Fix a bug where the HasFlag never matched since upgrading to imapclie…
Browse files Browse the repository at this point in the history
…nt 0.13.
  • Loading branch information
Thomi Richards committed Jul 26, 2015
1 parent 77fd82e commit 898d457
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions gmailfilter/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
datetime,
timedelta,
)
import logging
import operator
import unicodedata

Expand Down Expand Up @@ -174,6 +175,17 @@ def match(self, message):
return get_list_id(message) == self._target_list


# IMAPClient incorrectly declares these as strings. This is reported as
# https://bitbucket.org/mjs0/imapclient/issues/165/imapclientseen-friends-have-the-wrong-type
# Once this is fixed, the '.encode' parts can be stripped
def _correct_type(flag):
if isinstance(flag, bytes):
logging.debug("This fix can be removed now!")
return flag
else:
return flag.encode('utf-8')


class HasFlag(Test):

"""Test for certain flags being set on a message.
Expand All @@ -189,13 +201,12 @@ class HasFlag(Test):
HasFlag.SEEN
"""

ANSWERED = imapclient.ANSWERED
DELETED = imapclient.DELETED
DRAFT = imapclient.DRAFT
FLAGGED = imapclient.FLAGGED
RECENT = imapclient.RECENT
SEEN = imapclient.SEEN
ANSWERED = _correct_type(imapclient.ANSWERED)
DELETED = _correct_type(imapclient.DELETED)
DRAFT = _correct_type(imapclient.DRAFT)
FLAGGED = _correct_type(imapclient.FLAGGED)
RECENT = _correct_type(imapclient.RECENT)
SEEN = _correct_type(imapclient.SEEN)

def __init__(self, flag):
self.expected_flag = flag
Expand Down

0 comments on commit 898d457

Please sign in to comment.