예제 #1
0
    def test_get_mail_not_exist(self):
        when(self.soledad).get_doc(ANY()).thenAnswer(lambda: defer.succeed(None))
        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(_format_mdoc_id(uuid4(), 1))

        self.assertIsNone(mail)
    def test_get_mailbox_names(self):
        self._mock_get_mailbox('OTHER', create_new_uuid=True)
        store = LeapMailStore(self.soledad)

        names = yield store.get_mailbox_names()

        self.assertEqual({'INBOX', 'OTHER'}, names)
예제 #3
0
    def test_get_mailbox_names(self):
        self._mock_get_mailbox('OTHER', create_new_uuid=True)
        store = LeapMailStore(self.soledad)

        names = yield store.get_mailbox_names()

        self.assertEqual({'INBOX', 'OTHER'}, names)
    def test_get_mails_fails_for_invalid_mail_id(self):
        store = LeapMailStore(self.soledad)

        try:
            yield store.get_mails(['invalid'])
            self.fail('Exception expected')
        except Exception, e:
            pass
    def test_get_mail_not_exist(self):
        with patch('mockito.invocation.AnswerSelector', AnswerSelector):
            when(self.soledad).get_doc(ANY()).thenAnswer(lambda: defer.succeed(None))
        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(_format_mdoc_id(uuid4(), 1))

        self.assertIsNone(mail)
예제 #6
0
    def test_delete_mailbox(self):
        _, mbox_soledad_doc = self._mock_get_mailbox('INBOX')
        store = LeapMailStore(self.soledad)
        when(self.soledad).delete_doc(mbox_soledad_doc).thenReturn(defer.succeed(None))

        yield store.delete_mailbox('INBOX')

        verify(self.soledad).delete_doc(self.doc_by_id[mbox_soledad_doc.doc_id])
예제 #7
0
    def test_delete_mail(self):
        mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')

        store = LeapMailStore(self.soledad)

        yield store.delete_mail(mdoc_id)

        self._assert_mail_got_deleted(fdoc_id, mdoc_id)
    def test_delete_mail(self):
        mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')

        store = LeapMailStore(self.soledad)

        yield store.delete_mail(mdoc_id)

        self._assert_mail_got_deleted(fdoc_id, mdoc_id)
    def test_delete_mailbox(self):
        _, mbox_soledad_doc = self._mock_get_mailbox('INBOX')
        store = LeapMailStore(self.soledad)
        when(self.soledad).delete_doc(mbox_soledad_doc).thenReturn(defer.succeed(None))

        yield store.delete_mailbox('INBOX')

        verify(self.soledad).delete_doc(self.doc_by_id[mbox_soledad_doc.doc_id])
예제 #10
0
    def test_get_mails_fails_for_invalid_mail_id(self):
        store = LeapMailStore(self.soledad)

        try:
            yield store.get_mails(['invalid'])
            self.fail('Exception expected')
        except FirstError:
            pass
예제 #11
0
    def test_copy_mail_to_mailbox(self):
        expected_message = self._add_create_mail_mocks_to_soledad_from_fixture_file('mbox00000000')
        mail_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        self._mock_get_mailbox('TRASH')
        store = LeapMailStore(self.soledad)

        mail = yield store.copy_mail_to_mailbox(mail_id, 'TRASH')

        self._assert_message_docs_created(expected_message, mail, only_mdoc_and_fdoc=True)
    def test_get_mail_with_body(self):
        expeted_body = 'Dignissimos ducimus veritatis. Est tenetur consequatur quia occaecati. Vel sit sit voluptas.\n\nEarum distinctio eos. Accusantium qui sint ut quia assumenda. Facere dignissimos inventore autem sit amet. Pariatur voluptatem sint est.\n\nUt recusandae praesentium aspernatur. Exercitationem amet placeat deserunt quae consequatur eum. Unde doloremque suscipit quia.\n\n'
        mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')

        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(mdoc_id, include_body=True)

        self.assertEqual(expeted_body, mail.body)
 def test_get_mail_attachment_throws_exception_if_attachment_does_not_exist(self):
     attachment_id = '1B0A9AAD9E153D24265395203C53884506ABA276394B9FEC02B214BF9E77E48E'
     when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt', attachment_id).thenReturn(defer.succeed([]))
     store = LeapMailStore(self.soledad)
     try:
         yield store.get_mail_attachment(attachment_id)
         self.fail('ValueError exception expected')
     except ValueError:
         pass
    def test_copy_mail_to_mailbox(self):
        expected_message = self._add_create_mail_mocks_to_soledad_from_fixture_file('mbox00000000')
        mail_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        self._mock_get_mailbox('TRASH')
        store = LeapMailStore(self.soledad)

        mail = yield store.copy_mail_to_mailbox(mail_id, 'TRASH')

        self._assert_message_docs_created(expected_message, mail, only_mdoc_and_fdoc=True)
