def test_index_is_initialized_with_mail_tags_if_empty(self):
        mail_one = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=0, extra_headers={'X-Tags': '["tag_1"]'}))
        mail_two = PixelatedMail.from_soledad(*test_helper.leap_mail(uid=1, extra_headers={'X-Tags': '["tag_2"]'}))
        mails = [mail_one, mail_two]

        self.tag_service.load_index(mails)

        self.assertEqual(self.tag_service.all_tags(), {Tag('sent'), Tag('inbox'), Tag('drafts'), Tag('trash'), Tag('tag_1'), Tag('tag_2')})
Пример #2
0
    def test_bounced_mails_are_recognized(self):
        bounced_mail_hdoc = os.path.join(os.path.dirname(__file__), '..', 'fixtures', 'bounced_mail_hdoc.json')
        with open(bounced_mail_hdoc) as f:
            hdoc = json.loads(f.read())

        bounced_leap_mail = test_helper.leap_mail()
        bounced_leap_mail[1].content = hdoc
        bounced_mail = PixelatedMail.from_soledad(*bounced_leap_mail, soledad_querier=self.querier)

        not_bounced_leap_mail = test_helper.leap_mail()
        not_bounced_mail = PixelatedMail.from_soledad(*not_bounced_leap_mail, soledad_querier=self.querier)

        self.assertTrue(bounced_mail.bounced)
        self.assertIn('*****@*****.**', bounced_mail.bounced)
        self.assertIn("[email protected] (Mail Delivery System)", bounced_mail.bounced)
        self.assertFalse(not_bounced_mail.bounced)
Пример #3
0
    def test_headers_are_encoded_right(self):
        subject = "=?UTF-8?Q?test_encoding_St=C3=A4ch?="
        email_from = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="
        email_to = "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?="
        email_cc = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="
        email_bcc = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="

        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)

        self.assertEqual(str(mail.headers["Subject"]), "test encoding St\xc3\xa4ch")
        self.assertEqual(str(mail.headers["From"]), "St\xc3\xa4ch <*****@*****.**>")
        self.assertEqual(
            mail.headers["To"],
            [
                '"\xc3\x84\xc3\xbc\xc3\xb6 \xc3\x96\xc3\xbc\xc3\xa4" <*****@*****.**>',
                "F\xc3\xb6lker <*****@*****.**>",
            ],
        )
        self.assertEqual(mail.headers["Cc"], ["St\xc3\xa4ch <*****@*****.**>"])
        self.assertEqual(mail.headers["Bcc"], ["St\xc3\xa4ch <*****@*****.**>"])

        mail.as_dict()
Пример #4
0
    def test_bounced_mails_are_recognized(self):
        bounced_mail_hdoc = pkg_resources.resource_filename("test.unit.fixtures", "bounced_mail_hdoc.json")
        with open(bounced_mail_hdoc) as f:
            hdoc = json.loads(f.read())

        bounced_leap_mail = test_helper.leap_mail()
        bounced_leap_mail[1].content = hdoc
        bounced_mail = PixelatedMail.from_soledad(*bounced_leap_mail)

        not_bounced_leap_mail = test_helper.leap_mail()
        not_bounced_mail = PixelatedMail.from_soledad(*not_bounced_leap_mail)

        self.assertTrue(bounced_mail.bounced)
        self.assertIn("*****@*****.**", bounced_mail.bounced)
        self.assertIn("[email protected] (Mail Delivery System)", bounced_mail.bounced)
        self.assertFalse(not_bounced_mail.bounced)
