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_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_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_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_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_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(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_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_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_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_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_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_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_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_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_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_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_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_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_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_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"])