예제 #15
0
    def test_get_mail_from_mailbox(self):
        other, _ = self._mock_get_mailbox('OTHER', create_new_uuid=True)
        mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000', other.uuid)

        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(mdoc_id)

        self.assertEqual('OTHER', mail.mailbox_name)
예제 #16
0
    def test_get_mail_with_body(self):
        expeted_body = 'Dignissimos ducimus veritatis. Est tenetur consequatur quia occaecati. Vel sit sit voluptas.\n\nEarum distinctio eos. Accusantium qui sint ut quia assumenda. Facere dignissimos inventore autem sit amet. Pariatur voluptatem sint est.\n\nUt recusandae praesentium aspernatur. Exercitationem amet placeat deserunt quae consequatur eum. Unde doloremque suscipit quia.\n\n'
        mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')

        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(mdoc_id, include_body=True)

        self.assertEqual(expeted_body, mail.body)
    def test_get_mail_from_mailbox(self):
        other, _ = self._mock_get_mailbox('OTHER', create_new_uuid=True)
        mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000', other.uuid)

        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(mdoc_id)

        self.assertEqual('OTHER', mail.mailbox_name)
예제 #18
0
    def test_all_mail_graceful_error_handling(self):
        mail_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        when(self.soledad).get_from_index('by-type', 'meta').thenReturn(defer.succeed([self.doc_by_id[mail_id]]))
        when(self.soledad).get_doc(self.doc_by_id[mail_id].content['cdocs'][0]).thenAnswer(lambda: defer.fail(Exception('fail loading attachment')))
        store = LeapMailStore(self.soledad)

        mails = yield store.all_mails(gracefully_ignore_errors=True)

        self.assertEqual(0, len(mails))
    def test_get_mail_attachment(self):
        attachment_id = 'AAAA9AAD9E153D24265395203C53884506ABA276394B9FEC02B214BF9E77E48E'
        doc = SoledadDocument(json=json.dumps({'content_type': 'foo/bar', 'raw': 'asdf'}))
        when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt', attachment_id).thenReturn(defer.succeed([doc]))
        store = LeapMailStore(self.soledad)

        attachment = yield store.get_mail_attachment(attachment_id)

        self.assertEqual({'content-type': 'foo/bar', 'content': bytearray('asdf')}, attachment)
예제 #20
0
    def test_get_mailbox_mail_ids(self):
        mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        when(self.soledad).get_from_index('by-type-and-mbox-uuid', 'flags', underscore_uuid(self.mbox_uuid)).thenReturn(defer.succeed([self.doc_by_id[fdoc_id]]))
        self._mock_get_mailbox('INBOX')
        store = LeapMailStore(self.soledad)

        mail_ids = yield store.get_mailbox_mail_ids('INBOX')

        self.assertEqual(1, len(mail_ids))
        self.assertEqual(mdoc_id, mail_ids[0])
    def test_add_mail_with_special_chars(self):
        input_mail = MIMEText(u'a utf8 message', _charset='utf-8')
        input_mail['From'] = Header(u'"Älbert Übrö" <äüö@example.mail>', 'iso-8859-1')
        input_mail['Subject'] = Header(u'Hällö Wörld', 'iso-8859-1')
        self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)

        message = yield store.add_mail('INBOX', input_mail.as_string())

        self.assertEqual(u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\[email protected]>', message.as_dict()['header']['from'])
    def test_get_mailbox_mail_ids(self):
        mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        when(self.soledad).get_from_index('by-type-and-mbox-uuid', 'flags', underscore_uuid(self.mbox_uuid)).thenReturn(defer.succeed([self.doc_by_id[fdoc_id]]))
        self._mock_get_mailbox('INBOX')
        store = LeapMailStore(self.soledad)

        mail_ids = yield store.get_mailbox_mail_ids('INBOX')

        self.assertEqual(1, len(mail_ids))
        self.assertEqual(mdoc_id, mail_ids[0])
예제 #23
0
    def test_add_mail_with_special_chars(self):
        input_mail = MIMEText(u'a utf8 message', _charset='utf-8')
        input_mail['From'] = Header(u'"Älbert Übrö" <äüö@example.mail>', 'iso-8859-1')
        input_mail['Subject'] = Header(u'Hällö Wörld', 'iso-8859-1')
        self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)

        message = yield store.add_mail('INBOX', input_mail.as_string())

        self.assertEqual(u'"\xc4lbert \xdcbr\xf6" <\xe4\xfc\[email protected]>', message.as_dict()['header']['from'])