Пример #5
0
    def test_bounced_mails_are_recognized(self):
        bounced_mail_hdoc = os.path.join(os.path.dirname(__file__), '..', 'fixtures', 'bounced_mail_hdoc.json')
        with open(bounced_mail_hdoc) as f:
            hdoc = json.loads(f.read())

        bounced_leap_mail = test_helper.leap_mail()
        bounced_leap_mail[1].content = hdoc
        bounced_mail = PixelatedMail.from_soledad(*bounced_leap_mail, soledad_querier=self.querier)

        not_bounced_leap_mail = test_helper.leap_mail()
        not_bounced_mail = PixelatedMail.from_soledad(*not_bounced_leap_mail, soledad_querier=self.querier)

        self.assertTrue(bounced_mail.bounced)
        self.assertIn('*****@*****.**', bounced_mail.bounced)
        self.assertIn("[email protected] (Mail Delivery System)", bounced_mail.bounced)
        self.assertFalse(not_bounced_mail.bounced)
Пример #6
0
    def test_content_type_is_read_from_headers_for_plain_mail_when_converted_to_raw(self):
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'], body=u'some umlaut \xc3', extra_headers={'Content-Type': 'text/plain; charset=ISO-8859-1'})
        hdoc.content['headers']['Subject'] = 'The subject'
        hdoc.content['headers']['From'] = '*****@*****.**'
        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier)

        mail.raw
Пример #7
0
    def test_headers_are_encoded_right(self):
        subject = "=?UTF-8?Q?test_encoding_St=C3=A4ch?="
        email_from = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="
        email_to = "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?="
        email_cc = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="
        email_bcc = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="

        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 <*****@*****.**>')
        self.assertEqual(mail.headers['To'], [
            '"\xc3\x84\xc3\xbc\xc3\xb6 \xc3\x96\xc3\xbc\xc3\xa4" <*****@*****.**>',
            'F\xc3\xb6lker <*****@*****.**>'
        ])
        self.assertEqual(mail.headers['Cc'],
                         ['St\xc3\xa4ch <*****@*****.**>'])
        self.assertEqual(mail.headers['Bcc'],
                         ['St\xc3\xa4ch <*****@*****.**>'])

        mail.as_dict()
    def test_delete_mail(self):
        mail_to_delete = PixelatedMail.from_soledad(*leap_mail(), soledad_querier=None)
        when(self.mail_service).mail(1).thenReturn(mail_to_delete)

        self.mail_service.delete_mail(1)

        verify(self.mailboxes).move_to_trash(1)
Пример #9
0
    def test_as_dict(self):
        headers = {'Subject': 'The subject',
                   'From': '*****@*****.**',
                   'To': '*****@*****.**'}
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'],
                                                 extra_headers=headers)

        InputMail.FROM_EMAIL_ADDRESS = '*****@*****.**'

        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier)

        _dict = mail.as_dict()

        self.assertEquals(_dict, {'body': 'body',
                                  'header': {
                                      'date': dateparser.parse(hdoc.content['date']).isoformat(),
                                      'from': '*****@*****.**',
                                      'subject': 'The subject',
                                      'to': ['*****@*****.**'],
                                      'cc': [],
                                      'bcc': []
                                  },
                                  'ident': 'chash',
                                  'mailbox': 'inbox',
                                  'security_casing': {'imprints': [], 'locks': []},
                                  'status': ['recent'],
                                  'tags': [],
                                  'attachments': [],
                                  'replying': {
                                      'single': '*****@*****.**',
                                      'all': {
                                          'to-field': ['*****@*****.**'],
                                          'cc-field': []
                                      }
                                  }})
Пример #10
0
    def test_remove_message_from_mailbox(self):
        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
        when(self.querier).mail(1).thenReturn(mail)

        self.mailbox.remove(1)

        verify(self.querier).remove_mail(mail)
Пример #11
0
    def test_as_dict(self):
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'])
        hdoc.content['headers']['Subject'] = 'The subject'
        hdoc.content['headers']['From'] = '*****@*****.**'

        mail = PixelatedMail.from_soledad(fdoc,
                                          hdoc,
                                          bdoc,
                                          soledad_querier=self.querier)

        _dict = mail.as_dict()

        self.assertEquals(
            _dict, {
                'body': 'body',
                'header': {
                    'date': dateparser.parse(hdoc.content['date']).isoformat(),
                    'from': '*****@*****.**',
                    'subject': 'The subject'
                },
                'ident': 'chash',
                'mailbox': 'inbox',
                'security_casing': {
                    'imprints': [],
                    'locks': []
                },
                'status': ['recent'],
                'tags': [],
                'attachments': []
            })
