def test_attachment_quoted_printable(self):
        soledad = mock()
        bdoc = mock()
        bdoc.content = {'raw': quopri.encodestring('esse papo seu ta qualquer coisa'), 'content-type': 'text/plain'}
        when(soledad).get_from_index('by-type-and-payloadhash', 'cnt', any(unicode)).thenReturn([bdoc])
        querier = SoledadQuerier(soledad)

        attachment = querier.attachment(u'0400BEBACAFE', 'quoted-printable')

        self.assertEquals('esse papo seu ta qualquer coisa', attachment['content'])
Ejemplo n.º 2
0
    def test_attachment_base64(self):
        soledad = mock()
        bdoc = mock()
        bdoc.content = {'raw': base64.encodestring('esse papo seu ta qualquer coisa'), 'content-type': 'text/plain'}
        when(soledad).get_from_index('by-type-and-payloadhash', 'cnt', any(unicode)).thenReturn([bdoc])
        querier = SoledadQuerier(soledad)

        attachment = yield querier.attachment(u'0400BEBACAFE', 'base64')

        self.assertEquals('esse papo seu ta qualquer coisa', attachment['content'])
    def test_extract_part_without_headers(self):
        soledad = mock()
        bdoc = mock()
        bdoc.content = {'raw': 'esse papo seu ta qualquer coisa'}
        when(soledad).get_from_index('by-type-and-payloadhash', 'cnt', any(unicode)).thenReturn([bdoc])
        hdoc = {'multi': True, 'part_map': {'1': {'multi': False, 'phash': u'0400BEBACAFE'}}}
        querier = SoledadQuerier(soledad)

        parts = querier._extract_parts(hdoc)

        self.assertEquals(bdoc.content['raw'], parts['alternatives'][0]['content'])
Ejemplo n.º 4
0
    def test_extract_part_without_headers(self):
        soledad = mock()
        bdoc = mock()
        bdoc.content = {'raw': 'esse papo seu ta qualquer coisa'}
        when(soledad).get_from_index('by-type-and-payloadhash', 'cnt', any(unicode)).thenReturn([bdoc])
        hdoc = {'multi': True, 'part_map': {'1': {'multi': False, 'phash': u'0400BEBACAFE'}}}
        querier = SoledadQuerier(soledad)

        parts = yield querier._extract_parts(hdoc)

        self.assertEquals(bdoc.content['raw'], parts['alternatives'][0]['content'])
Ejemplo n.º 5
0
    def test_extract_handles_missing_part_map(self):
        soledad = mock()
        hdoc = {u'multi': True,
                u'ctype': u'message/delivery-status',
                u'headers': [[u'Content-Description', u'Delivery report'], [u'Content-Type', u'message/delivery-status']],
                u'parts': 2,
                u'phash': None,
                u'size': 554}
        querier = SoledadQuerier(soledad)

        parts = yield querier._extract_parts(hdoc)

        self.assertEquals(0, len(parts['alternatives']))
        self.assertEquals(0, len(parts['attachments']))
    def test_extract_handles_missing_part_map(self):
        soledad = mock()
        hdoc = {u'multi': True,
                u'ctype': u'message/delivery-status',
                u'headers': [[u'Content-Description', u'Delivery report'], [u'Content-Type', u'message/delivery-status']],
                u'parts': 2,
                u'phash': None,
                u'size': 554}
        querier = SoledadQuerier(soledad)

        parts = querier._extract_parts(hdoc)

        self.assertEquals(0, len(parts['alternatives']))
        self.assertEquals(0, len(parts['attachments']))
Ejemplo n.º 7
0
    def test_get_lastuid(self):
        soledad = mock()
        mbox = mock()
        indexer = mock()
        mbox.content = {'uuid': str(uuid4())}
        when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn(defer.succeed([mbox]))
        querier = SoledadQuerier(soledad)

        when(pixelated.adapter.soledad.soledad_facade_mixin).MailboxIndexer(soledad).thenReturn(indexer)
        when(indexer).create_table(any()).thenReturn(defer.succeed(None))
        when(indexer).get_last_uid(any()).thenReturn(defer.succeed(42))

        last_uid = (yield querier.get_lastuid('INBOX'))

        self.assertEquals(42, last_uid)