예제 #24
0
    def test_handles_unmapped_mailbox_uuid(self):
        # given
        store = LeapMailStore(self.soledad)
        new_uuid = 'UNICORN'

        # if no mailbox doc is created yet (async hell?)
        when(self.soledad).get_from_index('by-type', 'mbox').thenReturn(defer.succeed([]))

        # then it should point to empty, which is all mails
        name = yield store._mailbox_name_from_uuid(new_uuid)
        self.assertEquals('', name)
    def test_get_mails(self):
        first_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        second_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000001')

        store = LeapMailStore(self.soledad)

        mails = yield store.get_mails([first_mdoc_id, second_mdoc_id])

        self.assertEqual(2, len(mails))
        self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mails[0].subject)
        self.assertEqual('Error illum dignissimos autem eos aspernatur.', mails[1].subject)
예제 #26
0
    def test_add_mail(self):
        expected_message = self._add_create_mail_mocks_to_soledad_from_fixture_file('mbox00000000')
        mail = self._load_mail_from_file('mbox00000000')
        self._mock_get_mailbox('INBOX')

        store = LeapMailStore(self.soledad)

        message = yield store.add_mail('INBOX', mail.as_string())

        self.assertIsInstance(message, LeapMail)
        self._assert_message_docs_created(expected_message, message)
예제 #27
0
    def test_get_mails(self):
        first_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        second_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000001')

        store = LeapMailStore(self.soledad)

        mails = yield store.get_mails([first_mdoc_id, second_mdoc_id])

        self.assertEqual(2, len(mails))
        self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mails[0].subject)
        self.assertEqual('Error illum dignissimos autem eos aspernatur.', mails[1].subject)
    def test_handles_unmapped_mailbox_uuid(self):
        # given
        store = LeapMailStore(self.soledad)
        new_uuid = 'UNICORN'

        # if no mailbox doc is created yet (async hell?)
        when(self.soledad).get_from_index('by-type', 'mbox').thenReturn(defer.succeed([]))

        # then it should point to empty, which is all mails
        name = yield store._mailbox_name_from_uuid(new_uuid)
        self.assertEquals('', name)
    def test_add_mail(self):
        expected_message = self._add_create_mail_mocks_to_soledad_from_fixture_file('mbox00000000')
        mail = self._load_mail_from_file('mbox00000000')
        self._mock_get_mailbox('INBOX')

        store = LeapMailStore(self.soledad)

        message = yield store.add_mail('INBOX', mail.as_string())

        self.assertIsInstance(message, LeapMail)
        self._assert_message_docs_created(expected_message, message)
예제 #30
0
    def test_get_two_different_mails(self):
        first_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        second_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000001')

        store = LeapMailStore(self.soledad)

        mail1 = yield store.get_mail(first_mdoc_id)
        mail2 = yield store.get_mail(second_mdoc_id)

        self.assertNotEqual(mail1, mail2)
        self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mail1.subject)
        self.assertEqual('Error illum dignissimos autem eos aspernatur.', mail2.subject)
    def test_get_two_different_mails(self):
        first_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        second_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000001')

        store = LeapMailStore(self.soledad)

        mail1 = yield store.get_mail(first_mdoc_id)
        mail2 = yield store.get_mail(second_mdoc_id)

        self.assertNotEqual(mail1, mail2)
        self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mail1.subject)
        self.assertEqual('Error illum dignissimos autem eos aspernatur.', mail2.subject)
예제 #32
0
 def test_get_mail_attachment_throws_exception_if_attachment_does_not_exist(
         self):
     attachment_id = '1B0A9AAD9E153D24265395203C53884506ABA276394B9FEC02B214BF9E77E48E'
     when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt',
                                       attachment_id).thenReturn(
                                           defer.succeed([]))
     store = LeapMailStore(self.soledad)
     try:
         yield store.get_mail_attachment(attachment_id)
         self.fail('ValueError exception expected')
     except ValueError:
         pass