Пример #12
0
    def test_use_reply_to_address_for_replying(self):
        headers = {
            'Subject': 'The subject',
            'From': '*****@*****.**',
            'Reply-To': '*****@*****.**',
            'To': '[email protected], \[email protected]'
        }
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'],
                                                 extra_headers=headers)

        InputMail.FROM_EMAIL_ADDRESS = '*****@*****.**'

        mail = PixelatedMail.from_soledad(fdoc,
                                          hdoc,
                                          bdoc,
                                          soledad_querier=self.querier)

        _dict = mail.as_dict()

        self.assertEquals(
            _dict['replying'], {
                'single': '*****@*****.**',
                'all': {
                    'to-field': [
                        '*****@*****.**',
                        '*****@*****.**'
                    ],
                    'cc-field': []
                }
            })
Пример #13
0
    def test_mark_as_read(self):
        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(flags=[]),
                                          soledad_querier=self.querier)

        mail.mark_as_read()

        self.assertEquals(mail.fdoc.content['flags'], ['\\Seen'])
Пример #14
0
    def test_update_tags_return_a_set_with_the_current_tags(self):
        soledad_docs = test_helper.leap_mail(
            extra_headers={'X-tags': '["custom_1", "custom_2"]'})
        pixelated_mail = PixelatedMail.from_soledad(
            *soledad_docs, soledad_querier=self.querier)

        current_tags = pixelated_mail.update_tags({'custom_1', 'custom_3'})
        self.assertEquals({'custom_3', 'custom_1'}, current_tags)
    def test_recover_mail(self):
        mail_to_recover = PixelatedMail.from_soledad(*leap_mail(), soledad_querier=None)
        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')
Пример #16
0
    def test_delete_mail(self):
        mail_to_delete = PixelatedMail.from_soledad(*leap_mail(),
                                                    soledad_querier=None)
        when(self.mail_service).mail(1).thenReturn(mail_to_delete)

        self.mail_service.delete_mail(1)

        verify(self.mailboxes).move_to_trash(1)
    def test_remove_message_from_mailbox(self):
        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(),
                                          soledad_querier=self.querier)
        when(self.querier).mail(1).thenReturn(mail)

        self.mailbox.remove(1)

        verify(self.querier).remove_mail(mail)
    def test_move_to_inbox(self):
        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
        when(self.querier).mail(1).thenReturn(mail)
        when(mail).save().thenReturn(None)

        mail.set_mailbox('TRASH')
        recovered_mail = yield self.mailboxes.move_to_inbox(1)
        self.assertEquals('INBOX', recovered_mail.mailbox_name)
        verify(mail).save()
    def test_recover_mail(self):
        mail_to_recover = PixelatedMail.from_soledad(*leap_mail(), soledad_querier=None)
        when(self.mail_service).mail(1).thenReturn(mail_to_recover)
        when(self.mailboxes).move_to_inbox(1).thenReturn(mail_to_recover)

        self.mail_service.recover_mail(1)

        verify(self.mailboxes).move_to_inbox(1)
        verify(self.search_engine).index_mail(mail_to_recover)
Пример #20
0
    def test_parse_date_from_soledad_uses_date_header_if_available(self):
        leap_mail_date = 'Wed, 3 Sep 2014 12:36:17 -0300'
        leap_mail_date_in_iso_format = "2014-09-03T12:36:17-03:00"

        leap_mail = test_helper.leap_mail(headers={'date': leap_mail_date})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format)
