diff options
author | Patrick Maia <patrickjourdanmaia@gmail.com> | 2014-12-12 18:04:56 +0000 |
---|---|---|
committer | Patrick Maia <patrickjourdanmaia@gmail.com> | 2014-12-12 18:04:56 +0000 |
commit | 0d702851a2cfca3db85fd63a3b6093797f2aafb8 (patch) | |
tree | fe0228f91d1970ab093e604a3a37014cd39b8936 | |
parent | a0bc490dc985f88d8a7f9a835e6cd202e82cc760 (diff) |
Card #168 - ignores contacts coming from trash and drafts
-rw-r--r-- | service/pixelated/adapter/search.py | 9 | ||||
-rw-r--r-- | service/test/integration/contacts_test.py | 17 |
2 files changed, 23 insertions, 3 deletions
diff --git a/service/pixelated/adapter/search.py b/service/pixelated/adapter/search.py index 703f2f51..d1e43735 100644 --- a/service/pixelated/adapter/search.py +++ b/service/pixelated/adapter/search.py @@ -22,6 +22,7 @@ from pixelated.support.functional import flatten from whoosh.index import FileIndex from whoosh.fields import * from whoosh.qparser import QueryParser +from whoosh.query import Term from whoosh import sorting from pixelated.support.functional import unique from pixelated.support.date import milliseconds @@ -184,16 +185,18 @@ class SearchEngine(object): writer.commit() def contacts(self, query): + restrict_q = Term("tag", "drafts") | Term("tag", "trash") + if query: to = QueryParser('to', self._index.schema) cc = QueryParser('cc', self._index.schema) bcc = QueryParser('bcc', self._index.schema) with self._index.searcher() as searcher: - to = searcher.search(to.parse("*%s*" % query), limit=None, + to = searcher.search(to.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet('to', allow_overlap=True)).groups() - cc = searcher.search(cc.parse("*%s*" % query), limit=None, + cc = searcher.search(cc.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet('cc', allow_overlap=True)).groups() - bcc = searcher.search(bcc.parse("*%s*" % query), limit=None, + bcc = searcher.search(bcc.parse("*%s*" % query), limit=None, mask=restrict_q, groupedby=sorting.FieldFacet('bcc', allow_overlap=True)).groups() return flatten([to, cc, bcc]) diff --git a/service/test/integration/contacts_test.py b/service/test/integration/contacts_test.py index 79bbe287..85d6cd3d 100644 --- a/service/test/integration/contacts_test.py +++ b/service/test/integration/contacts_test.py @@ -20,3 +20,20 @@ class ContactsTest(SoledadTestBase): self.assertTrue('recipient@bcc.com' in contacts) d.addCallback(_assert) return d + + @deferred(timeout=SoledadTestBase.DEFERRED_TIMEOUT) + def test_trash_and_drafts_mailboxes_are_being_ignored(self): + self.client.add_multiple_to_mailbox(1, mailbox='INBOX', to='recipient@inbox.com') + self.client.add_multiple_to_mailbox(1, mailbox='DRAFTS', to='recipient@drafts.com') + self.client.add_multiple_to_mailbox(1, mailbox='SENT', to='recipient@sent.com') + self.client.add_multiple_to_mailbox(1, mailbox='TRASH', to='recipient@trash.com') + + d = self.get_contacts(query='recipient') + + def _assert(contacts): + self.assertTrue('recipient@inbox.com' in contacts) + self.assertTrue('recipient@sent.com' in contacts) + self.assertFalse('recipient@drafts.com' in contacts) + self.assertFalse('recipient@trash.com' in contacts) + d.addCallback(_assert) + return d |