Re: Fwd: a PATCH to Net_SMTP-1.0 and update
| From: | Damian Alejandro Fernandez Sosa | Date: | Fri, 03 Jan 2003 04:09:35 +0000 |
| Subject: | Re: Fwd: a PATCH to Net_SMTP-1.0 and update | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-12051@lists.php.net to get a copy of this message | ||
I send 2 patches against version 1.3 of SMTP.php (Net_SMTP class)
(diff cvs_version my_modified_version)
STMP.php_SIZE_CONTROL: checks the size you're going to send to the SIZE
capability (if that size is equal or greater that the server's
capability , Dont allow to send the email (because you only are wasting
network resourses) )
SMTP.php_auth_check: lets you choose the auth method to authenticate to
the server from the available list of methods (LOGIN AND PLAIN for now,
CRAM-MD5 and DIGEST-MD5 later).
Also, negociates an auth method with the server.
Please commit this changes if you consider they're OK
Thanks.
Once those changes are commited I'm going to use this class as base to
make Net_LMTP class to allow access to LMTP servers
On Thu, 2003-01-02 at 14:20, Jon Parise wrote:
> On Thu, Jan 02, 2003 at 11:12:37AM -0300, Damian Fernandez Sosa (DESC) wrote:
>
> > Please dont commit those changes yet.
>
> I've only committed the "off-by-one" bug fix in identifySender().
>
> > If you like the way this functionality is coded, I'd like to add the following
> > changes before you commit it:
>
> Sounds good. In the future, please send specific diff's instead of an
> entire file. A separate patch for each new piece of functionality
> would be best.
>
> --
> Jon Parise (jon@php.net) :: The PHP Project (http://www.php.net/)
254a255,261 > if (isset($this->esmtp['SIZE'])) { > if ( strlen($data) >= $this->esmtp['SIZE'] ){ > $this->disconnect(); > return new PEAR_Error('Message size excedes the server limit'); > } > } > 68a69,75 > > /** > * List of auth methods sorted by use > * @var string > */ > var $auth_methods = array ( 'LOGIN' , 'PLAIN' ); > 136a144,164 > * returns the best auth method that the server accepts > * > * @return mixed Returns a PEAR_Error with an error message on any > * kind of failure, or true on success. > * @access private > */ > function _getAuthMethod() > { > > $server_auths=explode(" ",$this->esmtp['AUTH'] ); > > for ( $a = 0 ; $a <count( $this->auth_methods ) ; $a++ ){ > > if( in_array( $this->auth_methods[$a] , $server_auths ) ){ > return $this->auth_methods[$a]; > } > } > return new PEAR_Error('The server does not accept any suported auth method'); > } > > /** 140a169 > * @param string The optional "mandatory" method to authenticate with. 146,150c175 < function auth($uid, $pwd) < { < /* Note: not currently checking if AUTH LOGIN is allowed */ < /* Note: only allows one authentication mechanism */ < --- > function auth($uid, $pwd , $method = null ) { 152a178,198 > } else { > if ( $method == null ){ > if (PEAR::isError( $method = $this->_getAuthMethod() ) ) { > return $method; // THE ERROR > } > } else { > $method = strtoupper($method); > // SAFETY CHECK > } > } > > switch ($method){ > case "LOGIN" : > $err = $this->_authLogin($uid,$pwd); > break; > case "PLAIN" : > $err = $this->_authPlain($uid,$pwd); > break; > default : > $err = new PEAR_Error('auth method $method not supported'); > break; 155c201,220 < if (PEAR::isError($this->socket->write("AUTH LOGIN\r\n"))) { --- > if ( PEAR::isError( $err ) ){ > return $err; > } > return true; > } > > > /** > * Attempt to do SMTP LOGIN authentication. > * > * @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 _authLogin($uid, $pwd) { > > if (PEAR::isError($this->socket->write("AUTH LOGIN\r\n"))) { 169c234 < if (PEAR::isError($this->socket->write(base64_encode($pwd) . "\r\n"))) { --- > if (PEAR::isError($this->socket->write(base64_encode($pwd) . "\r\n"))) { 172c237 < if (!$this->validateResponse('235')) { --- > if (!$this->validateResponse('235')) { 178a244,277 > > /** > * Attempt to do SMTP PLAIN authentication. > * > * @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 _authPlain($uid, $pwd) { > > if (PEAR::isError($this->socket->write("AUTH PLAIN\r\n"))) { > return new PEAR_Error('write to socket failed'); > } > if (!$this->validateResponse('334')) { > return new PEAR_Error('AUTH LOGIN not recognized'); > } > > if (PEAR::isError($this->socket->write( base64_encode(chr(0) . $uid . chr(0) . $pwd ) . "\r\n"))) { > return new PEAR_Error('write to socket failed'); > } > if (!$this->validateResponse('235')) { > return new PEAR_Error('235 not received'); > } > return true; > } > > > > > >
254a255,261 > if (isset($this->esmtp['SIZE'])) { > if ( strlen($data) >= $this->esmtp['SIZE'] ){ > $this->disconnect(); > return new PEAR_Error('Message size excedes the server limit'); > } > } > 68a69,75 > > /** > * List of auth methods sorted by use > * @var string > */ > var $auth_methods = array ( 'LOGIN' , 'PLAIN' ); > 136a144,164 > * returns the best auth method that the server accepts > * > * @return mixed Returns a PEAR_Error with an error message on any > * kind of failure, or true on success. > * @access private > */ > function _getAuthMethod() > { > > $server_auths=explode(" ",$this->esmtp['AUTH'] ); > > for ( $a = 0 ; $a <count( $this->auth_methods ) ; $a++ ){ > > if( in_array( $this->auth_methods[$a] , $server_auths ) ){ > return $this->auth_methods[$a]; > } > } > return new PEAR_Error('The server does not accept any suported auth method'); > } > > /** 140a169 > * @param string The optional "mandatory" method to authenticate with. 146,150c175 < function auth($uid, $pwd) < { < /* Note: not currently checking if AUTH LOGIN is allowed */ < /* Note: only allows one authentication mechanism */ < --- > function auth($uid, $pwd , $method = null ) { 152a178,198 > } else { > if ( $method == null ){ > if (PEAR::isError( $method = $this->_getAuthMethod() ) ) { > return $method; // THE ERROR > } > } else { > $method = strtoupper($method); > // SAFETY CHECK > } > } > > switch ($method){ > case "LOGIN" : > $err = $this->_authLogin($uid,$pwd); > break; > case "PLAIN" : > $err = $this->_authPlain($uid,$pwd); > break; > default : > $err = new PEAR_Error('auth method $method not supported'); > break; 155c201,220 < if (PEAR::isError($this->socket->write("AUTH LOGIN\r\n"))) { --- > if ( PEAR::isError( $err ) ){ > return $err; > } > return true; > } > > > /** > * Attempt to do SMTP LOGIN authentication. > * > * @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 _authLogin($uid, $pwd) { > > if (PEAR::isError($this->socket->write("AUTH LOGIN\r\n"))) { 169c234 < if (PEAR::isError($this->socket->write(base64_encode($pwd) . "\r\n"))) { --- > if (PEAR::isError($this->socket->write(base64_encode($pwd) . "\r\n"))) { 172c237 < if (!$this->validateResponse('235')) { --- > if (!$this->validateResponse('235')) { 178a244,277 > > /** > * Attempt to do SMTP PLAIN authentication. > * > * @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 _authPlain($uid, $pwd) { > > if (PEAR::isError($this->socket->write("AUTH PLAIN\r\n"))) { > return new PEAR_Error('write to socket failed'); > } > if (!$this->validateResponse('334')) { > return new PEAR_Error('AUTH LOGIN not recognized'); > } > > if (PEAR::isError($this->socket->write( base64_encode(chr(0) . $uid . chr(0) . $pwd ) . "\r\n"))) { > return new PEAR_Error('write to socket failed'); > } > if (!$this->validateResponse('235')) { > return new PEAR_Error('235 not received'); > } > return true; > } > > > > > >