Пример #21
0
    def test_parse_date_from_soledad_uses_date_header_if_available(self):
        leap_mail_date = 'Wed, 3 Sep 2014 12:36:17 -0300'
        leap_mail_date_in_iso_format = "2014-09-03T12:36:17-03:00"

        leap_mail = test_helper.leap_mail(headers={'date': leap_mail_date})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format)
Пример #22
0
    def test_parse_date_from_soledad_uses_date_header_if_available(self):
        leap_mail_date = "Wed, 3 Sep 2014 12:36:17 -0300"
        leap_mail_date_in_iso_format = "2014-09-03T12:36:17-03:00"

        leap_mail = test_helper.leap_mail(headers={"date": leap_mail_date})

        mail = PixelatedMail.from_soledad(*leap_mail)

        self.assertEqual(str(mail.headers["Date"]), leap_mail_date_in_iso_format)
Пример #23
0
    def test_parse_date_from_soledad_fallback_to_received_header_if_date_header_isnt_available(self):
        leap_mail_date = "Wed, 03 Sep 2014 13:11:15 -0300"
        leap_mail_date_in_iso_format = "2014-09-03T13:11:15-03:00"
        leap_mail_received_header = "by bitmask.local from 127.0.0.1 with ESMTP ;\n " + leap_mail_date

        leap_mail = test_helper.leap_mail(headers={'received': leap_mail_received_header})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format)
Пример #24
0
    def test_recover_mail(self):
        mail_to_recover = PixelatedMail.from_soledad(*leap_mail(),
                                                     soledad_querier=None)
        when(self.mail_service).mail(1).thenReturn(mail_to_recover)
        when(self.mailboxes).move_to_inbox(1).thenReturn(mail_to_recover)

        self.mail_service.recover_mail(1)

        verify(self.mailboxes).move_to_inbox(1)
        verify(self.search_engine).index_mail(mail_to_recover)
    def test_update_tags_notifies_tag_service(self):
        db_path = '/tmp/test_update_tags_notifies_tag_service'
        TagService.instance = TagService(TagIndex(db_path))

        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)

        mail.update_tags({'new_tag'})
        self.assertIn(Tag('new_tag'), mail.tag_service.all_tags())

        os.remove(db_path + '.db')
Пример #26
0
    def test_move_to_inbox(self):
        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(),
                                          soledad_querier=self.querier)
        when(self.querier).mail(1).thenReturn(mail)
        when(mail).save().thenReturn(None)

        mail.set_mailbox('TRASH')
        recovered_mail = yield self.mailboxes.move_to_inbox(1)
        self.assertEquals('INBOX', recovered_mail.mailbox_name)
        verify(mail).save()
Пример #27
0
    def test_that_body_understands_base64(self):
        body = u"bl\xe1"
        encoded_body = unicode(body.encode("utf-8").encode("base64"))

        fdoc, hdoc, bdoc = test_helper.leap_mail()
        parts = {"alternatives": []}
        parts["alternatives"].append({"content": encoded_body, "headers": {"Content-Transfer-Encoding": "base64"}})
        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, parts=parts)

        self.assertEquals(body, mail.text_plain_body)
Пример #28
0
    def test_fall_back_to_ascii_if_invalid_received_header(self):
        leap_mail_received_header = u"söme invalid received heäder\n"
        date_expected = "2014-09-03T13:11:15-03:00"

        when(pixelated.support.date).iso_now().thenReturn(date_expected)
        leap_mail = test_helper.leap_mail(headers={'received': leap_mail_received_header})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(mail.headers['Date'], date_expected)
Пример #29
0
    def test_that_body_understands_8bit(self):
        body = u"testtext"
        encoded_body = body

        fdoc, hdoc, bdoc = test_helper.leap_mail()
        parts = {"alternatives": []}
        parts["alternatives"].append({"content": encoded_body, "headers": {"Content-Transfer-Encoding": "8bit"}})
        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, parts=parts)

        self.assertEquals(body, mail.text_plain_body)
