summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-02-23 16:50:10 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-02-23 16:50:10 -0300
commitb967397c20e216b3e2d34926765ee5c6e5fcb8c3 (patch)
tree1b0248bbc739508016dc8ed63f9b54b84ebdedd2 /service
parentc37c3b425021eb485376b8b776c248afb2a9b2a6 (diff)
for #174, mailer daemon is now filtered from suggestions
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/model/mail.py4
-rw-r--r--service/pixelated/adapter/search/__init__.py3
-rw-r--r--service/test/integration/test_contacts.py1
-rw-r--r--service/test/unit/adapter/test_mail.py3
4 files changed, 8 insertions, 3 deletions
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 3ea7c95a..96f2c81c 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -384,7 +384,9 @@ class PixelatedMail(Mail):
def bounced(self):
content_type = self.hdoc.content["headers"].get("Content-Type", '')
if re.compile('delivery-status').search(content_type):
- return self._extract_bounced_address(self.hdoc.content)
+ bounce_recipient = self._extract_bounced_address(self.hdoc.content)
+ bounce_daemon = self.headers["From"]
+ return [bounce_recipient, bounce_daemon] if bounce_recipient else False
return False
diff --git a/service/pixelated/adapter/search/__init__.py b/service/pixelated/adapter/search/__init__.py
index e9301278..0b1a1034 100644
--- a/service/pixelated/adapter/search/__init__.py
+++ b/service/pixelated/adapter/search/__init__.py
@@ -124,6 +124,7 @@ class SearchEngine(object):
header = mdict['header']
tags = mdict.get('tags', [])
tags.append(mail.mailbox_name.lower())
+ bounced = mail.bounced if mail.bounced else ['']
index_data = {
'sender': unicode(header.get('from', '')),
'subject': unicode(header.get('subject', '')),
@@ -132,7 +133,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),
+ 'bounced': u','.join(bounced),
'body': unicode(mdict['textPlainBody']),
'ident': unicode(mdict['ident']),
'flags': unicode(','.join(unique(mail.flags))),
diff --git a/service/test/integration/test_contacts.py b/service/test/integration/test_contacts.py
index d96abd14..3a510346 100644
--- a/service/test/integration/test_contacts.py
+++ b/service/test/integration/test_contacts.py
@@ -100,6 +100,7 @@ class ContactsTest(SoledadTestBase):
def _assert(contacts):
self.assertNotIn('this_mail_was_bounced@domain.com', contacts)
+ self.assertNotIn("MAILER-DAEMON@domain.org (Mail Delivery System)", contacts)
self.assertIn('this_mail_was_not@bounced.com', contacts)
d.addCallback(_assert)
return d
diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py
index 4bf05d3f..54c421c7 100644
--- a/service/test/unit/adapter/test_mail.py
+++ b/service/test/unit/adapter/test_mail.py
@@ -224,7 +224,8 @@ class TestPixelatedMail(unittest.TestCase):
not_bounced_mail = PixelatedMail.from_soledad(*not_bounced_leap_mail, soledad_querier=self.querier)
self.assertTrue(bounced_mail.bounced)
- self.assertEquals('this_mail_was_bounced@domain.com', bounced_mail.bounced)
+ self.assertIn('this_mail_was_bounced@domain.com', bounced_mail.bounced)
+ self.assertIn("MAILER-DAEMON@domain.org (Mail Delivery System)", bounced_mail.bounced)
self.assertFalse(not_bounced_mail.bounced)
def test_ignore_transient_failures(self):