Beispiel #1
0
 def setUp(self):
     """
     setUp method for each test
     We override mixin method since we are only testing
     MessageCollection interface in this particular TestCase
     """
     memstore = MemoryStore()
     self.messages = MessageCollection("testmbox%s" % (self.count,),
                                       self._soledad, memstore=memstore)
     MessageCollectionTestCase.count += 1
Beispiel #2
0
    def __init__(self, uuid, userid, soledad):
        """
        Initializes the server factory.

        :param uuid: user uuid
        :type uuid: str

        :param userid: user id ([email protected])
        :type userid: str

        :param soledad: soledad instance
        :type soledad: Soledad
        """
        self._uuid = uuid
        self._userid = userid
        self._soledad = soledad
        self._memstore = MemoryStore(
            permanent_store=SoledadStore(soledad))

        theAccount = SoledadBackedAccount(
            uuid, soledad=soledad,
            memstore=self._memstore)
        self.theAccount = theAccount
    def _init_local_soledad(self):
        """
        Initialize local Soledad instance.
        """
        self.uuid = self._settings.get_uuid(self.userid)
        if not self.uuid:
            print "Cannot get UUID from settings. Log in at least once."
            return False

        print "UUID: %s" % (self.uuid)

        secrets, localdb = get_db_paths(self.uuid)

        self.sol = initialize_soledad(self.uuid, self.userid, self.passwd,
                                      secrets, localdb, "/tmp", "/tmp")
        memstore = MemoryStore(permanent_store=SoledadStore(self.sol),
                               write_period=5)
        self.acct = SoledadBackedAccount(self.userid,
                                         self.sol,
                                         memstore=memstore)
        return True
Beispiel #4
0
    def setUp(self):
        """
        Setup method for each test.

        Initializes and run a LEAP IMAP4 Server,
        but passing the same Soledad instance (it's costly to initialize),
        so we have to be sure to restore state across tests.
        """
        UUID = 'deadbeef',
        USERID = TEST_USER
        memstore = MemoryStore()

        d = defer.Deferred()
        self.server = LeapIMAPServer(
            uuid=UUID, userid=USERID,
            contextFactory=self.serverCTX,
            # XXX do we really need this??
            soledad=self._soledad)

        self.client = SimpleClient(d, contextFactory=self.clientCTX)
        self.connected = d

        # XXX REVIEW-ME.
        # We're adding theAccount here to server
        # but it was also passed to initialization
        # as it was passed to realm.
        # I THINK we ONLY need to do it at one place now.

        theAccount = SoledadBackedAccount(
            USERID,
            soledad=self._soledad,
            memstore=memstore)
        LeapIMAPServer.theAccount = theAccount

        # in case we get something from previous tests...
        for mb in self.server.theAccount.mailboxes:
            self.server.theAccount.delete(mb)

        # email parser
        self.parser = parser.Parser()
Beispiel #5
0
 def _create_account(self, uuid, soledad_session):
     memstore = MemoryStore(
         permanent_store=SoledadStore(soledad_session.soledad))
     return SoledadBackedAccount(uuid, soledad_session.soledad, memstore)
Beispiel #6
0
class LeapIMAPFactory(ServerFactory):
    """
    Factory for a IMAP4 server with soledad remote sync and gpg-decryption
    capabilities.
    """

    def __init__(self, uuid, userid, soledad):
        """
        Initializes the server factory.

        :param uuid: user uuid
        :type uuid: str

        :param userid: user id ([email protected])
        :type userid: str

        :param soledad: soledad instance
        :type soledad: Soledad
        """
        self._uuid = uuid
        self._userid = userid
        self._soledad = soledad
        self._memstore = MemoryStore(
            permanent_store=SoledadStore(soledad))

        theAccount = SoledadBackedAccount(
            uuid, soledad=soledad,
            memstore=self._memstore)
        self.theAccount = theAccount

        # XXX how to pass the store along?

    def buildProtocol(self, addr):
        """
        Return a protocol suitable for the job.

        :param addr: remote ip address
        :type addr:  str
        """
        imapProtocol = LeapIMAPServer(
            uuid=self._uuid,
            userid=self._userid,
            soledad=self._soledad)
        imapProtocol.theAccount = self.theAccount
        imapProtocol.factory = self
        return imapProtocol

    def doStop(self, cv=None):
        """
        Stops imap service (fetcher, factory and port).

        :param cv: A condition variable to which we can signal when imap
                   indeed stops.
        :type cv: threading.Condition
        :return: a Deferred that stops and flushes the in memory store data to
                 disk in another thread.
        :rtype: Deferred
        """
        if DO_PROFILE:
            log.msg("Stopping PROFILING")
            pr.disable()
            pr.dump_stats(PROFILE_DAT)

        ServerFactory.doStop(self)

        if cv is not None:
            def _stop_imap_cb():
                logger.debug('Stopping in memory store.')
                self._memstore.stop_and_flush()
                while not self._memstore.producer.is_queue_empty():
                    logger.debug('Waiting for queue to be empty.')
                    # TODO use a gatherResults over the new/dirty
                    # deferred list,
                    # as in memorystore's expunge() method.
                    time.sleep(1)
                # notify that service has stopped
                logger.debug('Notifying that service has stopped.')
                cv.acquire()
                cv.notify()
                cv.release()

            return threads.deferToThread(_stop_imap_cb)