Пример #30
0
    def test_parse_date_from_soledad_fallback_to_now_if_neither_date_nor_received_header(self):
        leap_mail_date_in_iso_format = "2014-09-03T13:11:15-03:00"

        when(pixelated.support.date).iso_now().thenReturn(leap_mail_date_in_iso_format)
        fdoc, hdoc, bdoc = test_helper.leap_mail()
        del hdoc.content['date']

        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format)
Пример #31
0
    def test_parse_UTF8_headers_with_CharsetAscii(self):
        leap_mail_from = u'"söme ümläuds" <*****@*****.**>'
        leap_mail_to = u'"söme ümläuds" <*****@*****.**>,\n"söme ümläuds" <*****@*****.**>'

        leap_mail = test_helper.leap_mail(extra_headers={'From': leap_mail_from, 'Subject': "some subject", 'To': leap_mail_to})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        mail.headers['From'].encode('ascii')
        self.assertEqual(mail.headers['To'], ['"sme mluds" <*****@*****.**>', '"sme mluds" <*****@*****.**>'])
Пример #32
0
    def test_that_body_understands_base64(self):
        body = u'bl\xe1'
        encoded_body = unicode(body.encode('utf-8').encode('base64'))

        fdoc, hdoc, bdoc = test_helper.leap_mail()
        parts = {'alternatives': []}
        parts['alternatives'].append({'content': encoded_body, 'headers': {'Content-Transfer-Encoding': 'base64'}})
        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier, parts=parts)

        self.assertEquals(body, mail.text_plain_body)
Пример #33
0
    def test_that_body_understands_8bit(self):
        body = u'testtext'
        encoded_body = body

        fdoc, hdoc, bdoc = test_helper.leap_mail()
        parts = {'alternatives': []}
        parts['alternatives'].append({'content': encoded_body, 'headers': {'Content-Transfer-Encoding': '8bit'}})
        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier, parts=parts)

        self.assertEquals(body, mail.text_plain_body)
Пример #34
0
    def test_use_datetime_now_as_fallback_for_invalid_date(self):
        leap_mail_date = u'söme däte'
        date_expected = "2014-09-03T13:11:15-03:00"

        when(pixelated.support.date).iso_now().thenReturn(date_expected)
        leap_mail = test_helper.leap_mail(headers={'date': leap_mail_date})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), date_expected)
Пример #35
0
    def test_that_body_understands_base64(self):
        body = u'bl\xe1'
        encoded_body = unicode(body.encode('utf-8').encode('base64'))

        fdoc, hdoc, bdoc = test_helper.leap_mail()
        parts = {'alternatives': []}
        parts['alternatives'].append({'content': encoded_body, 'headers': {'Content-Transfer-Encoding': 'base64'}})
        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier, parts=parts)

        self.assertEquals(body, mail.text_plain_body)
Пример #36
0
    def test_parse_date_from_soledad_fallback_to_now_if_neither_date_nor_received_header(self):
        leap_mail_date_in_iso_format = "2014-09-03T13:11:15-03:00"

        when(pixelated.support.date).iso_now().thenReturn(leap_mail_date_in_iso_format)
        fdoc, hdoc, bdoc = test_helper.leap_mail()
        del hdoc.content['date']

        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format)
Пример #37
0
    def test_use_datetime_now_as_fallback_for_invalid_date(self):
        leap_mail_date = u'söme däte'
        date_expected = "2014-09-03T13:11:15-03:00"

        when(pixelated.support.date).iso_now().thenReturn(date_expected)
        leap_mail = test_helper.leap_mail(headers={'date': leap_mail_date})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), date_expected)
