Exemplo n.º 1
0
    def grab(self):
        # Don't run concurrently, ever.
        if self.running:
            return
        self.running = True

        from twisted.internet import reactor

        port = self.port
        if self.ssl:
            if port is None:
                port = 995
            connect = lambda h, p, f: reactor.connectSSL(
                h, p, f, ssl.ClientContextFactory())
        else:
            if port is None:
                port = 110
            connect = reactor.connectTCP

        factory = POP3GrabberFactory(self, self.ssl)
        if self.debug:
            factory = policies.TrafficLoggingFactory(
                factory, 'pop3client-%d-%f' % (self.storeID, time.time()))

        self.status.setStatus(u"Connecting to %s:%d..." % (self.domain, port))
        self.connector = connect(
            self.domain, port,
            BandwidthMeasuringFactory(factory, 'pop3-grabber'))
Exemplo n.º 2
0
    def getFactory(self):
        if self.factory is None:
            self.portal = portal.Portal(self.userbase, [self.userbase])
            self.factory = POP3ServerFactory(self.portal)

            if self.debug:
                self.factory = policies.TrafficLoggingFactory(
                    self.factory, 'pop3')
        return self.factory
Exemplo n.º 3
0
    def test_loggingFactoryOpensLogfileAutomatically(self):
        """
        When the L{policies.TrafficLoggingFactory} builds a protocol, it
        automatically opens a unique log file for that protocol and attaches
        the logfile to the built protocol.
        """
        open_calls = []
        open_rvalues = []

        def mocked_open(*args, **kwargs):
            """
            Mock for the open call to prevent actually opening a log file.
            """
            open_calls.append((args, kwargs))
            io = NativeStringIO()
            io.name = args[0]
            open_rvalues.append(io)
            return io

        self.patch(builtins, 'open', mocked_open)

        wrappedFactory = protocol.ServerFactory()
        wrappedFactory.protocol = SimpleProtocol
        factory = policies.TrafficLoggingFactory(wrappedFactory, 'test')
        first_proto = factory.buildProtocol(address.IPv4Address('TCP',
                                                                '127.0.0.1',
                                                                12345))
        second_proto = factory.buildProtocol(address.IPv4Address('TCP',
                                                                 '127.0.0.1',
                                                                 12346))

        # We expect open to be called twice, with the files passed to the
        # protocols.
        first_call = (('test-1', 'w'), {})
        second_call = (('test-2', 'w'), {})
        self.assertEqual([first_call, second_call], open_calls)
        self.assertEqual(
            [first_proto.logfile, second_proto.logfile], open_rvalues
        )
Exemplo n.º 4
0
    def getFactory(self):
        if self.factory is None:
            if self.certificateFile is not None:
                cert = PrivateCertificate.loadPEM(
                    file(self.certificateFile).read())
                certOpts = CertificateOptions(cert.privateKey.original,
                                              cert.original,
                                              requireCertificate=False,
                                              method=SSL.SSLv23_METHOD)
            else:
                certOpts = None

            self.portal = portal.Portal(
                self.userbase,
                [self.userbase, checkers.AllowAnonymousAccess()])
            self.factory = ESMTPFactory(
                self.portal, self.domain, {
                    'CRAM-MD5': credentials.CramMD5Credentials,
                    'LOGIN': imap4.LOGINCredentials,
                }, certOpts)
            if self.debug:
                self.factory = policies.TrafficLoggingFactory(
                    self.factory, 'smtp')
        return self.factory