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

Add query uid__range #153

Merged
merged 2 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:*)')