Пример #38
0
    def test_parse_date_from_soledad_fallback_to_received_header_if_date_header_isnt_available(self):
        leap_mail_date = "Wed, 03 Sep 2014 13:11:15 -0300"
        leap_mail_date_in_iso_format = "2014-09-03T13:11:15-03:00"
        leap_mail_received_header = "by bitmask.local from 127.0.0.1 with ESMTP ;\n " + leap_mail_date

        leap_mail = test_helper.leap_mail(headers={'received': leap_mail_received_header})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(str(mail.headers['Date']), leap_mail_date_in_iso_format)
Пример #39
0
    def test_parse_UTF8_headers_with_CharsetAscii(self):
        leap_mail_from = u'"söme ümläuds" <*****@*****.**>'
        leap_mail_to = u'"söme ümläuds" <*****@*****.**>,\n"söme ümläuds" <*****@*****.**>'

        leap_mail = test_helper.leap_mail(extra_headers={'From': leap_mail_from, 'Subject': "some subject", 'To': leap_mail_to})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        mail.headers['From'].encode('ascii')
        self.assertEqual(mail.headers['To'], ['"sme mluds" <*****@*****.**>', '"sme mluds" <*****@*****.**>'])
Пример #40
0
    def test_that_body_understands_8bit(self):
        body = u'testtext'
        encoded_body = body

        fdoc, hdoc, bdoc = test_helper.leap_mail()
        parts = {'alternatives': []}
        parts['alternatives'].append({'content': encoded_body, 'headers': {'Content-Transfer-Encoding': '8bit'}})
        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier, parts=parts)

        self.assertEquals(body, mail.text_plain_body)
Пример #41
0
    def test_fall_back_to_ascii_if_invalid_received_header(self):
        leap_mail_received_header = u"söme invalid received heäder\n"
        date_expected = "2014-09-03T13:11:15-03:00"

        when(pixelated.support.date).iso_now().thenReturn(date_expected)
        leap_mail = test_helper.leap_mail(headers={'received': leap_mail_received_header})

        mail = PixelatedMail.from_soledad(*leap_mail, soledad_querier=self.querier)

        self.assertEqual(mail.headers['Date'], date_expected)
Пример #42
0
    def test_ignore_transient_failures(self):
        """
        Persistent errors should start with 5.
        See: http://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes.xhtml
        """
        bounced_mail_hdoc = os.path.join(os.path.dirname(__file__), '..', 'fixtures', 'bounced_mail_hdoc.json')
        with open(bounced_mail_hdoc) as f:
            content = f.read()
            # Change status to 4.XXX.YYY (only the first number is relevant here)
            content = content.replace("5.1.1", "4.X.Y")
            hdoc = json.loads(content)

        temporary_bounced_leap_mail = test_helper.leap_mail()
        temporary_bounced_leap_mail[1].content = hdoc
        temporary_bounced_mail = PixelatedMail.from_soledad(*temporary_bounced_leap_mail, soledad_querier=self.querier)

        not_bounced_leap_mail = test_helper.leap_mail()
        not_bounced_mail = PixelatedMail.from_soledad(*not_bounced_leap_mail, soledad_querier=self.querier)

        self.assertFalse(temporary_bounced_mail.bounced)
        self.assertFalse(not_bounced_mail.bounced)
Пример #43
0
    def test_clean_line_breaks_on_address_headers(self):
        many_recipients = "One <*****@*****.**>,\nTwo <*****@*****.**>, Normal <*****@*****.**>,\[email protected]"
        headers = {"Cc": many_recipients, "Bcc": many_recipients, "To": many_recipients}
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=["\\Recent"], extra_headers=headers)

        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc)

        for header_label in ["To", "Cc", "Bcc"]:
            for address in mail.headers[header_label]:
                self.assertNotIn("\n", address)
                self.assertNotIn(",", address)
            self.assertEquals(4, len(mail.headers[header_label]))
