def test_as_dict(self): mail = LeapMail('doc id', 'INBOX', {'From': '*****@*****.**', 'Subject': 'A test Mail', 'To': '[email protected],[email protected]'}, ('foo', 'bar')) expected = { 'header': { 'from': '*****@*****.**', 'subject': 'A test Mail', 'to': ['*****@*****.**', '*****@*****.**'], }, 'ident': 'doc id', 'mailbox': 'inbox', 'tags': {'foo', 'bar'}, 'status': [], 'body': None, 'textPlainBody': None, 'replying': {'all': {'cc-field': [], 'to-field': ['*****@*****.**', '*****@*****.**', '*****@*****.**']}, 'single': '*****@*****.**'}, 'attachments': [] } self.assertEqual(expected, mail.as_dict())
def test_reply_all_result_does_contain_own_address_if_only_recipient(self): my_address = "*****@*****.**" with patch("pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS", my_address): mail = LeapMail("", "INBOX", {"From": "*****@*****.**", "To": "*****@*****.**"}) self.assertEqual(["*****@*****.**"], mail.as_dict()["replying"]["all"]["to-field"])
def test_as_dict(self): mail = LeapMail( "doc id", "INBOX", {"From": "*****@*****.**", "Subject": "A test Mail", "To": "[email protected],[email protected]"}, ("foo", "bar"), ) self.maxDiff = None expected = { "header": { "from": "*****@*****.**", "subject": "A test Mail", "to": ["*****@*****.**", "*****@*****.**"], }, "ident": "doc id", "mailbox": "inbox", "tags": {"foo", "bar"}, "status": [], "body": None, "textPlainBody": None, "security_casing": {"imprints": [{"state": "no_signature_information"}], "locks": []}, "replying": { "all": { "cc-field": [], "to-field": ["*****@*****.**", "*****@*****.**", "*****@*****.**"], }, "single": "*****@*****.**", }, "attachments": [], } self.assertEqual(expected, mail.as_dict())
def test_reply_result_swaps_sender_and_recipient_if_i_am_the_sender(self): my_address = "*****@*****.**" with patch("pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS", my_address): mail = LeapMail("", "INBOX", {"From": "*****@*****.**", "To": "*****@*****.**"}) self.assertEqual("*****@*****.**", mail.as_dict()["replying"]["single"])
def test_security_casing(self): # No Encryption, no Signature mail = LeapMail('id', 'INBOX', {}) self.assertEqual( { 'locks': [], 'imprints': [{ 'state': 'no_signature_information' }] }, mail.security_casing) # Encryption mail = LeapMail('id', 'INBOX', {'X-Leap-Encryption': 'decrypted'}) self.assertEqual([{'state': 'valid'}], mail.security_casing['locks']) mail = LeapMail('id', 'INBOX', {'X-Leap-Encryption': 'false'}) self.assertEqual([], mail.security_casing['locks']) # Signature mail = LeapMail('id', 'INBOX', {'X-Leap-Signature': 'valid'}) self.assertEqual([{ 'seal': { 'validity': 'valid' }, 'state': 'valid' }], mail.security_casing['imprints']) mail = LeapMail('id', 'INBOX', {'X-Leap-Signature': 'invalid'}) self.assertEqual([], mail.security_casing['imprints'])
def test_as_dict(self): mail = LeapMail('doc id', 'INBOX', {'From': '*****@*****.**', 'Subject': 'A test Mail', 'To': '[email protected],[email protected]'}, ('foo', 'bar')) self.maxDiff = None expected = { 'header': { 'from': '*****@*****.**', 'subject': 'A test Mail', 'to': ['*****@*****.**', '*****@*****.**'], }, 'ident': 'doc id', 'mailbox': 'inbox', 'tags': {'foo', 'bar'}, 'status': [], 'body': None, 'textPlainBody': None, 'security_casing': { 'imprints': [{'state': 'no_signature_information'}], 'locks': [] }, 'replying': {'all': {'cc-field': [], 'to-field': ['*****@*****.**', '*****@*****.**', '*****@*****.**']}, 'single': '*****@*****.**'}, 'attachments': [] } self.assertEqual(expected, mail.as_dict())
def test_as_dict(self): mail = LeapMail( 'doc id', 'INBOX', { 'From': '*****@*****.**', 'Subject': 'A test Mail', 'To': '[email protected],[email protected]' }, ('foo', 'bar')) self.maxDiff = None expected = { 'header': { 'from': '*****@*****.**', 'subject': 'A test Mail', 'to': ['*****@*****.**', '*****@*****.**'], }, 'ident': 'doc id', 'mailbox': 'inbox', 'tags': {'foo', 'bar'}, 'status': [], 'body': None, 'textPlainBody': None, 'security_casing': { 'imprints': [{ 'state': 'no_signature_information' }], 'locks': [] }, 'attachments': [] } self.assertEqual(expected, mail.as_dict())
def test_reply_all_result_does_not_contain_own_address_in_cc(self): my_address = "*****@*****.**" with patch("pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS", my_address): mail = LeapMail("", "INBOX", {"From": "*****@*****.**", "To": "*****@*****.**", "Cc": my_address}) self.assertEqual([], mail.as_dict()["replying"]["all"]["cc-field"])
def test_reply_all_result_does_not_contain_own_address_in_to_with_name(self): my_address = '*****@*****.**' with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address): mail = LeapMail('', 'INBOX', {'From': '*****@*****.**', 'To': '[email protected], Folker Bernitt <%s>' % my_address}) self.assertEqual(['*****@*****.**', '*****@*****.**'], mail.as_dict()['replying']['all']['to-field'])
def test_reply_all_result_does_contain_own_address_if_only_recipient(self): my_address = '*****@*****.**' with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address): mail = LeapMail('', 'INBOX', {'From': '*****@*****.**', 'To': '*****@*****.**'}) self.assertEqual(['*****@*****.**'], mail.as_dict()['replying']['all']['to-field'])
def test_reply_result_swaps_sender_and_recipient_if_i_am_the_sender(self): my_address = '*****@*****.**' with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address): mail = LeapMail('', 'INBOX', {'From': '*****@*****.**', 'To': '*****@*****.**'}) self.assertEqual('*****@*****.**', mail.as_dict()['replying']['single'])
def test_reply_all_result_does_not_contain_own_address_in_to_with_encoded(self): my_address = '*****@*****.**' with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address): mail = LeapMail('', 'INBOX', {'From': '*****@*****.**', 'To': '[email protected], =?iso-8859-1?q?=C4lbert_=3Cmyaddress=40example=2Etest=3E?='}) self.assertEqual(['*****@*****.**', '*****@*****.**'], mail.as_dict()['replying']['all']['to-field'])
def test_reply_all_result_does_not_contain_own_address_in_cc(self): my_address = '*****@*****.**' with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address): mail = LeapMail('', 'INBOX', {'From': '*****@*****.**', 'To': '*****@*****.**', 'Cc': my_address}) self.assertEqual([my_address], mail.as_dict()['replying']['all']['cc-field'])
def test_as_dict_replying_with_special_chars(self): expected_address = u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\[email protected]>' 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_as_dict_with_body(self): body = "some body content" mail = LeapMail( "doc id", "INBOX", {"From": "*****@*****.**", "Subject": "A test Mail", "To": "*****@*****.**"}, ("foo", "bar"), body=body, ) self.assertEqual(body, mail.as_dict()["body"])
def test_as_dict_with_body(self): body = 'some body content' mail = LeapMail('doc id', 'INBOX', { 'From': '*****@*****.**', 'Subject': 'A test Mail', 'To': '*****@*****.**' }, ('foo', 'bar'), body=body) self.assertEqual(body, mail.as_dict()['body'])
def test_as_dict_headers_with_special_chars(self): expected_address = u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\[email protected]>' expected_subject = u'H\xe4ll\xf6 W\xf6rld' 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()['header']['from']) self.assertEqual([expected_address], mail.as_dict()['header']['to']) self.assertEqual([expected_address], mail.as_dict()['header']['cc']) self.assertEqual(expected_subject, mail.as_dict()['header']['subject'])
def test_reply_all_result_does_not_contain_own_address_in_to_with_spaces(self): my_address = '*****@*****.**' with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address): mail = LeapMail('', 'INBOX', {'From': '*****@*****.**', 'To': '[email protected], %s ' % my_address}) expected_recipients = ['*****@*****.**', '*****@*****.**'] actual_recipients = mail.as_dict()['replying']['all']['to-field'] expected_recipients.sort() actual_recipients.sort() self.assertEqual(expected_recipients, actual_recipients)
def test_reply_all_does_not_contain_own_address_in_to_field_with_different_encodings(self): my_address = '*****@*****.**' with patch('pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS', my_address): mail = LeapMail('', 'INBOX', {'From': '*****@*****.**', 'To': '[email protected], =?iso-8859-1?q?=C4lbert_=3Cmyaddress=40example=2Etest=3E?='}) expected_recipients = [u'*****@*****.**', u'*****@*****.**'] actual_recipients = mail.as_dict()['replying']['all']['to-field'] expected_recipients.sort() actual_recipients.sort() self.assertEqual(expected_recipients, actual_recipients)
def test_other_methods_are_delegated(self): mail = LeapMail('mail id', ANY_MAILBOX) when(self.delegate_mail_store).get_mail('mail id').thenReturn( defer.succeed(mail), defer.succeed(mail)) result = yield self.store.get_mail('mail id') self.assertEqual(mail, result)
def test_contents_encoding_special_characters(self): # given se = SearchEngine(INDEX_KEY, self.user_home) headers = { 'From': '*****@*****.**', 'To': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=', 'Cc': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=', 'Subject': 'Some test mail', 'Date': str(datetime.now()) } body = "When doing the search, 您好 أهلا" # when se.index_mail( LeapMail('mailid', 'INBOX', headers=headers, body=body) ) # test_helper.pixelated_mail(extra_headers=headers, chash='mailid')) result = se.search(u"您好") self.assertEqual((['mailid'], 1), result) result = se.search(u"أهلا") self.assertEqual((['mailid'], 1), result)
def test_contents_encoding_accents(self): # given se = SearchEngine(INDEX_KEY, self.user_home) headers = { 'From': '*****@*****.**', 'To': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=', 'Cc': '=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?=', 'Subject': 'Some test mail', 'Date': str(datetime.now()) } body = "When doing the search, it's not possible to find words with graphical accents, e.g.: 'coração', 'é', 'Fièvre', La Pluie d'été, 'não'." # when se.index_mail( LeapMail('mailid', 'INBOX', headers=headers, body=body) ) # test_helper.pixelated_mail(extra_headers=headers, chash='mailid')) result = se.search(u"'coração', 'é',") self.assertEqual((['mailid'], 1), result) result = se.search(u"Fièvre") self.assertEqual((['mailid'], 1), result) result = se.search(u"été") self.assertEqual((['mailid'], 1), result)
def test_send_mail_marks_as_read(self): mail = LeapMail('id', 'INBOX') when(mail).raw = 'raw mail' when(InputMail).from_dict(ANY()).thenReturn(mail) when(self.mail_store).delete_mail('12').thenReturn(defer.succeed(None)) when(self.mail_sender).sendmail(ANY()).thenReturn(defer.succeed(None)) sent_mail = LeapMail('id', 'INBOX') add_mail_deferral = defer.succeed(sent_mail) when(self.mail_store).add_mail('SENT', ANY()).thenReturn(add_mail_deferral) yield self.mail_service.send_mail({'ident': '12'}) self.assertIn(Status.SEEN, sent_mail.flags) verify(self.mail_store).update_mail(sent_mail)
def test_as_dict_replying_with_special_chars(self): expected_address = u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\[email protected]>' 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_reply_all_result_does_not_contain_own_address_in_to_with_encoded(self): my_address = "*****@*****.**" with patch("pixelated.adapter.mailstore.leap_mailstore.InputMail.FROM_EMAIL_ADDRESS", my_address): mail = LeapMail( "", "INBOX", { "From": "*****@*****.**", "To": "[email protected], =?iso-8859-1?q?=C4lbert_=3Cmyaddress=40example=2Etest=3E?=", }, ) self.assertEqual( ["*****@*****.**", "*****@*****.**"], mail.as_dict()["replying"]["all"]["to-field"] )
def test_delete_mail(self): mail_to_delete = LeapMail(1, 'INBOX') when(self.mail_store).get_mail(1, include_body=True).thenReturn(defer.succeed(mail_to_delete)) yield self.mail_service.delete_mail(1) verify(self.mail_store).move_mail_to_mailbox(1, 'TRASH')
def test_as_dict_with_attachments(self): attachment_info = AttachmentInfo('id', 'name', 'encoding', ctype='text/plain', size=2) mail = LeapMail('doc id', 'INBOX', attachments=[attachment_info]) self.assertEqual([{ 'ident': 'id', 'name': 'name', 'encoding': 'encoding', 'content-type': 'text/plain', 'size': 2 }], mail.as_dict()['attachments'])
def test_update_mail_delegates_to_mail_store_and_updates_index(self): leap_mail = LeapMail('id', ANY_MAILBOX) yield self.store.update_mail(leap_mail) verify(self.delegate_mail_store).update_mail(leap_mail) verify(self.search_index).index_mail(leap_mail)
def test_mark_as_read(self): mail = LeapMail(1, 'INBOX') when(self.mail_store).get_mail(1, include_body=True).thenReturn(mail) yield self.mail_service.mark_as_read(1) self.assertIn(Status.SEEN, mail.flags) verify(self.mail_store).update_mail(mail)
def test_recover_mail(self): mail_to_recover = LeapMail(1, 'TRASH') when(self.mail_service).mail(1).thenReturn(mail_to_recover) when(self.mail_store).move_mail_to_mailbox(1, 'INBOX').thenReturn(mail_to_recover) yield self.mail_service.recover_mail(1) verify(self.mail_store).move_mail_to_mailbox(1, 'INBOX')
def test_raw_constructed_by_headers_and_body(self): body = 'some body content' mail = LeapMail('doc id', 'INBOX', {'From': '*****@*****.**', 'Subject': 'A test Mail', 'To': '*****@*****.**'}, ('foo', 'bar'), body=body) result = mail.raw expected_raw = 'To: [email protected]\nFrom: [email protected]\nSubject: A test Mail\n\nsome body content' self.assertEqual(expected_raw, result)
def test_send_mail_removes_draft(self): mail = LeapMail('id', 'INBOX') when(mail).raw = 'raw mail' mail._headers['To'] = [] mail._headers['Cc'] = [] mail._headers['Bcc'] = [] when(InputMail).from_dict(ANY(), ANY()).thenReturn(mail) when(self.mail_store).delete_mail('12').thenReturn(defer.succeed(None)) when(self.mail_store).add_mail('SENT', ANY()).thenReturn(mail) deferred_success = defer.succeed(None) when(self.mail_sender).sendmail(ANY()).thenReturn(deferred_success) yield self.mail_service.send_mail({'ident': '12'}) verify(self.mail_sender).sendmail(mail) verify(self.mail_store).add_mail('SENT', mail.raw) verify(self.mail_store).delete_mail('12')
def test_copy_mail_delegates_to_mail_store_and_updates_index(self): copied_mail = LeapMail('new id', ANY_MAILBOX) when(self.delegate_mail_store).copy_mail_to_mailbox( 'mail id', ANY_MAILBOX).thenReturn(defer.succeed(copied_mail)) result = yield self.store.copy_mail_to_mailbox('mail id', ANY_MAILBOX) verify(self.search_index).index_mail(copied_mail) self.assertEqual(copied_mail, result)
def test_as_dict_headers_with_special_chars(self): expected_address = u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\[email protected]>' expected_subject = u"H\xe4ll\xf6 W\xf6rld" 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()["header"]["from"]) self.assertEqual([expected_address], mail.as_dict()["header"]["to"]) self.assertEqual([expected_address], mail.as_dict()["header"]["cc"]) self.assertEqual(expected_subject, mail.as_dict()["header"]["subject"])
def test_update_tags_return_a_set_with_the_current_tags(self): mail = LeapMail(1, 'INBOX', tags={'custom_1', 'custom_2'}) when(self.mail_store).get_mail(1, include_body=True).thenReturn(mail) when(self.search_engine).tags(query='', skip_default_tags=True).thenReturn([]) updated_mail = yield self.mail_service.update_tags(1, {'custom_1', 'custom_3'}) verify(self.mail_store).update_mail(mail) self.assertEqual({'custom_1', 'custom_3'}, updated_mail.tags)
def test_update_draft(self): mail = InputMail.from_dict(test_helper.mail_dict(), from_address='pixelated@org') when(self.mail_store).delete_mail(mail.ident).thenReturn(defer.succeed(True)) when(self.mail_store).add_mail('DRAFTS', mail.raw).thenReturn(defer.succeed(LeapMail('id', 'DRAFTS'))) self.draft_service.update_draft(mail.ident, mail) inorder.verify(self.mail_store).delete_mail(mail.ident) inorder.verify(self.mail_store).add_mail('DRAFTS', mail.raw)
def test_mark_as_unread(self): mail = LeapMail(1, 'INBOX') mail.flags.add(Status.SEEN) when(self.mail_store).get_mail(1, include_body=True).thenReturn(mail) yield self.mail_service.mark_as_unread(1) verify(self.mail_store).update_mail(mail) self.assertNotEqual(mail.status, Status.SEEN)
def test_add_mail_delegates_to_mail_store_and_updates_index(self): mail = self._load_mail_from_file('mbox00000000') leap_mail = LeapMail('id', ANY_MAILBOX) when(self.delegate_mail_store).add_mail(ANY_MAILBOX, mail).thenReturn( defer.succeed(leap_mail)) result = yield self.store.add_mail(ANY_MAILBOX, mail) verify(self.delegate_mail_store).add_mail(ANY_MAILBOX, mail) verify(self.search_index).index_mail(leap_mail) self.assertEqual(leap_mail, result)
def test_leap_mail(self): mail = LeapMail( '', 'INBOX', { 'From': '*****@*****.**', 'Subject': 'A test Mail', 'To': '*****@*****.**' }) self.assertEqual('*****@*****.**', mail.from_sender) self.assertEqual(['*****@*****.**'], mail.to) self.assertEqual('A test Mail', mail.subject)
def test_encoding(self): # given se = SearchEngine(INDEX_KEY, self.agent_home) headers = { 'From': '*****@*****.**', '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( LeapMail('mailid', 'INBOX', headers=headers) ) # test_helper.pixelated_mail(extra_headers=headers, chash='mailid')) result = se.search('folker') self.assertEqual((['mailid'], 1), result)
def test_as_dict_with_attachments(self): attachment_info = AttachmentInfo('id', 'name', 'encoding', ctype='text/plain', size=2) mail = LeapMail('doc id', 'INBOX', attachments=[attachment_info]) self.assertEqual([{'ident': 'id', 'name': 'name', 'encoding': 'encoding', 'content-type': 'text/plain', 'size': 2}], mail.as_dict()['attachments'])
def test_as_dict_with_attachments(self): mail = LeapMail('doc id', 'INBOX', attachments=[AttachmentInfo('id', 'name', 'encoding')]) self.assertEqual([{'ident': 'id', 'name': 'name', 'encoding': 'encoding'}], mail.as_dict()['attachments'])
def test_as_dict_with_body(self): body = 'some body content' mail = LeapMail('doc id', 'INBOX', {'From': '*****@*****.**', 'Subject': 'A test Mail', 'To': '*****@*****.**'}, ('foo', 'bar'), body=body) self.assertEqual(body, mail.as_dict()['body'])
def test_as_dict_with_mixed_encodings(self): subject = 'Another test with =?iso-8859-1?B?3G1s5Px0?= =?iso-8859-1?Q?s?=' mail = LeapMail('', 'INBOX', {'Subject': subject}) self.assertEqual(u'Another test with Ümläüts', mail.as_dict()['header']['subject'])
def test_as_dict_with_attachments(self): mail = LeapMail("doc id", "INBOX", attachments=[AttachmentInfo("id", "name", "encoding")]) self.assertEqual([{"ident": "id", "name": "name", "encoding": "encoding"}], mail.as_dict()["attachments"])
def test_email_addresses_might_be_empty_array(self): mail = LeapMail('', 'INBOX', {'Cc': None}) self.assertEqual([], mail.headers['Cc'])
def test_email_addresses_in_bcc_are_split_into_a_list(self): mail = LeapMail('', 'INBOX', {'Bcc': '[email protected],[email protected]'}) self.assertEqual(['*****@*****.**', '*****@*****.**'], mail.headers['Bcc'])
def test_headers_none_recipients_are_converted_to_empty_array(self): mail = LeapMail('id', 'INBOX', {'To': None, 'Cc': None, 'Bcc': None}) self.assertEquals([], mail.headers['To']) self.assertEquals([], mail.headers['Cc']) self.assertEquals([], mail.headers['Bcc'])
def test_as_dict_with_mixed_encodings(self): subject = "Another test with =?iso-8859-1?B?3G1s5Px0?= =?iso-8859-1?Q?s?=" mail = LeapMail("", "INBOX", {"Subject": subject}) self.assertEqual(u"Another test with Ümläüts", mail.as_dict()["header"]["subject"])