* eMail/egw-pear: fixed problem with unexpected (but valid) multiline response for STATUS commands

This commit is contained in:
Klaus Leithoff 2013-03-04 08:03:52 +00:00
parent e8961f6fd4
commit f50768ec0b

View File

@ -28,7 +28,7 @@ require_once 'Net/Socket.php';
*/ */
class Net_IMAPProtocol { class Net_IMAPProtocol {
/** /**
* The auth methods this class support * The auth methods this class support
* @var array * @var array
@ -72,7 +72,7 @@ class Net_IMAPProtocol {
/** /**
* The options for SSL/TLS connection * The options for SSL/TLS connection
* (see documentation for stream_context_create) * (see documentation for stream_context_create)
* @var array * @var array
*/ */
@ -260,7 +260,7 @@ class Net_IMAPProtocol {
* Sets printed output of errors on or of * Sets printed output of errors on or of
* *
* @param boolean true or false * @param boolean true or false
* *
* @return nothing * @return nothing
* @access public * @access public
* @since 1.1 * @since 1.1
@ -406,7 +406,7 @@ class Net_IMAPProtocol {
} }
/** /**
* set the options for a SSL/TLS connection * set the options for a SSL/TLS connection
* (see documentation for stream_context_create) * (see documentation for stream_context_create)
* *
* @param array $options the options for the SSL/TLS connection * @param array $options the options for the SSL/TLS connection
@ -1112,7 +1112,7 @@ class Net_IMAPProtocol {
* Send the STATUS Mailbox Command * Send the STATUS Mailbox Command
* *
* @param string $mailbox the mailbox name * @param string $mailbox the mailbox name
* @param mixed $request the request status * @param mixed $request the request status
* it could be an array or space separated string of * it could be an array or space separated string of
* MESSAGES | RECENT | UIDNEXT * MESSAGES | RECENT | UIDNEXT
* UIDVALIDITY | UNSEEN * UIDVALIDITY | UNSEEN
@ -1138,7 +1138,7 @@ class Net_IMAPProtocol {
$this->_prot_error("request '$status_data' is invalid! see RFC 3501!!!!" , __LINE__ , __FILE__); $this->_prot_error("request '$status_data' is invalid! see RFC 3501!!!!" , __LINE__ , __FILE__);
} }
} }
// back to space separated string // back to space separated string
$request = implode(' ', $request); $request = implode(' ', $request);
@ -1147,7 +1147,7 @@ class Net_IMAPProtocol {
if (!PEAR::isError($ret) && isset($ret['PARSED'])) { if (!PEAR::isError($ret) && isset($ret['PARSED'])) {
foreach ($ret['PARSED'] as &$parsed) foreach ($ret['PARSED'] as &$parsed)
{ {
if (!empty($parsed['EXT'])) if (!empty($parsed['EXT']) && $parsed['COMMAND']=='STATUS')
{ {
if(empty($ret['RESPONSE']['CODE'])) $ret['RESPONSE']['CODE'] ='OK'; if(empty($ret['RESPONSE']['CODE'])) $ret['RESPONSE']['CODE'] ='OK';
$ret['PARSED'] = $parsed['EXT']; $ret['PARSED'] = $parsed['EXT'];
@ -1337,7 +1337,7 @@ class Net_IMAPProtocol {
*/ */
function cmdSort($sort_cmd) function cmdSort($sort_cmd)
{ {
/* /*
if ($_charset != '' ) if ($_charset != '' )
$_charset = "[$_charset] "; $_charset = "[$_charset] ";
$param = sprintf("%s%s",$charset,$search_cmd); $param = sprintf("%s%s",$charset,$search_cmd);
@ -1764,7 +1764,7 @@ class Net_IMAPProtocol {
return new PEAR_Error("This IMAP server does not support ACL's! "); return new PEAR_Error("This IMAP server does not support ACL's! ");
} }
$mailbox_name=$this->_createQuotedString($mailbox_name); $mailbox_name=$this->_createQuotedString($mailbox_name);
return $this->_genericCommand('DELETEACL', sprintf("%s \"%s\"",$mailbox_name,$user) ); return $this->_genericCommand('DELETEACL', sprintf("%s \"%s\"",$mailbox_name,$user) );
} }
@ -2072,7 +2072,7 @@ class Net_IMAPProtocol {
function _createQuotedString($mailbox) function _createQuotedString($mailbox)
{ {
$search = array('\\', '"'); $search = array('\\', '"');
$replace = array('\\\\', '\\"'); $replace = array('\\\\', '\\"');
@ -2422,14 +2422,14 @@ class Net_IMAPProtocol {
#error_log(__METHOD__. $len . "#".$str."\n"); #error_log(__METHOD__. $len . "#".$str."\n");
$startingpos = $pos; $startingpos = $pos;
if ($str[$pos] !== '"') return false; // start condition failed if ($str[$pos] !== '"') return false; // start condition failed
$pos++; $pos++;
$delimCount=0; $delimCount=0;
while($str[$pos] !== '"' && $pos < $len) { while($str[$pos] !== '"' && $pos < $len) {
// this is a fix to stop before the delimiter, in broken string messages containing an odd number of double quotes // this is a fix to stop before the delimiter, in broken string messages containing an odd number of double quotes
// the idea is to check for a stopDelimited followed by eiter a new startDelimiter or an other stopDelimiter // the idea is to check for a stopDelimited followed by eiter a new startDelimiter or an other stopDelimiter
// that allows to have something like '"Name (Nick)" <email>' containing one delimiter // that allows to have something like '"Name (Nick)" <email>' containing one delimiter
// if you have something like "Name ((something))" we must count the delimiters (and hope that they are not unbalanced too) // if you have something like "Name ((something))" we must count the delimiters (and hope that they are not unbalanced too)
// and check if we have a negative amount of delimiters or no delimiters to meet the stop condition, before we run into a closing double quote // and check if we have a negative amount of delimiters or no delimiters to meet the stop condition, before we run into a closing double quote
if ($str[$pos] === $startDelim) $delimCount++; if ($str[$pos] === $startDelim) $delimCount++;
if ($str[$pos] === $stopDelim) $delimCount--; if ($str[$pos] === $stopDelim) $delimCount--;
if ($str[$pos] === $stopDelim && ($str[$pos+1] === $startDelim || ($str[$pos+1] === $stopDelim && $delimCount<=0))) { if ($str[$pos] === $stopDelim && ($str[$pos+1] === $startDelim || ($str[$pos+1] === $stopDelim && $delimCount<=0))) {
@ -2898,7 +2898,7 @@ class Net_IMAPProtocol {
$expused = $this->_parseOneStringResponse( $str,__LINE__ , __FILE__ ); $expused = $this->_parseOneStringResponse( $str,__LINE__ , __FILE__ );
$expmax = $this->_parseOneStringResponse( $str,__LINE__ , __FILE__ ); $expmax = $this->_parseOneStringResponse( $str,__LINE__ , __FILE__ );
return array(); //throw away this information as this info seems quite useless return array(); //throw away this information as this info seems quite useless
break; break;
case "FETCH" : case "FETCH" :
$this->_parseSpace( $str ,__LINE__ ,__FILE__ ); $this->_parseSpace( $str ,__LINE__ ,__FILE__ );
// Get the parsed pathenthesis // Get the parsed pathenthesis
@ -2917,7 +2917,7 @@ class Net_IMAPProtocol {
$this->_parseSpace( $str , __LINE__ , __FILE__ ); $this->_parseSpace( $str , __LINE__ , __FILE__ );
$this->_getNextToken($str , $shared, false); $this->_getNextToken($str , $shared, false);
$struct_arr['NAMESPACES']['shared'] = $this->_arrayfy_content($shared); $struct_arr['NAMESPACES']['shared'] = $this->_arrayfy_content($shared);
return array($token=>$struct_arr); return array($token=>$struct_arr);
break; break;
case "CAPABILITY" : case "CAPABILITY" :
@ -3065,7 +3065,7 @@ class Net_IMAPProtocol {
//$str = " INBOX\r\nA0006 OK Completed\r\n"; //$str = " INBOX\r\nA0006 OK Completed\r\n";
$this->_parseSpace($str, __LINE__, __FILE__); $this->_parseSpace($str, __LINE__, __FILE__);
$this->_getNextToken($str, $mailbox); $this->_getNextToken($str, $mailbox);
$arr = array(); $arr = array();
while (substr($str, 0, 2) != "\r\n") { while (substr($str, 0, 2) != "\r\n") {
$this->_parseSpace($str, __LINE__, __FILE__); $this->_parseSpace($str, __LINE__, __FILE__);
@ -3202,7 +3202,7 @@ class Net_IMAPProtocol {
// I get the command // I get the command
$this->_getNextToken($str, $command); $this->_getNextToken($str, $command);
if (($ext_arr = $this->_retrParsedResponse($str, $command, $msg_nro)) == false) { if (($ext_arr = $this->_retrParsedResponse($str, $command, $msg_nro)) == false) {
// if this bogus response cis a FLAGS () or EXPUNGE response // if this bogus response cis a FLAGS () or EXPUNGE response
// the ignore it // the ignore it
@ -3298,7 +3298,7 @@ class Net_IMAPProtocol {
if(function_exists('mb_convert_encoding')) { if(function_exists('mb_convert_encoding')) {
return mb_convert_encoding($str, "UTF7-IMAP", "ISO-8859-1"); return mb_convert_encoding($str, "UTF7-IMAP", "ISO-8859-1");
} }
$encoded_utf7 = ''; $encoded_utf7 = '';
$base64_part = ''; $base64_part = '';
if(is_array($str)){ if(is_array($str)){
@ -3432,8 +3432,8 @@ class Net_IMAPProtocol {
} }
return true; return true;
} }
function _getLineLength($string) function _getLineLength($string)
{ {
if (extension_loaded('mbstring')) { if (extension_loaded('mbstring')) {
return mb_strlen($string,'latin1'); return mb_strlen($string,'latin1');
@ -3442,7 +3442,7 @@ class Net_IMAPProtocol {
} }
} }
function _getSubstr($string, $start, $length = false) function _getSubstr($string, $start, $length = false)
{ {
if (extension_loaded('mbstring')) { if (extension_loaded('mbstring')) {
if($length !== false) { if($length !== false) {