Пример #44
0
    def test_ignore_transient_failures(self):
        """
        Persistent errors should start with 5.
        See: http://www.iana.org/assignments/smtp-enhanced-status-codes/smtp-enhanced-status-codes.xhtml
        """
        bounced_mail_hdoc = os.path.join(os.path.dirname(__file__), '..', 'fixtures', 'bounced_mail_hdoc.json')
        with open(bounced_mail_hdoc) as f:
            content = f.read()
            # Change status to 4.XXX.YYY (only the first number is relevant here)
            content = content.replace("5.1.1", "4.X.Y")
            hdoc = json.loads(content)

        temporary_bounced_leap_mail = test_helper.leap_mail()
        temporary_bounced_leap_mail[1].content = hdoc
        temporary_bounced_mail = PixelatedMail.from_soledad(*temporary_bounced_leap_mail, soledad_querier=self.querier)

        not_bounced_leap_mail = test_helper.leap_mail()
        not_bounced_mail = PixelatedMail.from_soledad(*not_bounced_leap_mail, soledad_querier=self.querier)

        self.assertFalse(temporary_bounced_mail.bounced)
        self.assertFalse(not_bounced_mail.bounced)
Пример #45
0
    def test_clean_line_breaks_on_address_headers(self):
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'])
        hdoc.content['headers']['To'] = 'One <*****@*****.**>,\nTwo <*****@*****.**>, Normal <*****@*****.**>,\[email protected]'
        hdoc.content['headers']['Bcc'] = hdoc.content['headers']['To']
        hdoc.content['headers']['Cc'] = hdoc.content['headers']['To']

        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier)

        for header_label in ['To', 'Cc', 'Bcc']:
            for address in mail.headers[header_label]:
                self.assertNotIn('\n', address)
                self.assertNotIn(',', address)
            self.assertEquals(4, len(mail.headers[header_label]))
Пример #46
0
    def test_as_dict(self):
        headers = {
            'Subject': 'The subject',
            'From': '*****@*****.**',
            'To': '*****@*****.**'
        }
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'],
                                                 extra_headers=headers)

        InputMail.FROM_EMAIL_ADDRESS = '*****@*****.**'

        mail = PixelatedMail.from_soledad(fdoc,
                                          hdoc,
                                          bdoc,
                                          soledad_querier=self.querier)

        _dict = mail.as_dict()

        self.maxDiff = None

        self.assertEquals(
            _dict, {
                'htmlBody': None,
                'textPlainBody': 'body',
                'header': {
                    'date': dateparser.parse(hdoc.content['date']).isoformat(),
                    'from': '*****@*****.**',
                    'subject': 'The subject',
                    'to': ['*****@*****.**'],
                    'cc': [],
                    'bcc': []
                },
                'ident': 'chash',
                'mailbox': 'inbox',
                'security_casing': {
                    'imprints': [{
                        'state': 'no_signature_information'
                    }],
                    'locks': []
                },
                'status': ['recent'],
                'tags': [],
                'attachments': [],
                'replying': {
                    'single': '*****@*****.**',
                    'all': {
                        'to-field': ['*****@*****.**'],
                        'cc-field': []
                    }
                }
            })
Пример #47
0
    def test_clean_line_breaks_on_address_headers(self):
        many_recipients = 'One <*****@*****.**>,\nTwo <*****@*****.**>, Normal <*****@*****.**>,\[email protected]'
        headers = {'Cc': many_recipients,
                   'Bcc': many_recipients,
                   'To': many_recipients}
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'],
                                                 extra_headers=headers)

        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier)

        for header_label in ['To', 'Cc', 'Bcc']:
            for address in mail.headers[header_label]:
                self.assertNotIn('\n', address)
                self.assertNotIn(',', address)
            self.assertEquals(4, len(mail.headers[header_label]))