예제 #33
0
    def test_add_mail_with_inline_attachment(self):
        input_mail = MIMEMultipart()
        input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))
        attachment = MIMEApplication('pretend to be an inline attachment')
        attachment.add_header('Content-Disposition', 'u\'inline;\n\tfilename=super_nice_photo.jpg')
        input_mail.attach(attachment)
        mocked_message = self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)

        message = yield store.add_mail('INBOX', input_mail.as_string())

        expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'super_nice_photo.jpg', 'encoding': 'base64', 'size': 202, 'content-type': 'application/octet-stream'}]
        self.assertEqual(expected, message.as_dict()['attachments'])
    def test_get_mail(self):
        mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')

        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(mdoc_id)

        self.assertIsInstance(mail, LeapMail)
        self.assertEqual('*****@*****.**', mail.from_sender)
        self.assertEqual(['*****@*****.**'], mail.to)
        self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mail.subject)
        self.assertIsNone(mail.body)
        self.assertEqual('INBOX', mail.mailbox_name)
    def test_add_mail_with_attachment(self):
        input_mail = MIMEMultipart()
        input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))
        attachment = MIMEApplication('pretend to be binary attachment data')
        attachment.add_header('Content-Disposition', 'attachment', filename='filename.txt')
        input_mail.attach(attachment)
        mocked_message = self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)

        message = yield store.add_mail('INBOX', input_mail.as_string())

        expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64'}]
        self.assertEqual(expected, message.as_dict()['attachments'])
예제 #36
0
    def test_all_mails(self):
        first_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        second_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000001')
        when(self.soledad).get_from_index('by-type', 'meta').thenReturn(defer.succeed([self.doc_by_id[first_mdoc_id], self.doc_by_id[second_mdoc_id]]))

        store = LeapMailStore(self.soledad)

        mails = yield store.all_mails()

        self.assertIsNotNone(mails)
        self.assertEqual(2, len(mails))
        self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mails[0].subject)
        self.assertEqual('Error illum dignissimos autem eos aspernatur.', mails[1].subject)
    def test_add_mail_with_inline_attachment(self):
        input_mail = MIMEMultipart()
        input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))
        attachment = MIMEApplication('pretend to be an inline attachment')
        attachment.add_header('Content-Disposition', 'u\'inline;\n\tfilename=super_nice_photo.jpg')
        input_mail.attach(attachment)
        mocked_message = self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)

        message = yield store.add_mail('INBOX', input_mail.as_string())

        expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'super_nice_photo.jpg', 'encoding': 'base64', 'size': 48, 'content-type': 'application/octet-stream'}]
        self.assertEqual(expected, message.as_dict()['attachments'])
예제 #38
0
    def test_get_mail(self):
        mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')

        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(mdoc_id)

        self.assertIsInstance(mail, LeapMail)
        self.assertEqual('*****@*****.**', mail.from_sender)
        self.assertEqual(['*****@*****.**'], mail.to)
        self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mail.subject)
        self.assertIsNone(mail.body)
        self.assertEqual('INBOX', mail.mailbox_name)
    def test_all_mails(self):
        first_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        second_mdoc_id, _ = self._add_mail_fixture_to_soledad_from_file('mbox00000001')
        when(self.soledad).get_from_index('by-type', 'meta').thenReturn(defer.succeed([self.doc_by_id[first_mdoc_id], self.doc_by_id[second_mdoc_id]]))

        store = LeapMailStore(self.soledad)

        mails = yield store.all_mails()

        self.assertIsNotNone(mails)
        self.assertEqual(2, len(mails))
        self.assertEqual('Itaque consequatur repellendus provident sunt quia.', mails[0].subject)
        self.assertEqual('Error illum dignissimos autem eos aspernatur.', mails[1].subject)
예제 #40
0
    def test_add_mailbox(self):
        when(self.soledad).list_indexes().thenReturn(defer.succeed(MAIL_INDEXES)).thenReturn(defer.succeed(MAIL_INDEXES))
        when(self.soledad).get_from_index('by-type-and-mbox', 'mbox', 'TEST').thenReturn(defer.succeed([]))
        self._mock_create_soledad_doc(self.mbox_uuid, MailboxWrapper(mbox='TEST'))
        when(self.soledad).get_doc(self.mbox_uuid).thenAnswer(lambda: defer.succeed(self.doc_by_id[self.mbox_uuid]))
        when(self.soledad).put_doc(ANY()).thenAnswer(lambda: defer.succeed(None))
        store = LeapMailStore(self.soledad)

        mbox = yield store.add_mailbox('TEST')

        self.assertIsNotNone(mbox)
        self.assertEqual(self.mbox_uuid, mbox.doc_id)
        self.assertEqual('TEST', mbox.mbox)
        self.assertIsNotNone(mbox.uuid)
