Skip to content

Commit

Permalink
Merge pull request #153 from SkullTech/query-uid__range
Browse files Browse the repository at this point in the history
Add query uid__range
  • Loading branch information
martinrusev committed Sep 10, 2018
2 parents d0b3fa4 + c21f2ec commit 782d397
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ Usage
# Messages whose subjects contain a string
inbox_messages_subject_christmas = imbox.messages(subject='Christmas')
# Messages whose UID is greater than 1050
inbox_messages_subject_christmas = imbox.messages(uid__range='1050:*')
# Messages from a specific folder
messages_in_folder_social = imbox.messages(folder='Social')
Expand Down
4 changes: 4 additions & 0 deletions imbox/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def build_search_query(**kwargs):
date__lt = kwargs.get('date__lt', False)
date__on = kwargs.get('date__on', False)
subject = kwargs.get('subject')
uid__range = kwargs.get('uid__range')

query = []

Expand Down Expand Up @@ -53,6 +54,9 @@ def build_search_query(**kwargs):
if subject is not None:
query.append('(SUBJECT "%s")' % subject)

if uid__range:
query.append('(UID %s)' % uid__range)

if query:
logger.debug("IMAP query: {}".format(" ".join(query)))
return " ".join(query)
Expand Down
4 changes: 4 additions & 0 deletions tests/query_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ def test_date__lt(self):
def test_date__on(self):
res = build_search_query(date__on=date(2014, 1, 1))
self.assertEqual(res, '(ON "01-Jan-2014")')

def test_uid__range(self):
res = build_search_query(uid__range='1000:*')
self.assertEqual(res, '(UID 1000:*)')

0 comments on commit 782d397

Please sign in to comment.