Horde_Smtp::_auth PHP Méthode

_auth() protected méthode

Authenticate user to server for a given method.
protected _auth ( string $method )
$method string Authentication method.
    protected function _auth($method)
    {
        $user = $this->getParam('username');
        $pass = $this->getParam('password');
        $debug = sprintf("[AUTH Command - method: %s; username: %s]\n", $method, $user);
        switch ($method) {
            case 'CRAM-MD5':
            case 'CRAM-SHA1':
            case 'CRAM-SHA256':
                // RFC 2195: CRAM-MD5
                // CRAM-SHA1 & CRAM-SHA256 supported by Courier SASL library
                $this->_connection->write('AUTH ' . $method);
                $resp = $this->_getResponse(334);
                $this->_debug->active = false;
                $this->_connection->write(base64_encode($user . ' ' . hash_hmac(Horde_String::lower(substr($method, 5)), base64_decode(reset($resp)), $pass, false)));
                $this->_debug->active = true;
                $this->_debug->raw($debug);
                break;
            case 'DIGEST-MD5':
                // RFC 2831/4422; obsoleted by RFC 6331
                // Since this is obsolete, will only attempt if
                // Horde_Imap_Client is also present on the system.
                if (!class_exists('Horde_Imap_Client_Auth_DigestMD5')) {
                    throw new Horde_Smtp_Exception('DIGEST-MD5 not supported');
                }
                $this->_connection->write('AUTH ' . $method);
                $resp = $this->_getResponse(334);
                $this->_debug->active = false;
                $this->_connection->write(base64_encode(new Horde_Imap_Client_Auth_DigestMD5($user, $pass, base64_decode(reset($resp)), $this->getParam('hostspec'), 'smtp')));
                $this->_debug->active = true;
                $this->_debug->raw($debug);
                $this->_getResponse(334);
                $this->_connection->write('');
                break;
            case 'LOGIN':
                $this->_connection->write('AUTH ' . $method);
                $this->_getResponse(334);
                $this->_connection->write(base64_encode($user));
                $this->_getResponse(334);
                $this->_debug->active = false;
                $this->_connection->write(base64_encode($pass));
                $this->_debug->active = true;
                $this->_debug->raw($debug);
                break;
            case 'PLAIN':
                // RFC 2595/4616 - PLAIN SASL mechanism
                $auth = base64_encode(implode("", array($user, $user, $pass)));
                $this->_debug->active = false;
                $this->_connection->write('AUTH ' . $method . ' ' . $auth);
                $this->_debug->active = true;
                $this->_debug->raw($debug);
                break;
            case 'XOAUTH2':
                // Google XOAUTH2
                $this->_debug->active = false;
                $this->_connection->write('AUTH ' . $method . ' ' . $this->getParam('xoauth2_token'));
                $this->_debug->active = true;
                $this->_debug->raw($debug);
                try {
                    $this->_getResponse(235);
                    return;
                } catch (Horde_Smtp_Exception $e) {
                    switch ($e->getSmtpCode()) {
                        case 334:
                            $this->_connection->write('');
                            break;
                    }
                }
                break;
            default:
                throw new Horde_Smtp_Exception(sprintf('Authentication method %s not supported', $method));
        }
        $this->_getResponse(235);
    }