* eMail/Net-IMAP: harden get raw response against unexpected return results from server; backport of special-use folder retrieval

This commit is contained in:
Klaus Leithoff 2013-07-26 12:27:01 +00:00
parent bbb837346d
commit 019fbb0474
2 changed files with 61 additions and 2 deletions

View File

@ -279,10 +279,16 @@ class Net_IMAP extends Net_IMAPProtocol {
if (PEAR::isError($ret)) {
return $ret;
}
if(strtoupper( $ret["RESPONSE"]["CODE"]) != "OK" ){
if (strtoupper($ret["RESPONSE"]["CODE"]) != "OK" && count($ret['PARSED'])) error_log(__METHOD__.__LINE__.' ResposeCode not OK but found:'.count($ret['PARSED']).' parsed Responses for '.$msg_id.' PartId'.$part_id);
if(strtoupper( $ret["RESPONSE"]["CODE"]) != "OK" && !empty($ret["RESPONSE"]["CODE"])){
return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
}
$ret=$ret["PARSED"][0]["EXT"][$resp_command]["CONTENT"];
foreach($ret["PARSED"] as $key => $value)
{
if (isset($ret["PARSED"][$key]["EXT"][$command]["CONTENT"])) {$found = $key; break;}
if (isset($ret["PARSED"][$key]["EXT"][$resp_command]["CONTENT"])) {$found = $key; break;}
}
$ret=($ret["PARSED"][$found]["EXT"][$resp_command]["CONTENT"]?$ret["PARSED"][$found]["EXT"][$resp_command]["CONTENT"]:$ret["PARSED"][$found]["EXT"][$command]["CONTENT"]);
return $ret;
}
@ -1451,6 +1457,44 @@ class Net_IMAP extends Net_IMAPProtocol {
}
/**
* Gets the SPECIAL-USE Folders
*
* $param string the mailbox to get the SPECIAL-USE Folders from
*
* @return string the hierarchy delimiter
*
* @access public
* @since 1.0
*/
function getSpecialUseFolders( $mailbox = '' )
{
$returnAttributes=true;
if( PEAR::isError( $ret = $this->cmdListSpecialUse( $mailbox , '*' ) ) ){
return $ret;
}
//error_log(__METHOD__.__LINE__.array2string($ret));
if(strtoupper($ret["RESPONSE"]["CODE"]) != "OK"){
return new PEAR_Error($ret["RESPONSE"]["CODE"] . ", " . $ret["RESPONSE"]["STR_CODE"]);
}
$ret_aux=array();
if( isset($ret["PARSED"]) ){
foreach( $ret["PARSED"] as $mbox ){
//If the folder has the \NoSelect atribute we don't put in the list
// it solves a bug in wu-imap that crash the IMAP server if we select that mailbox
if( isset($mbox["EXT"]["LIST"]["NAME_ATTRIBUTES"]) ){
if( $returnAttributes){
$ret_aux[]=array( 'MAILBOX' => $mbox["EXT"]["LIST"]["MAILBOX_NAME"],
'ATTRIBUTES' => $mbox["EXT"]["LIST"]["NAME_ATTRIBUTES"] ,
//'HIERACHY_DELIMITER' => $mbox["EXT"]["LIST"]["HIERACHY_DELIMITER"]
) ;
}
}
}
}
return $ret_aux;
}
/**
* Returns an array containing the names of the selected mailboxes

View File

@ -1180,6 +1180,21 @@ class Net_IMAPProtocol {
/**
* Send the LIST Command for SPECIAL-USE folders
*
* @return mixed Returns a PEAR_Error with an error message on any
* kind of failure, or true on success.
* @access public
* @since 1.0
*/
function cmdListSpecialUse($mailbox_base, $mailbox)
{
$mailbox_name=$this->_createQuotedString($mailbox);
$mailbox_base=$this->_createQuotedString($mailbox_base);
//error_log(__METHOD__.__LINE__."(SPECIAL-USE) $mailbox_base $mailbox_name");
return $this->_genericCommand('LIST', "(SPECIAL-USE) $mailbox_base $mailbox_name" );
}