Skip to content

Commit

Permalink
Merge pull request #107 from memanikantan/master
Browse files Browse the repository at this point in the history
Query and mark emails as flagged/starred.
  • Loading branch information
martinrusev authored Oct 29, 2017
2 parents ed251ce + 2f72aa1 commit 6c11c75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions imbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def mark_seen(self, uid):
logger.info("Mark UID {} with \\Seen FLAG".format(int(uid)))
self.connection.uid('STORE', uid, '+FLAGS', '(\\Seen)')

def mark_flag(self, uid):
logger.info("Mark UID {} with \\Flagged FLAG".format(int(uid)))
self.connection.uid('STORE', uid, '+FLAGS', '(\\Flagged)')

def delete(self, uid):
logger.info("Mark UID {} with \\Deleted FLAG and expunge.".format(int(uid)))
mov, data = self.connection.uid('STORE', uid, '+FLAGS', '(\\Deleted)')
Expand Down
8 changes: 8 additions & 0 deletions imbox/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def build_search_query(**kwargs):

# Parse keyword arguments
unread = kwargs.get('unread', False)
unflagged = kwargs.get('unflagged', False)
flagged = kwargs.get('flagged', False)
sent_from = kwargs.get('sent_from', False)
sent_to = kwargs.get('sent_to', False)
date__gt = kwargs.get('date__gt', False)
Expand All @@ -32,6 +34,12 @@ def build_search_query(**kwargs):
if unread:
query.append("(UNSEEN)")

if unflagged:
query.append("(UNFLAGGED)")

if flagged:
query.append("(FLAGGED)")

if sent_from:
query.append('(FROM "%s")' % sent_from)

Expand Down
10 changes: 10 additions & 0 deletions tests/query_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ def test_unread(self):
res = build_search_query(unread=True)
self.assertEqual(res, "(UNSEEN)")

def test_unflagged(self):

res = build_search_query(unflagged=True)
self.assertEqual(res, "(UNFLAGGED)")

def test_flagged(self):

res = build_search_query(flagged=True)
self.assertEqual(res, "(FLAGGED)")

def test_sent_from(self):

res = build_search_query(sent_from='test@example.com')
Expand Down

0 comments on commit 6c11c75

Please sign in to comment.