Index: SMTP.php =================================================================== RCS file: /repository/pear/Net_SMTP/SMTP.php,v retrieving revision 1.20 diff -u -r1.20 SMTP.php --- SMTP.php 12 Jan 2003 23:21:00 -0000 1.20 +++ SMTP.php 14 Jan 2003 03:46:01 -0000 @@ -82,7 +82,7 @@ * The list of supported authentication methods, ordered by preference. * @var string */ - var $_auth_methods = array('CRAM-MD5', 'LOGIN', 'PLAIN'); + var $_auth_methods = array('DIGEST-MD5', 'CRAM-MD5', 'LOGIN', 'PLAIN'); /** * Constructor @@ -346,6 +346,9 @@ } switch ($method) { + case 'DIGEST-MD5': + $result = $this->_authDigest_MD5($uid, $pwd); + break; case 'CRAM-MD5': $result = $this->_authCRAM_MD5($uid, $pwd); break; @@ -401,6 +404,47 @@ $digest = md5($k_opad . $inner); return $digest; + } + + /* Authenticates the user using the DIGEST-MD5 method. + * + * @param string The userid to authenticate as. + * @param string The password to authenticate with. + * + * @return mixed Returns a PEAR_Error with an error message on any + * kind of failure, or true on success. + * @access private + */ + function _authDigest_MD5($uid, $pwd) + { + if (PEAR::isError($error = $this->_put('AUTH', 'DIGEST-MD5'))) { + return $error; + } + if (PEAR::isError($error = $this->_parseResponse(334))) { + return $error; + } + + $challenge = base64_decode($this->_arguments[0]); + include_once('Auth/SASL.php'); + $digest_auth=&Auth_SASL::factory('digestmd5'); + $auth_str = base64_encode( $digest_auth->getResponse($uid, $pwd, $challenge, $this->host, "smtp") ) ; + if (PEAR::isError($error = $this->_put($auth_str ))) { + return $error; + } + if (PEAR::isError($error = $this->_parseResponse(334))) { + return $error; + } + /* + We don't use the protocol's steep three + (SMTP don't allow subsequent authentication), + so we silently ignore them + */ + if (PEAR::isError($error = $this->_put(" " ))) { + return $error; + } + if (PEAR::isError($error = $this->_parseResponse(235))) { + return $error; + } } /* Authenticates the user using the CRAM-MD5 method.