Пример #48
0
    def test_clean_line_breaks_on_address_headers(self):
        many_recipients = 'One <*****@*****.**>,\nTwo <*****@*****.**>, Normal <*****@*****.**>,\[email protected]'
        headers = {'Cc': many_recipients,
                   'Bcc': many_recipients,
                   'To': many_recipients}
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'],
                                                 extra_headers=headers)

        mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier)

        for header_label in ['To', 'Cc', 'Bcc']:
            for address in mail.headers[header_label]:
                self.assertNotIn('\n', address)
                self.assertNotIn(',', address)
            self.assertEquals(4, len(mail.headers[header_label]))
    def test_send_mail_sends_to_To_Cc_and_Bcc(self):
        headers = {
            'To': ['*****@*****.**', '*****@*****.**'],
            'Cc': ['*****@*****.**', '*****@*****.**'],
            'Bcc': ['*****@*****.**', '*****@*****.**']
        }

        mail = PixelatedMail.from_soledad(*test_helper.leap_mail(extra_headers=headers))
        mail.to_smtp_format = lambda: "mail as smtp string"

        self.mail_sender.sendmail(mail)

        expected_recipients = ['*****@*****.**', '*****@*****.**', '*****@*****.**',
                               '*****@*****.**',
                               '*****@*****.**', '*****@*****.**']

        verify(self.smtp_client).sendmail(self.mail_address, expected_recipients, "mail as smtp string")
Пример #50
0
    def test_clean_line_breaks_on_address_headers(self):
        fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent'])
        hdoc.content['headers'][
            'To'] = 'One <*****@*****.**>,\nTwo <*****@*****.**>, Normal <*****@*****.**>,\[email protected]'
        hdoc.content['headers']['Bcc'] = hdoc.content['headers']['To']
        hdoc.content['headers']['Cc'] = hdoc.content['headers']['To']

        mail = PixelatedMail.from_soledad(fdoc,
                                          hdoc,
                                          bdoc,
                                          soledad_querier=self.querier)

        for header_label in ['To', 'Cc', 'Bcc']:
            for address in mail.headers[header_label]:
                self.assertNotIn('\n', address)
                self.assertNotIn(',', address)
            self.assertEquals(4, len(mail.headers[header_label]))
Пример #51
0
    def test_parse_UTF8_headers_with_CharsetAscii(self):
        leap_mail_from = u'"söme ümläuds" <*****@*****.**>'
        leap_mail_to = (
            u'"söme ümläuds" <*****@*****.**>,\n"söme ümläuds" <*****@*****.**>'
        )

        leap_mail = test_helper.leap_mail(
            extra_headers={"From": leap_mail_from, "Subject": "some subject", "To": leap_mail_to}
        )

        mail = PixelatedMail.from_soledad(*leap_mail)

        mail.headers["From"].encode("ascii")
        self.assertEqual(
            mail.headers["To"],
            ['"sme mluds" <*****@*****.**>', '"sme mluds" <*****@*****.**>'],
        )
Пример #52
0
    def test_headers_are_encoded_right(self):
        subject = "=?UTF-8?Q?test_encoding_St=C3=A4ch?="
        email_from = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="
        email_to = "=?utf-8?b?IsOEw7zDtiDDlsO8w6QiIDxmb2xrZXJAcGl4ZWxhdGVkLXByb2plY3Qub3Jn?=\n =?utf-8?b?PiwgRsO2bGtlciA8Zm9sa2VyQHBpeGVsYXRlZC1wcm9qZWN0Lm9yZz4=?="
        email_cc = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="
        email_bcc = "=?UTF-8?Q?St=C3=A4ch_<*****@*****.**>?="

        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 <*****@*****.**>')
        self.assertEqual(mail.headers['To'], ['"\xc3\x84\xc3\xbc\xc3\xb6 \xc3\x96\xc3\xbc\xc3\xa4" <*****@*****.**>', 'F\xc3\xb6lker <*****@*****.**>'])
        self.assertEqual(mail.headers['Cc'], ['St\xc3\xa4ch <*****@*****.**>'])
        self.assertEqual(mail.headers['Bcc'], ['St\xc3\xa4ch <*****@*****.**>'])

        mail.as_dict()