Horde_Smtp::_startTls PHP Method

_startTls() protected method

Starts the TLS connection to the server, if necessary. See RFC 3207.
protected _startTls ( ) : boolean
return boolean True if TLS was started.
    protected function _startTls()
    {
        $secure = $this->getParam('secure');
        if ($this->isSecureConnection() || $secure !== true && $secure !== 'tls') {
            return false;
        }
        if (!$this->queryExtension('STARTTLS')) {
            if ($secure === true) {
                return false;
            }
            throw new Horde_Smtp_Exception(Horde_Smtp_Translation::r("Server does not support TLS connections."), Horde_Smtp_Exception::LOGIN_TLSFAILURE);
        }
        $this->_connection->write('STARTTLS');
        $this->_getResponse(220, array('error' => 'logout'));
        if (!$this->_connection->startTls()) {
            $this->logout();
            $e = new Horde_Smtp_Exception();
            $e->setSmtpCode(454);
            throw $e;
        }
        $this->_debug->info('Successfully completed TLS negotiation.');
        $this->setParam('secure', 'tls');
        return true;
    }