Ejemplo n.º 8
0
    def setup(self, leap_home, leap_session):

        soledad_querier = SoledadQuerier(soledad=leap_session.soledad_session.soledad)

        yield self.setup_search_engine(
            leap_home,
            soledad_querier)

        self.wrap_mail_store_with_indexing_mail_store(leap_session)

        pixelated_mailboxes = Mailboxes(
            leap_session.account,
            leap_session.soledad_session.soledad,
            soledad_querier,
            self.search_engine)
        yield pixelated_mailboxes.index_mailboxes()

        self.mail_service = yield self.setup_mail_service(
            leap_session,
            soledad_querier,
            self.search_engine,
            pixelated_mailboxes)

        self.keymanager = leap_session.nicknym
        self.draft_service = self.setup_draft_service(leap_session.mail_store)

        yield self.post_setup(soledad_querier, leap_session)
    def __init__(self, soledad_test_folder='/tmp/soledad-test/test'):

        self.soledad = initialize_soledad(tempdir=soledad_test_folder)
        self.mail_address = "*****@*****.**"

        # setup app
        PixelatedMail.from_email_address = self.mail_address

        SearchEngine.DEFAULT_INDEX_HOME = soledad_test_folder

        self.app = App()

        self.soledad_querier = SoledadQuerier(self.soledad)
        self.soledad_querier.get_index_masterkey = lambda: self.INDEX_KEY

        self.account = SoledadBackedAccount('test', self.soledad, MagicMock())
        self.mailboxes = Mailboxes(self.account, self.soledad_querier)
        self.mail_sender = Mock()
        self.tag_service = TagService()
        self.draft_service = DraftService(self.mailboxes)
        self.mail_service = MailService(self.mailboxes, self.mail_sender,
                                        self.tag_service, self.soledad_querier)
        self.search_engine = SearchEngine(self.soledad_querier)
        self.search_engine.index_mails(self.mail_service.all_mails())

        self.app.resource = RootResource()

        self.app.resource.initialize(self.soledad_querier, self.search_engine,
                                     self.mail_service, self.draft_service)
Ejemplo n.º 10
0
def init_app(app, leap_home, leap_session):
    leap_session.start_background_jobs()
    keymanager = leap_session.nicknym.keymanager

    soledad_querier = SoledadQuerier(soledad=leap_session.account._soledad)

    search_engine = SearchEngine(soledad_querier, agent_home=leap_home)
    pixelated_mail_sender = MailSender(
        leap_session.account_email(),
        lambda: leap_session.smtp.ensure_running())

    pixelated_mailboxes = Mailboxes(leap_session.account, soledad_querier,
                                    search_engine)
    draft_service = DraftService(pixelated_mailboxes)
    mail_service = MailService(pixelated_mailboxes, pixelated_mail_sender,
                               soledad_querier, search_engine)

    MailboxIndexerListener.SEARCH_ENGINE = search_engine
    InputMail.FROM_EMAIL_ADDRESS = leap_session.account_email()

    app.resource.initialize(soledad_querier, keymanager, search_engine,
                            mail_service, draft_service)

    register(signal=proto.SOLEDAD_DONE_DATA_SYNC,
             callback=init_index_and_remove_dupes(querier=soledad_querier,
                                                  search_engine=search_engine,
                                                  mail_service=mail_service))

    register(signal=proto.SOLEDAD_DONE_DATA_SYNC,
             uid=CREATE_KEYS_IF_KEYS_DONT_EXISTS_CALLBACK,
             callback=look_for_user_key_and_create_if_cant_find(leap_session))

    reactor.threadpool.adjustPoolsize(20, 40)
    reactor.stop = stop_incoming_mail_fetcher(reactor.stop, leap_session)
Ejemplo n.º 11
0
    def test_create_mail(self):
        soledad = mock()
        mbox = mock()
        mail = mock()
        indexer = mock()
        mbox.content = {'uuid': 'some uuid'}
        when(mail).get_for_save(next_uid=any(), mailbox='INBOX').thenReturn([])
        when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn(defer.succeed([mbox]))
        querier = SoledadQuerier(soledad)
        when(querier).mail(any()).thenReturn([])

        when(pixelated.adapter.soledad.soledad_facade_mixin).MailboxIndexer(soledad).thenReturn(indexer)
        when(indexer).create_table(any()).thenReturn('')
        when(indexer).get_last_uid('some uuid').thenReturn(defer.succeed(42))

        mail_result = yield querier.create_mail(mail, 'INBOX')

        self.assertEquals([], mail_result)
