summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py18
-rw-r--r--service/test/integration/test_leap_mailstore.py2
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mail.py18
3 files changed, 19 insertions, 19 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 3bf27bbf..90035d20 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -49,9 +49,8 @@ class LeapMail(Mail):
@property
def headers(self):
cpy = dict(self._headers)
-
for name in set(self._headers.keys()).intersection(['To', 'Cc', 'Bcc']):
- cpy[name] = self._headers[name].split(',') if self._headers[name] else []
+ cpy[name] = [address.strip() for address in (self._headers[name].split(',') if self._headers[name] else [])]
return cpy
@@ -146,17 +145,20 @@ class LeapMail(Mail):
if sender_mail is None:
sender_mail = InputMail.FROM_EMAIL_ADDRESS
- recipients = self._decoded_header_utf_8(self._reply_recipient('To'))
- if not self._parsed_mail_matches(sender_mail, InputMail.FROM_EMAIL_ADDRESS) or len(recipients) == 0:
- recipients.append(sender_mail)
+ recipients = self._reply_recipient('To')
+ recipients = self._decoded_header_utf_8(recipients)
+ recipients.append(sender_mail)
recipients = self.remove_duplicates(recipients)
ccs = self._decoded_header_utf_8(self._reply_recipient('Cc'))
result['single'] = sender_mail
- result['all']['to-field'] = recipients
- result['all']['cc-field'] = ccs
+ result['all']['to-field'] = self._remove_me(recipients) if len(recipients) > 1 else recipients
+ result['all']['cc-field'] = self._remove_me(ccs) if len(ccs) > 1 else ccs
return result
+ def _remove_me(self, recipients):
+ return [recipient for recipient in recipients if not self._parsed_mail_matches(recipient, InputMail.FROM_EMAIL_ADDRESS)]
+
def remove_duplicates(self, recipients):
return list(set(recipients))
@@ -170,7 +172,7 @@ class LeapMail(Mail):
def _parsed_mail_matches(self, to_parse, expected):
if InputMail.FROM_EMAIL_ADDRESS is None:
return False
- return parseaddr(self._decoded_header_utf_8(to_parse))[1] == expected
+ return parseaddr(to_parse)[1] == expected
@staticmethod
def from_dict(mail_dict):
diff --git a/service/test/integration/test_leap_mailstore.py b/service/test/integration/test_leap_mailstore.py
index af5ba8a0..9e63c693 100644
--- a/service/test/integration/test_leap_mailstore.py
+++ b/service/test/integration/test_leap_mailstore.py
@@ -188,7 +188,7 @@ class LeapMailStoreTest(SoledadTestBase):
replying = mail.as_dict()['replying']
self.assertEqual(replying['single'], 'me@pixelated.org')
- self.assertEqual(replying['all']['to-field'], [u'addr1@pixelated.org', u'me@pixelated.org'])
+ self.assertEqual(replying['all']['to-field'], [u'addr1@pixelated.org'])
self.assertEqual(replying['all']['cc-field'], [])
@defer.inlineCallbacks
diff --git a/service/test/unit/adapter/mailstore/test_leap_mail.py b/service/test/unit/adapter/mailstore/test_leap_mail.py
index fc271e55..3f117dbe 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mail.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mail.py
@@ -111,7 +111,6 @@ class TestLeapMail(TestCase):
'To': '=?iso-8859-1?q?=22=C4lbert_=DCbr=F6=22_=3C=E4=FC=F6=40example=2Email=3E?=',
'Cc': '=?iso-8859-1?q?=22=C4lbert_=DCbr=F6=22_=3C=E4=FC=F6=40example=2Email=3E?=',
'Subject': '=?iso-8859-1?q?H=E4ll=F6_W=F6rld?='})
-
self.assertEqual([expected_address], mail.as_dict()['replying']['all']['to-field'])
self.assertEqual([expected_address], mail.as_dict()['replying']['all']['cc-field'])
self.assertEqual(expected_address, mail.as_dict()['replying']['single'])
@@ -123,7 +122,7 @@ class TestLeapMail(TestCase):
mail = LeapMail('', 'INBOX',
{'From': 'test@example.test',
'To': 'receiver@example.test, %s ' % my_address})
- expected_recipients = [my_address, 'receiver@example.test', 'test@example.test']
+ expected_recipients = ['receiver@example.test', 'test@example.test']
actual_recipients = mail.as_dict()['replying']['all']['to-field']
expected_recipients.sort()
actual_recipients.sort()
@@ -138,7 +137,7 @@ class TestLeapMail(TestCase):
{'From': 'test@example.test',
'To': 'receiver@example.test, Folker Bernitt <%s>' % my_address})
- expected_recipients = ['Folker Bernitt <%s>' % my_address, 'receiver@example.test', 'test@example.test']
+ expected_recipients = ['receiver@example.test', 'test@example.test']
actual_recipients = mail.as_dict()['replying']['all']['to-field']
expected_recipients.sort()
actual_recipients.sort()
@@ -146,7 +145,7 @@ class TestLeapMail(TestCase):
self.assertEqual(expected_recipients, actual_recipients)
# TODO: fix this test
- def _test_reply_all_result_does_not_contain_own_address_in_to_with_encoded(self):
+ def test_reply_all_does_not_contain_own_address_in_to_field_with_different_encodings(self):
my_address = 'myaddress@example.test'
with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address):
@@ -154,13 +153,12 @@ class TestLeapMail(TestCase):
{'From': 'test@example.test',
'To': 'receiver@example.test, =?iso-8859-1?q?=C4lbert_=3Cmyaddress=40example=2Etest=3E?='})
- # expected_recipients = ['receiver@example.test', 'test@example.test']
- # actual_recipients = mail.as_dict()['replying']['all']['to-field']
- # expected_recipients.sort()
- # actual_recipients.sort()
+ expected_recipients = [u'receiver@example.test', u'test@example.test']
+ actual_recipients = mail.as_dict()['replying']['all']['to-field']
+ expected_recipients.sort()
+ actual_recipients.sort()
- # self.assertEqual(expected_recipients, actual_recipients)
- self.assertEqual(['receiver@example.test', 'test@example.test'], mail.as_dict()['replying']['all']['to-field'])
+ self.assertEqual(expected_recipients, actual_recipients)
def test_reply_all_result_does_not_contain_own_address_in_cc(self):
my_address = 'myaddress@example.test'