Пример #1
0
        def callback(password):
            # Note that we cheat with the context factory here (value=1),
            # because ssl.connectSSL does it automatically, and in the
            # case of STARTTLS we override esmtpState_starttls above
            # to supply the correct SSL context.
            factory = smtp.ESMTPSenderFactory(username, password, from_addr,
                                              to_addrs, msg,
                                              deferred, retries, timeout,
                                              1, heloFallback, authRequired,
                                              securityRequired)

            factory.protocol = _TwistedESMTPSender
            factory.testing  = testing

            # Convert the Unicode hostname to an str
            # before passing to twisted since twisted uses
            # a repr of the hostname in error messages.
            host = self.account.host.encode("utf-8", "ignore")

            if self.account.connectionSecurity == 'SSL':
                ssl.connectSSL(host, self.account.port, factory,
                               self.view)
            else:
                ssl.connectTCP(host, self.account.port, factory,
                               self.view)
Пример #2
0
    def _connectToServer(self):
        if __debug__:
            trace("_connectToServer")

        if self.cancel:
            return self._resetClient()

        self.view.refresh()

        #Overidden method
        self._getAccount()

        # The isOnline check is performed in the Twisted thread
        # so pass in a view.
        if not Globals.mailService.isOnline(self.view):
            if self.statusMessages:
                msg = constants.MAIL_PROTOCOL_OFFLINE % \
                              {"accountName": self.account.displayName}

                setStatusMessage(msg)
            return

        if self.performingAction:
            if __debug__:
                trace("%s is currently in use request ignored" %
                      self.clientType)
            return

        self.performingAction = True

        if self.statusMessages:
            msg = constants.MAIL_PROTOCOL_CONNECTION \
                          % {"accountName": self.account.displayName,
                             "serverDNSName": self.account.host}

            setStatusMessage(msg)

        self.factory = self.factoryType(self)

        if self.testing:
            # If in testing mode then do not want to retry connection or
            # wait a long period for a timeout
            self.factory.retries = 0
            self.factory.timeout = constants.TESTING_TIMEOUT

        if self.account.connectionSecurity == 'SSL':
            ssl.connectSSL(self.account.host, self.account.port, self.factory,
                           self.view)
        else:
            ssl.connectTCP(self.account.host, self.account.port, self.factory,
                           self.view)
Пример #3
0
    def _connectToServer(self):
        if __debug__:
            trace("_connectToServer")

        if self.cancel:
            return self._resetClient()

        self.view.refresh()

        #Overidden method
        self._getAccount()

        # The isOnline check is performed in the Twisted thread
        # so pass in a view.
        if not Globals.mailService.isOnline(self.view):
            if self.statusMessages:
                msg = constants.MAIL_PROTOCOL_OFFLINE % \
                              {"accountName": self.account.displayName}

                setStatusMessage(msg)
            return

        if self.performingAction:
            if __debug__:
                trace("%s is currently in use request ignored" % self.clientType)
            return

        self.performingAction = True

        if self.statusMessages:
            msg = constants.MAIL_PROTOCOL_CONNECTION \
                          % {"accountName": self.account.displayName,
                             "serverDNSName": self.account.host}

            setStatusMessage(msg)

        self.factory = self.factoryType(self)

        if self.testing:
            # If in testing mode then do not want to retry connection or
            # wait a long period for a timeout
            self.factory.retries = 0
            self.factory.timeout = constants.TESTING_TIMEOUT

        if self.account.connectionSecurity == 'SSL':
            ssl.connectSSL(self.account.host, self.account.port,
                           self.factory, self.view)
        else:
            ssl.connectTCP(self.account.host, self.account.port,
                           self.factory, self.view)
Пример #4
0
def connectFactory(factory, host, port, timeout):
    if getattr(factory, 'startTLS', False):
        return ssl.connectSSL(host,
                              port,
                              factory,
                              factory.repositoryView,
                              timeout=timeout)
    else:
        return reactor.connectTCP(host, port, factory, timeout=timeout)
Пример #5
0
    def connect(self, password, useSSL, register, view):

        factory = client.basicClientFactory(self.id, password)
        self.connected = False

        if register:
            invalidUser = lambda x: factory.authenticator.registerAccount()
        else:
            invalidUser = self.invaliduser

        factory.addBootstrap('//event/stream/authd', self.authd)
        factory.addBootstrap("//event/client/basicauth/authfailed",
                             self.authfailed)
        factory.addBootstrap("//event/client/basicauth/invaliduser",
                             invalidUser)
        factory.addBootstrap("//event/stream/error", self.error)

        if useSSL:
            ssl.connectSSL(self.host, 5223, factory, view)
        else:
            reactor.connectTCP(self.host, 5222, factory)
Пример #6
0
        def callback(password):
            # Note that we cheat with the context factory here (value=1),
            # because ssl.connectSSL does it automatically, and in the
            # case of STARTTLS we override esmtpState_starttls above
            # to supply the correct SSL context.
            factory = smtp.ESMTPSenderFactory(username, password, from_addr,
                                              to_addrs, msg, deferred, retries,
                                              timeout, 1, heloFallback,
                                              authRequired, securityRequired)

            factory.protocol = _TwistedESMTPSender
            factory.testing = testing

            # Convert the Unicode hostname to an str
            # before passing to twisted since twisted uses
            # a repr of the hostname in error messages.
            host = self.account.host.encode("utf-8", "ignore")

            if self.account.connectionSecurity == 'SSL':
                ssl.connectSSL(host, self.account.port, factory, self.view)
            else:
                ssl.connectTCP(host, self.account.port, factory, self.view)
Пример #7
0
    def connect(self, password, useSSL, register, view):

        factory = client.basicClientFactory(self.id, password)
        self.connected = False

        if register:
            invalidUser = lambda x: factory.authenticator.registerAccount()
        else:
            invalidUser = self.invaliduser

        factory.addBootstrap('//event/stream/authd',
                             self.authd)
        factory.addBootstrap("//event/client/basicauth/authfailed",
                             self.authfailed)
        factory.addBootstrap("//event/client/basicauth/invaliduser",
                             invalidUser)
        factory.addBootstrap("//event/stream/error",
                             self.error)

        if useSSL:
            ssl.connectSSL(self.host, 5223, factory, view)
        else:
            reactor.connectTCP(self.host, 5222, factory)
Пример #8
0
def connectFactory(factory, host, port, timeout):
    if getattr(factory, 'startTLS', False):
        return ssl.connectSSL(host, port, factory, factory.repositoryView,
                              timeout=timeout)
    else:
        return reactor.connectTCP(host, port, factory, timeout=timeout)