Ejemplo n.º 12
0
    def test_extract_parts(self):
        soledad = mock()
        bdoc = mock()
        bdoc.content = {'raw': 'esse papo seu ta qualquer coisa'}
        when(soledad).get_from_index('by-type-and-payloadhash', 'cnt', any(unicode)).thenReturn([bdoc])
        multipart_attachment_file = pkg_resources.resource_filename('test.unit.fixtures', 'multipart_attachment.json')
        with open(multipart_attachment_file) as f:
            hdoc = json.loads(f.read())
        querier = SoledadQuerier(soledad)

        parts = yield querier._extract_parts(hdoc)

        self.assertIn('alternatives', parts.keys())
        self.assertIn('attachments', parts.keys())
        self.assertEquals(2, len(parts['alternatives']))
        self.assertEquals(1, len(parts['attachments']))

        self.check_alternatives(parts)
        self.check_attachments(parts)
    def test_extract_parts(self):
        soledad = mock()
        bdoc = mock()
        bdoc.content = {'raw': 'esse papo seu ta qualquer coisa'}
        when(soledad).get_from_index('by-type-and-payloadhash', 'cnt', any(unicode)).thenReturn([bdoc])
        multipart_attachment_file = os.path.join(os.path.dirname(__file__), '..', 'fixtures', 'multipart_attachment.json')
        with open(multipart_attachment_file) as f:
            hdoc = json.loads(f.read())
        querier = SoledadQuerier(soledad)

        parts = querier._extract_parts(hdoc)

        self.assertIn('alternatives', parts.keys())
        self.assertIn('attachments', parts.keys())
        self.assertEquals(2, len(parts['alternatives']))
        self.assertEquals(1, len(parts['attachments']))

        self.check_alternatives(parts)
        self.check_attachments(parts)
    def test_create_mail_increments_uid(self):
        soledad = mock()
        mbox = mock()
        mail = mock()
        when(mail).get_for_save(next_uid=any(), mailbox='INBOX').thenReturn([])
        mbox.content = {'lastuid': 0}
        when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn([mbox])
        querier = SoledadQuerier(soledad)
        when(querier).mail(any()).thenReturn([])

        self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 0)
        querier.create_mail(mail, 'INBOX')
        self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 1)
    def test_get_lastuid(self):
        soledad = mock()
        mbox = mock()
        mbox.content = {'lastuid': 0}
        when(soledad).get_from_index('by-type-and-mbox', 'mbox', 'INBOX').thenReturn([mbox])
        querier = SoledadQuerier(soledad)

        self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 0)
        mbox.content = {'lastuid': 1}
        self.assertEquals(querier.get_lastuid(querier.get_mbox('INBOX')[0]), 1)
    def test_empty_or_null_queries_are_ignored(self):
        soledad = mock()
        when(soledad).get_from_index(any(), any(), any()).thenReturn(['nonempty', 'list'])
        querier = SoledadQuerier(soledad)

        test_parameters = ['', None]

        def call_with_bad_parameters(funct):
            for param in test_parameters:
                self.assertFalse(funct(param))

        call_with_bad_parameters(querier.get_all_flags_by_mbox)
        call_with_bad_parameters(querier.get_content_by_phash)
        call_with_bad_parameters(querier.get_flags_by_chash)
        call_with_bad_parameters(querier.get_header_by_chash)
        call_with_bad_parameters(querier.get_recent_by_mbox)
        call_with_bad_parameters(querier.idents_by_mailbox)
        call_with_bad_parameters(querier.get_mbox)
Ejemplo n.º 17
0
    def test_empty_or_null_queries_are_ignored(self):
        soledad = mock()
        when(soledad).get_from_index(any(), any(), any()).thenReturn(['nonempty', 'list'])
        querier = SoledadQuerier(soledad)

        test_parameters = ['', None]

        def call_with_bad_parameters(funct):
            deferreds = []
            for param in test_parameters:
                d = defer.maybeDeferred(funct, param)
                d.addCallback(self.assertFalse)
                deferreds.append(d)
            return defer.DeferredList(deferreds)

        yield call_with_bad_parameters(querier.get_all_flags_by_mbox)
        yield call_with_bad_parameters(querier.get_content_by_phash)
        yield call_with_bad_parameters(querier.get_flags_by_chash)
        yield call_with_bad_parameters(querier.get_header_by_chash)
        yield call_with_bad_parameters(querier.get_recent_by_mbox)
        yield call_with_bad_parameters(querier.idents_by_mailbox)
        yield call_with_bad_parameters(querier.get_mbox)
 def _create_soledad_querier(self, soledad, index_key):
     soledad_querier = SoledadQuerier(soledad)
     soledad_querier.get_index_masterkey = lambda: index_key
     return soledad_querier
 def _create_soledad_querier(self, soledad, index_key):
     soledad_querier = SoledadQuerier(soledad)
     soledad_querier.get_index_masterkey = lambda: index_key
     return soledad_querier