Index: trunk/kernel/include/smtp.php
===================================================================
diff -u -r1390 -r3515
--- trunk/kernel/include/smtp.php (.../smtp.php) (revision 1390)
+++ trunk/kernel/include/smtp.php (.../smtp.php) (revision 3515)
@@ -8,7 +8,7 @@
define('SMTP_STATUS_NOT_CONNECTED', 1, TRUE);
define('SMTP_STATUS_CONNECTED', 2, TRUE);
- $CRLF = "\r\n";
+ $CRLF = "\n";
class smtp{
@@ -28,7 +28,7 @@
var $pass;
var $debug;
var $buffer;
-
+
/**
* List of supported authentication methods, in preferential order.
* @var array
@@ -41,7 +41,7 @@
* @access private
*/
var $_code = -1;
-
+
/**
* The most recent server response arguments.
* @var array
@@ -54,7 +54,7 @@
* @access private
*/
var $_esmtp = array();
-
+
/***************************************
** Constructor function. Arguments:
** $params - An assoc array of parameters:
@@ -72,7 +72,7 @@
***************************************/
function smtp($params = array()){
-
+
$this->timeout = 5;
$this->status = SMTP_STATUS_NOT_CONNECTED;
$this->host = 'localhost';
@@ -91,7 +91,7 @@
/***************************************
** Connect function. This will, when called
- ** statically, create a new smtp object,
+ ** statically, create a new smtp object,
** call the connect function (ie this function)
** and return it. When not called statically,
** it will connect to the server and send
@@ -171,12 +171,12 @@
if(!$this->data())
return FALSE;
-
+
// Transparency
$headers = str_replace($CRLF.'.', $CRLF.'..', trim(implode($CRLF, $this->headers)));
$body = str_replace($CRLF.'.', $CRLF.'..', $this->body);
$body = $body[0] == '.' ? '.'.$body : $body;
-
+
$this->send_data($headers);
$this->send_data('');
$this->send_data($body);
@@ -188,7 +188,7 @@
return FALSE;
}
}
-
+
/***************************************
** Function to implement HELO cmd
***************************************/
@@ -205,7 +205,7 @@
return FALSE;
}
}
-
+
/***************************************
** Function to implement EHLO cmd
***************************************/
@@ -226,16 +226,16 @@
strlen($argument) - strlen($verb) - 1);
$this->_esmtp[$verb] = $arguments;
}
-
+
return TRUE;
-
+
}
-
+
/***************************************
** Function to implement AUTH cmd
***************************************/
-
+
function _getBestAuthMethod()
{
$available_methods = explode(' ', $this->_esmtp['AUTH']);
@@ -246,13 +246,13 @@
}
return false;
}
-
-
+
+
function auth(){
if(is_resource($this->connection))
{
$method=$this->_getBestAuthMethod();
-
+
switch ($method) {
case 'DIGEST-MD5':
$result = $this->_authDigest_MD5($this->user, $this->pass);
@@ -299,7 +299,7 @@
function _authDigest_MD5($uid, $pwd)
{
$this->send_data('AUTH DIGEST-MD5');
-
+
/* 334: Continue authentication request */
if(($error=$this->_parseResponse(334)) !== true)
{
@@ -314,28 +314,28 @@
$auth_str = base64_encode($this->get_digestMD5Auth($uid, $pwd, $challenge,
$this->host, "smtp"));
-
+
$this->send_data($auth_str);
-
+
/* 334: Continue authentication request */
if(($error=$this->_parseResponse(334)) !== true) return $error;
-
+
/*
* We don't use the protocol's third step because SMTP doesn't allow
* subsequent authentication, so we just silently ignore it.
*/
$this->send_data(' ');
-
+
/* 235: Authentication successful */
if(($error=$this->_parseResponse(235)) !== true) return $error;
}
-
-
+
+
/**
* Provides the (main) client response for DIGEST-MD5
* requires a few extra parameters than the other
* mechanisms, which are unavoidable.
- *
+ *
* @param string $authcid Authentication id (username)
* @param string $pass Password
* @param string $challenge The digest challenge sent by the server
@@ -350,7 +350,7 @@
$challenge = $this->_parseChallenge($challenge);
$authzid_string = '';
if ($authzid != '') {
- $authzid_string = ',authzid="' . $authzid . '"';
+ $authzid_string = ',authzid="' . $authzid . '"';
}
if (!empty($challenge)) {
@@ -363,7 +363,7 @@
return PEAR::raiseError('Invalid digest challenge');
}
}
-
+
/**
* Parses and verifies the digest challenge*
*
@@ -412,17 +412,17 @@
$uname = posix_uname();
$tokens['realm'] = $uname['nodename'];
}
-
+
// Maxbuf
if (empty($tokens['maxbuf'])) {
$tokens['maxbuf'] = 65536;
}
-
+
// Required: nonce, algorithm
if (empty($tokens['nonce']) OR empty($tokens['algorithm'])) {
return array();
}
-
+
return $tokens;
}
@@ -438,7 +438,7 @@
* @param string $authzid Authorization id
* @return string The response= part of the digest response
* @access private
- */
+ */
function _getResponseValue($authcid, $pass, $realm, $nonce, $cnonce, $digest_uri, $authzid = '')
{
if ($authzid == '') {
@@ -470,17 +470,17 @@
for ($i=0; $i<32; $i++) {
$str .= chr(mt_rand(0, 255));
}
-
+
return base64_encode($str);
}
}
-
-
-
-
-
-
+
+
+
+
+
+
/**
* Authenticates the user using the CRAM-MD5 method.
*
@@ -495,7 +495,7 @@
function _authCRAM_MD5($uid, $pwd)
{
$this->send_data('AUTH CRAM-MD5');
-
+
/* 334: Continue authentication request */
if(($error=$this->_parseResponse(334)) !== true)
{
@@ -508,7 +508,7 @@
$challenge = base64_decode($this->_arguments[0]);
$auth_str = base64_encode($uid . ' ' . $this->_HMAC_MD5($pwd, $challenge));
-
+
$this->send_data($auth_str);
/* 235: Authentication successful */
@@ -531,7 +531,7 @@
function _authLogin($uid, $pwd)
{
$this->send_data('AUTH LOGIN');
-
+
/* 334: Continue authentication request */
if(($error=$this->_parseResponse(334)) !== true)
{
@@ -541,12 +541,12 @@
}
return $error;
}
-
+
$this->send_data( base64_encode($uid) );
-
+
/* 334: Continue authentication request */
if(($error=$this->_parseResponse(334)) !== true) return $error;
-
+
$this->send_data( base64_encode($pwd) );
/* 235: Authentication successful */
@@ -569,7 +569,7 @@
function _authPlain($uid, $pwd)
{
$this->send_data('AUTH PLAIN');
-
+
/* 334: Continue authentication request */
if(($error=$this->_parseResponse(334)) !== true)
{
@@ -602,22 +602,22 @@
if (strlen($key) > 64) {
$key = pack('H32', md5($key));
}
-
+
if (strlen($key) < 64) {
$key = str_pad($key, 64, chr(0));
}
-
+
$k_ipad = substr($key, 0, 64) ^ str_repeat(chr(0x36), 64);
$k_opad = substr($key, 0, 64) ^ str_repeat(chr(0x5C), 64);
-
+
$inner = pack('H32', md5($k_ipad . $data));
$digest = md5($k_opad . $inner);
-
+
return $digest;
}
-
+
/**
* Read a reply from the SMTP server. The reply consists of a response
* code and a response message.
@@ -639,43 +639,43 @@
global $CRLF;
$this->_code = -1;
$this->_arguments = array();
-
+
if(!is_resource($this->connection)) return false;
-
+
while ($line = fgets($this->connection, 512)) {
if ($this->debug) {
echo "DEBUG: Recv: $line
\n";
}
-
+
/* If we receive an empty line, the connection has been closed. */
if (empty($line)) {
$this->disconnect();
return 'Connection was unexpectedly closed';
}
-
+
/* Read the code and store the rest in the arguments array. */
$code = substr($line, 0, 3);
$this->_arguments[] = trim(substr($line, 4));
-
+
/* Check the syntax of the response code. */
if (is_numeric($code)) {
$this->_code = (int)$code;
} else {
$this->_code = -1;
break;
}
-
+
/* If this is not a multiline response, we're done. */
if (substr($line, 3, 1) != '-') {
break;
}
}
-
+
/* Compare the server's response code with the valid code. */
if (is_int($valid) && ($this->_code === $valid)) {
return true;
}
-
+
/* If we were given an array of valid response codes, check each one. */
if (is_array($valid)) {
foreach ($valid as $valid_code) {
@@ -684,15 +684,15 @@
}
}
}
-
+
return 'Invalid response code received from server';
}
-
+
/***************************************
** Function that handles the MAIL FROM: cmd
***************************************/
-
+
function mail($from){
if($this->is_connected()
@@ -708,7 +708,7 @@
/***************************************
** Function that handles the RCPT TO: cmd
***************************************/
-
+
function rcpt($to){
if($this->is_connected()
@@ -732,7 +732,7 @@
if($this->is_connected()
AND $this->send_data('DATA')
AND substr(trim($error = $this->get_data()), 0, 3) === '354' ){
-
+
return TRUE;
}else{
@@ -767,12 +767,12 @@
return FALSE;
}
- function bytes_left($fp)
- {
+ function bytes_left($fp)
+ {
$status = socket_get_status ($fp);
//print_r($status);
$bytes = $status["unread_bytes"];
- return $bytes;
+ return $bytes;
}
/***************************************
@@ -786,13 +786,13 @@
if(is_resource($this->connection))
{
while(strpos($return, $CRLF) === FALSE OR substr($line,3,1) !== ' ')
- {
+ {
$line = fgets($this->connection, 512);
- $return .= $line;
+ $return .= $line;
}
if($this->debug)
{
- $this->buffer[] = "GET: ".$return."
\n";
+ $this->buffer[] = "GET: ".$return."
\n";
}
return $return;
@@ -803,16 +803,16 @@
/***************************************
** Sets a variable
***************************************/
-
+
function set($var, $value){
$this->$var = $value;
return TRUE;
}
} // End of class
-
-
-
-
+
+
+
+
?>