diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-03-20 13:45:29 +0100 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-03-20 13:45:29 +0100 |
commit | d43abfceecee6051f6c29c48e64a073455356cb5 (patch) | |
tree | c507ca77756772542dc5b8c1ea8b4ed142753c08 /service/test/unit/adapter | |
parent | e500877b7de0fa1f249887e7afe089f560094893 (diff) |
Added support for encoded To, Cc and Bcc headers.
- Issue #248
Diffstat (limited to 'service/test/unit/adapter')
-rw-r--r-- | service/test/unit/adapter/search/test_search.py | 31 | ||||
-rw-r--r-- | service/test/unit/adapter/test_mail.py | 13 |
2 files changed, 42 insertions, 2 deletions
diff --git a/service/test/unit/adapter/search/test_search.py b/service/test/unit/adapter/search/test_search.py index a3726b88..d57b8227 100644 --- a/service/test/unit/adapter/search/test_search.py +++ b/service/test/unit/adapter/search/test_search.py @@ -50,11 +50,40 @@ class SearchEngineTest(unittest.TestCase): soledad_querier = mock() lock_stub = LockStub() when(soledad_querier).get_index_masterkey().thenReturn(INDEX_KEY) + + self.assertEqual(INDEX_KEY, soledad_querier.get_index_masterkey()) se = SearchEngine(soledad_querier, self.agent_home) se._write_lock = lock_stub + headers = { + 'From': 'from@bar.tld', + 'To': 'to@bar.tld', + 'Subject': 'Some test mail', + } + # when - se.index_mail(test_helper.pixelated_mail()) + se.index_mail(test_helper.pixelated_mail(extra_headers=headers)) # then self.assertTrue(lock_stub.called) + + def test_encoding(self): + # given + soledad_querier = mock() + when(soledad_querier).get_index_masterkey().thenReturn(INDEX_KEY) + + se = SearchEngine(soledad_querier, self.agent_home) + + headers = { + 'From': 'foo@bar.tld', + 'To': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=', + 'Cc': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=', + 'Subject': 'Some test mail', + } + + # when + se.index_mail(test_helper.pixelated_mail(extra_headers=headers, chash='mailid')) + + result = se.search('folker') + + self.assertEqual((['mailid'], 1), result) diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py index fc0861d6..1b83f79e 100644 --- a/service/test/unit/adapter/test_mail.py +++ b/service/test/unit/adapter/test_mail.py @@ -306,22 +306,33 @@ class TestPixelatedMail(unittest.TestCase): def test_encoding_special_character_on_header(self): subject = "=?UTF-8?Q?test_encoding_St=C3=A4ch?=" email_from = "=?UTF-8?Q?St=C3=A4ch_<stach@pixelated-project.org>?=" + email_to = "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=" pixel_mail = PixelatedMail() self.assertEqual(pixel_mail._decode_header(subject), 'test encoding St\xc3\xa4ch') self.assertEqual(pixel_mail._decode_header(email_from), 'St\xc3\xa4ch <stach@pixelated-project.org>') + self.assertEqual(pixel_mail._decode_header(email_to), '"\xc3\x84\xc3\xbc\xc3\xb6 \xc3\x96\xc3\xbc\xc3\xa4" <folker@pixelated-project.org>, F\xc3\xb6lker <folker@pixelated-project.org>') + self.assertEqual(pixel_mail._decode_header(None), None) def test_headers_are_encoded_right(self): subject = "=?UTF-8?Q?test_encoding_St=C3=A4ch?=" email_from = "=?UTF-8?Q?St=C3=A4ch_<stach@pixelated-project.org>?=" + email_to = "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=" + email_cc = "=?UTF-8?Q?St=C3=A4ch_<stach@pixelated-project.org>?=" + email_bcc = "=?UTF-8?Q?St=C3=A4ch_<stach@pixelated-project.org>?=" - leap_mail = test_helper.leap_mail(extra_headers={'Subject': subject, 'From': email_from}) + leap_mail = test_helper.leap_mail(extra_headers={'Subject': subject, 'From': email_from, 'To': email_to, 'Cc': email_cc, 'Bcc': email_bcc}) mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier) self.assertEqual(str(mail.headers['Subject']), 'test encoding St\xc3\xa4ch') self.assertEqual(str(mail.headers['From']), 'St\xc3\xa4ch <stach@pixelated-project.org>') + self.assertEqual(mail.headers['To'], ['"\xc3\x84\xc3\xbc\xc3\xb6 \xc3\x96\xc3\xbc\xc3\xa4" <folker@pixelated-project.org>', 'F\xc3\xb6lker <folker@pixelated-project.org>']) + self.assertEqual(mail.headers['Cc'], ['St\xc3\xa4ch <stach@pixelated-project.org>']) + self.assertEqual(mail.headers['Bcc'], ['St\xc3\xa4ch <stach@pixelated-project.org>']) + + mail.as_dict() class InputMailTest(unittest.TestCase): |