summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/search
diff options
context:
space:
mode:
authorPatrick Maia <pmaia@thoughtworks.com>2015-02-20 11:14:58 -0300
committerPatrick Maia <pmaia@thoughtworks.com>2015-02-20 11:17:01 -0300
commit2bd46a719b947b0839f47fd9e4bf5517f396fd29 (patch)
tree3f9acb994c118163fea8eeaafedf030a20022b15 /service/pixelated/adapter/search
parentc5f29f136f293a51d2fd42fcfd8fc18a39f09cfa (diff)
Issue #174 - rejects bounced addresses on contacts suggestions
Diffstat (limited to 'service/pixelated/adapter/search')
-rw-r--r--service/pixelated/adapter/search/__init__.py2
-rw-r--r--service/pixelated/adapter/search/contacts.py13
2 files changed, 12 insertions, 3 deletions
diff --git a/service/pixelated/adapter/search/__init__.py b/service/pixelated/adapter/search/__init__.py
index eedeaa45..e9301278 100644
--- a/service/pixelated/adapter/search/__init__.py
+++ b/service/pixelated/adapter/search/__init__.py
@@ -102,6 +102,7 @@ class SearchEngine(object):
to=KEYWORD(stored=False, commas=True),
cc=KEYWORD(stored=False, commas=True),
bcc=KEYWORD(stored=False, commas=True),
+ bounced=KEYWORD(stored=False, commas=True),
subject=TEXT(stored=False),
date=NUMERIC(stored=False, sortable=True, bits=64, signed=False),
body=TEXT(stored=False),
@@ -131,6 +132,7 @@ class SearchEngine(object):
'cc': u','.join(header.get('cc', [''])),
'bcc': u','.join(header.get('bcc', [''])),
'tag': u','.join(unique(tags)),
+ 'bounced': unicode(mail.bounced),
'body': unicode(mdict['textPlainBody']),
'ident': unicode(mdict['ident']),
'flags': unicode(','.join(unique(mail.flags))),
diff --git a/service/pixelated/adapter/search/contacts.py b/service/pixelated/adapter/search/contacts.py
index afef6ad0..0dfeb15b 100644
--- a/service/pixelated/adapter/search/contacts.py
+++ b/service/pixelated/adapter/search/contacts.py
@@ -31,14 +31,21 @@ def address_duplication_filter(contacts):
return contacts_by_mail.values()
+def bounced_addresses_filter(searcher, contacts):
+ query = QueryParser('bounced', searcher.schema).parse('*')
+ bounced_addresses = searcher.search(query,
+ limit=None,
+ groupedby=sorting.FieldFacet('bounced',
+ allow_overlap=True)).groups()
+ return set(contacts) - set(flatten([bounced_addresses]))
+
+
def extract_mail_address(text):
return parseaddr(text)[1]
def contacts_suggestions(query, searcher):
- if query:
- return address_duplication_filter(search_addresses(searcher, query))
- return []
+ return address_duplication_filter(bounced_addresses_filter(searcher, search_addresses(searcher, query))) if query else []
def search_addresses(searcher, query):