Example #1
0
    def test_store_attachment_twice_does_not_cause_exception(self):
        attachment_id = '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0'
        content = 'this is some attachment content'
        content_type = 'text/plain'
        cdoc_serialized = {
            'content_transfer_encoding': 'base64',
            'lkf': [],
            'content_disposition': 'attachment',
            'ctype': '',
            'raw': 'dGhpcyBpcyBzb21lIGF0dGFjaG1lbnQgY29udGVudA==',
            'phash':
            '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0',
            'content_type': 'text/plain',
            'type': 'cnt'
        }
        doc = SoledadDocument(json=json.dumps({
            'content_type': content_type,
            'raw': content
        }))
        when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt',
                                          attachment_id).thenReturn(
                                              defer.succeed([doc]))

        store = LeapAttachmentStore(self.soledad)

        when(self.soledad).create_doc(cdoc_serialized,
                                      doc_id=attachment_id).thenRaise(
                                          u1db.errors.RevisionConflict())

        actual_attachment_id = yield store.add_attachment(
            content, content_type)

        self.assertEqual(attachment_id, actual_attachment_id)
    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 = LeapAttachmentStore(self.soledad)

        attachment = yield store.get_mail_attachment(attachment_id)

        self.assertEqual({'content-type': 'foo/bar', 'content': bytearray('asdf')}, attachment)
 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 = LeapAttachmentStore(self.soledad)
     try:
         yield store.get_mail_attachment(attachment_id)
         self.fail('ValueError exception expected')
     except ValueError:
         pass
Example #4
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 = LeapAttachmentStore(self.soledad)
     try:
         yield store.get_mail_attachment(attachment_id)
         self.fail('ValueError exception expected')
     except ValueError:
         pass
    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 = LeapAttachmentStore(self.soledad)

            attachment = yield store.get_mail_attachment(attachment_id)

            self.assertEqual(bytearray(data), attachment['content'])
    def test_store_attachment(self):
        content = 'this is some attachment content'
        content_type = 'text/plain'
        cdoc_serialized = {'content_transfer_encoding': 'base64', 'lkf': [], 'content_disposition': 'attachment',
                           'ctype': '', 'raw': 'dGhpcyBpcyBzb21lIGF0dGFjaG1lbnQgY29udGVudA==',
                           'phash': '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0',
                           'content_type': 'text/plain', 'type': 'cnt'}

        store = LeapAttachmentStore(self.soledad)

        attachment_id = yield store.add_attachment(content, content_type)

        self.assertEqual('9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0', attachment_id)

        verify(self.soledad).create_doc(cdoc_serialized, doc_id=attachment_id)
Example #7
0
    def start(self):
        soledad_test_folder = os.path.join(self._leap_home, self._uuid)
        self.soledad = yield initialize_soledad(tempdir=soledad_test_folder,
                                                uuid=self._uuid)
        self.search_engine = SearchEngine(self.INDEX_KEY,
                                          user_home=soledad_test_folder)
        self.keymanager = mock()
        self.mail_sender = self._create_mail_sender()
        self.mail_store = SearchableMailStore(LeapMailStore(self.soledad),
                                              self.search_engine)
        self.attachment_store = LeapAttachmentStore(self.soledad)

        yield self._initialize_imap_account()

        self.draft_service = DraftService(self.mail_store)
        self.leap_session = mock()
        self.feedback_service = FeedbackService(self.leap_session)

        self.mail_service = self._create_mail_service(self.mail_sender,
                                                      self.mail_store,
                                                      self.search_engine,
                                                      self.attachment_store)

        mails = yield self.mail_service.all_mails()
        if len(mails) > 0:
            raise Exception('What? Where did these come from?')
        self.search_engine.index_mails(mails)
    def test_store_attachment_twice_does_not_cause_exception(self):
        attachment_id = '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0'
        content = 'this is some attachment content'
        content_type = 'text/plain'
        cdoc_serialized = {'content_transfer_encoding': 'base64', 'lkf': [], 'content_disposition': 'attachment',
                           'ctype': '', 'raw': 'dGhpcyBpcyBzb21lIGF0dGFjaG1lbnQgY29udGVudA==',
                           'phash': '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0',
                           'content_type': 'text/plain', 'type': 'cnt'}
        doc = SoledadDocument(json=json.dumps({'content_type': content_type, 'raw': content}))
        when(self.soledad).get_from_index('by-type-and-payloadhash', 'cnt', attachment_id).thenReturn(defer.succeed([doc]))

        store = LeapAttachmentStore(self.soledad)

        when(self.soledad).create_doc(cdoc_serialized, doc_id=attachment_id).thenRaise(u1db.errors.RevisionConflict())

        actual_attachment_id = yield store.add_attachment(content, content_type)

        self.assertEqual(attachment_id, actual_attachment_id)
Example #9
0
    def _setup_mail_service(self, search_engine):
        pixelated_mail_sender = MailSender(
            self._leap_session.smtp_config,
            self._leap_session.keymanager.keymanager)

        return MailService(pixelated_mail_sender,
                           self._leap_session.mail_store, search_engine,
                           self._leap_session.account_email(),
                           LeapAttachmentStore(self._leap_session.soledad))
Example #10
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 = LeapAttachmentStore(self.soledad)

        attachment = yield store.get_mail_attachment(attachment_id)

        self.assertEqual(
            {
                'content-type': 'foo/bar',
                'content': bytearray('asdf')
            }, attachment)
Example #11
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 = LeapAttachmentStore(self.soledad)

            attachment = yield store.get_mail_attachment(attachment_id)

            self.assertEqual(bytearray(data), attachment['content'])
Example #12
0
    def test_store_attachment(self):
        content = 'this is some attachment content'
        content_type = 'text/plain'
        cdoc_serialized = {
            'content_transfer_encoding': 'base64',
            'lkf': [],
            'content_disposition': 'attachment',
            'ctype': '',
            'raw': 'dGhpcyBpcyBzb21lIGF0dGFjaG1lbnQgY29udGVudA==',
            'phash':
            '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0',
            'content_type': 'text/plain',
            'type': 'cnt'
        }

        store = LeapAttachmentStore(self.soledad)

        attachment_id = yield store.add_attachment(content, content_type)

        self.assertEqual(
            '9863729729D2E2EE8E52F0A7115CE33AD18DDA4B58E49AE08DD092D1C8E699B0',
            attachment_id)

        verify(self.soledad).create_doc(cdoc_serialized, doc_id=attachment_id)