From 1f0b952fbcbe8a19f6bcef8314d363ce211d5b55 Mon Sep 17 00:00:00 2001 From: Sumit Ghosh Date: Sat, 8 Sep 2018 21:54:59 +0530 Subject: [PATCH 1/2] Add query uid__range --- imbox/query.py | 4 ++++ tests/query_tests.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/imbox/query.py b/imbox/query.py index cd4fe7f..6e8d806 100644 --- a/imbox/query.py +++ b/imbox/query.py @@ -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 = [] @@ -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) diff --git a/tests/query_tests.py b/tests/query_tests.py index 00206da..1bf7ba7 100644 --- a/tests/query_tests.py +++ b/tests/query_tests.py @@ -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:*)') From c21f2ec9f7a444641b2385416a4f4dc1d2ebd324 Mon Sep 17 00:00:00 2001 From: Sumit Ghosh Date: Sat, 8 Sep 2018 21:57:57 +0530 Subject: [PATCH 2/2] Edit README mentioning usage of uid__range --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 8c55755..0e68411 100644 --- a/README.rst +++ b/README.rst @@ -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')