예제 #41
0
    def test_add_mail_with_nested_attachments(self):
        input_mail = MIMEMultipart()
        input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))
        attachment = MIMEApplication('pretend to be binary attachment data')
        attachment.add_header('Content-Disposition', 'attachment', filename='filename.txt')
        nested_attachment = MIMEMultipart()
        nested_attachment.attach(attachment)
        input_mail.attach(nested_attachment)
        mocked_message = self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)

        message = yield store.add_mail('INBOX', input_mail.as_string())

        expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64', 'size': 197, 'content-type': 'application/octet-stream'}]
        self.assertEqual(expected, message.as_dict()['attachments'])
    def test_update_mail(self):
        mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        soledad_fdoc = self.doc_by_id[fdoc_id]
        when(self.soledad).put_doc(soledad_fdoc).thenReturn(defer.succeed(None))

        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(mdoc_id)

        mail.tags.add('new_tag')

        yield store.update_mail(mail)

        verify(self.soledad).put_doc(soledad_fdoc)
        self.assertTrue('new_tag' in soledad_fdoc.content['tags'])
    def test_get_mail_attachment_different_content_encodings(self):
        attachment_id = '1B0A9AAD9E153D24265395203C53884506ABA276394B9FEC02B214BF9E77E48E'
        encoding_examples = [('', 'asdf', 'asdf'),
                             ('base64', 'asdf', 'YXNkZg=='),
                             ('quoted-printable', 'äsdf', '=C3=A4sdf')]

        for transfer_encoding, data, encoded_data in encoding_examples:
            doc = SoledadDocument(json=json.dumps({'content_type': 'foo/bar', 'raw': encoded_data,
                                                   'content_transfer_encoding': transfer_encoding}))
            when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt', attachment_id).thenReturn(defer.succeed([doc]))
            store = LeapMailStore(self.soledad)

            attachment = yield store.get_mail_attachment(attachment_id)

            self.assertEqual(bytearray(data), attachment['content'])
예제 #44
0
    def test_update_mail(self):
        mdoc_id, fdoc_id = self._add_mail_fixture_to_soledad_from_file('mbox00000000')
        soledad_fdoc = self.doc_by_id[fdoc_id]
        when(self.soledad).put_doc(soledad_fdoc).thenReturn(defer.succeed(None))

        store = LeapMailStore(self.soledad)

        mail = yield store.get_mail(mdoc_id)

        mail.tags.add('new_tag')

        yield store.update_mail(mail)

        verify(self.soledad).put_doc(soledad_fdoc)
        self.assertTrue('new_tag' in soledad_fdoc.content['tags'])
예제 #45
0
    def test_extract_attachment_filename_with_or_without_quotes(self):
        input_mail = MIMEMultipart()
        input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))

        attachment_without_quotes = MIMEApplication('pretend to be an attachment from apple mail')
        attachment_without_quotes.add_header('Content-Disposition', 'u\'attachment;\n\tfilename=batatinha.rtf')
        input_mail.attach(attachment_without_quotes)

        attachment_with_quotes = MIMEApplication('pretend to be an attachment from thunderbird')
        attachment_with_quotes.add_header('Content-Disposition', 'u\'attachment; filename="receipt.pdf"')
        input_mail.attach(attachment_with_quotes)

        message = self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)
        attachment_info = store._extract_attachment_info_from(message)

        self.assertEqual('batatinha.rtf', attachment_info[0].name)
        self.assertEqual('receipt.pdf', attachment_info[1].name)
