summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-09-01 14:00:21 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-09-01 14:00:21 +0200
commita43f3a7c9c47dc9c9239414a0eba9bbc1f3cfdbf (patch)
tree919ad8a3679e0d81f6c53d32456a199cd4b355dc /service
parent722edf3a306e495808c3ca751f6c74f5d6e5b138 (diff)
Encode mail addresses when replying
- Issue #448
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py12
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mail.py18
2 files changed, 23 insertions, 7 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 73ce543f..9b1afdd4 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -90,7 +90,7 @@ class LeapMail(Mail):
def _decoded_header_utf_8(self, header_value):
if isinstance(header_value, list):
- return [self._decoded_header_utf_8(v) for v in header_value]
+ return self.remove_duplicates([self._decoded_header_utf_8(v) for v in header_value])
else:
content, encoding = decode_header(header_value)[0]
if encoding:
@@ -114,20 +114,24 @@ class LeapMail(Mail):
def _replying_dict(self):
result = {'single': None, 'all': {'to-field': [], 'cc-field': []}}
- sender_mail = self.headers.get('Reply-To', self.headers.get('From'))
+ sender_mail = self._decoded_header_utf_8(self.headers.get('Reply-To', self.headers.get('From')))
# Issue #215: Fix for existing mails without any from address.
if sender_mail is None:
sender_mail = InputMail.FROM_EMAIL_ADDRESS
- recipients = self._reply_recipient('To')
+ recipients = self._decoded_header_utf_8(self._reply_recipient('To'))
recipients.append(sender_mail)
- ccs = self._reply_recipient('Cc')
+ 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
return result
+ def remove_duplicates(self, recipients):
+ return list(set(recipients))
+
def _reply_recipient(self, kind):
recipients = self.headers.get(kind, [])
if not recipients:
diff --git a/service/test/unit/adapter/mailstore/test_leap_mail.py b/service/test/unit/adapter/mailstore/test_leap_mail.py
index 9dab4e28..9b72d8c3 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mail.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mail.py
@@ -48,7 +48,7 @@ class TestLeapMail(TestCase):
def test_as_dict(self):
mail = LeapMail('doc id', 'INBOX', {'From': 'test@example.test', 'Subject': 'A test Mail', 'To': 'receiver@example.test,receiver2@other.test'}, ('foo', 'bar'))
-
+ self.maxDiff = None
expected = {
'header': {
'from': 'test@example.test',
@@ -64,8 +64,8 @@ class TestLeapMail(TestCase):
'textPlainBody': None,
'replying': {'all': {'cc-field': [],
'to-field': ['receiver@example.test',
- 'receiver2@other.test',
- 'test@example.test']},
+ 'test@example.test',
+ 'receiver2@other.test']},
'single': 'test@example.test'},
'attachments': []
}
@@ -98,6 +98,18 @@ class TestLeapMail(TestCase):
self.assertEqual([expected_address], mail.as_dict()['header']['cc'])
self.assertEqual(expected_subject, mail.as_dict()['header']['subject'])
+ def test_as_dict_replying_with_special_chars(self):
+ expected_address = u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\xf6@example.mail>'
+ mail = LeapMail('', 'INBOX',
+ {'From': '=?iso-8859-1?q?=22=C4lbert_=DCbr=F6=22_=3C=E4=FC=F6=40example=2Email=3E?=',
+ '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'])
+
def test_raw_constructed_by_headers_and_body(self):
body = 'some body content'
mail = LeapMail('doc id', 'INBOX', {'From': 'test@example.test', 'Subject': 'A test Mail', 'To': 'receiver@example.test'}, ('foo', 'bar'), body=body)