예제 #46
0
    def test_get_mail_attachment(self):
        attachment_id = 'AAAA9AAD9E153D24265395203C53884506ABA276394B9FEC02B214BF9E77E48E'
        doc = SoledadDocument(json=json.dumps({
            'content_type': 'foo/bar',
            'raw': 'asdf'
        }))
        when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt',
                                          attachment_id).thenReturn(
                                              defer.succeed([doc]))
        store = LeapMailStore(self.soledad)

        attachment = yield store.get_mail_attachment(attachment_id)

        self.assertEqual(
            {
                'content-type': 'foo/bar',
                'content': bytearray('asdf')
            }, attachment)
    def test_extract_attachment_filename_with_or_without_quotes(self):
        input_mail = MIMEMultipart()
        input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))

        attachment_without_quotes = MIMEApplication('pretend to be an attachment from apple mail')
        attachment_without_quotes.add_header('Content-Disposition', 'u\'attachment;\n\tfilename=batatinha.rtf')
        input_mail.attach(attachment_without_quotes)

        attachment_with_quotes = MIMEApplication('pretend to be an attachment from thunderbird')
        attachment_with_quotes.add_header('Content-Disposition', 'u\'attachment; filename="receipt.pdf"')
        input_mail.attach(attachment_with_quotes)

        message = self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)
        attachment_info = store._extract_attachment_info_from(message)

        self.assertEqual('batatinha.rtf', attachment_info[0].name)
        self.assertEqual('receipt.pdf', attachment_info[1].name)
    def test_extract_attachment_filename_from_other_headers(self):
        input_mail = MIMEMultipart()
        input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))

        attachment_without_description = MIMEApplication('pretend to be an attachment from apple mail', _subtype='pgp-keys')
        attachment_without_description.add_header('Content-Disposition', 'attachment')
        attachment_without_description.add_header('Content-Description', 'Some GPG Key')

        input_mail.attach(attachment_without_description)

        attachment_with_name_in_content_type = MIMEApplication('pretend to be an attachment from thunderbird', _subtype='pgp-signature; name="signature.asc"')
        attachment_with_name_in_content_type.add_header('Content-Disposition', 'inline')
        input_mail.attach(attachment_with_name_in_content_type)

        message = self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)
        attachment_info = store._extract_attachment_info_from(message)

        self.assertEqual('Some GPG Key', attachment_info[0].name)
        self.assertEqual('signature.asc', attachment_info[1].name)
예제 #49
0
    def test_extract_attachment_filename_from_other_headers(self):
        input_mail = MIMEMultipart()
        input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))

        attachment_without_description = MIMEApplication('pretend to be an attachment from apple mail', _subtype='pgp-keys')
        attachment_without_description.add_header('Content-Disposition', 'attachment')
        attachment_without_description.add_header('Content-Description', 'Some GPG Key')

        input_mail.attach(attachment_without_description)

        attachment_with_name_in_content_type = MIMEApplication('pretend to be an attachment from thunderbird', _subtype='pgp-signature; name="signature.asc"')
        attachment_with_name_in_content_type.add_header('Content-Disposition', 'inline')
        input_mail.attach(attachment_with_name_in_content_type)

        message = self._add_create_mail_mocks_to_soledad(input_mail)
        store = LeapMailStore(self.soledad)
        attachment_info = store._extract_attachment_info_from(message)

        self.assertEqual('Some GPG Key', attachment_info[0].name)
        self.assertEqual('signature.asc', attachment_info[1].name)
예제 #50
0
    def test_get_mail_attachment_different_content_encodings(self):
        attachment_id = '1B0A9AAD9E153D24265395203C53884506ABA276394B9FEC02B214BF9E77E48E'
        encoding_examples = [('', 'asdf', 'asdf'),
                             ('base64', 'asdf', 'YXNkZg=='),
                             ('quoted-printable', 'äsdf', '=C3=A4sdf')]

        for transfer_encoding, data, encoded_data in encoding_examples:
            doc = SoledadDocument(
                json=json.dumps({
                    'content_type': 'foo/bar',
                    'raw': encoded_data,
                    'content_transfer_encoding': transfer_encoding
                }))
            when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt',
                                              attachment_id).thenReturn(
                                                  defer.succeed([doc]))
            store = LeapMailStore(self.soledad)

            attachment = yield store.get_mail_attachment(attachment_id)

            self.assertEqual(bytearray(data), attachment['content'])
예제 #51
0
    def test_get_mailbox_names_always_contains_inbox(self):
        store = LeapMailStore(self.soledad)

        names = yield store.get_mailbox_names()

        self.assertEqual({'INBOX'}, names)
    def test_get_mailbox_names_always_contains_inbox(self):
        store = LeapMailStore(self.soledad)

        names = yield store.get_mailbox_names()

        self.assertEqual({'INBOX'}, names)