MailSo fixes

This commit is contained in:
RainLoop Team 2014-08-19 16:39:27 +04:00
parent 860bf3be74
commit eb11eaa096
4 changed files with 83 additions and 6 deletions

View file

@ -79,6 +79,7 @@ class FetchType
{
$aReturn = array();
self::addHelper($aReturn, self::UID);
self::addHelper($aReturn, self::RFC822_SIZE);
foreach ($aFetchItems as $mFetchKey)
{
@ -92,22 +93,20 @@ class FetchType
break;
case self::INDEX:
case self::UID:
case self::RFC822_SIZE:
break;
case self::ALL:
self::addHelper($aReturn, self::FLAGS);
self::addHelper($aReturn, self::INTERNALDATE);
self::addHelper($aReturn, self::RFC822_SIZE);
self::addHelper($aReturn, self::ENVELOPE);
break;
case self::FAST:
self::addHelper($aReturn, self::FLAGS);
self::addHelper($aReturn, self::INTERNALDATE);
self::addHelper($aReturn, self::RFC822_SIZE);
break;
case self::FULL:
self::addHelper($aReturn, self::FLAGS);
self::addHelper($aReturn, self::INTERNALDATE);
self::addHelper($aReturn, self::RFC822_SIZE);
self::addHelper($aReturn, self::ENVELOPE);
self::addHelper($aReturn, self::BODY);
break;

View file

@ -197,6 +197,28 @@ class FetchResponse
return $sReturn;
}
private static function findFetchUidAndSize($aList)
{
$bUid = false;
$bSize = false;
if (is_array($aList))
{
foreach ($aList as $mItem)
{
if (\MailSo\Imap\Enumerations\FetchType::UID === $mItem)
{
$bUid = true;
}
else if (\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE === $mItem)
{
$bSize = true;
}
}
}
return $bUid && $bSize;
}
/**
* @param \MailSo\Imap\Response $oImapResponse
*
@ -204,10 +226,28 @@ class FetchResponse
*/
public static function IsValidFetchImapResponse($oImapResponse)
{
return ($oImapResponse && true !== $oImapResponse->IsStatusResponse
return (
$oImapResponse
&& true !== $oImapResponse->IsStatusResponse
&& \MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType
&& 3 < count($oImapResponse->ResponseList) && 'FETCH' === $oImapResponse->ResponseList[2]
&& is_array($oImapResponse->ResponseList[3]));
&& is_array($oImapResponse->ResponseList[3])
);
}
/**
* @param \MailSo\Imap\Response $oImapResponse
*
* @return bool
*/
public static function IsNotEmptyFetchImapResponse($oImapResponse)
{
return (
$oImapResponse
&& self::IsValidFetchImapResponse($oImapResponse)
&& isset($oImapResponse->ResponseList[3])
&& self::findFetchUidAndSize($oImapResponse->ResponseList[3])
);
}
/**

View file

@ -909,7 +909,17 @@ class ImapClient extends \MailSo\Net\NetClient
{
if (FetchResponse::IsValidFetchImapResponse($oImapResponse))
{
$aReturn[] = FetchResponse::NewInstance($oImapResponse);
if (FetchResponse::IsNotEmptyFetchImapResponse($oImapResponse))
{
$aReturn[] = FetchResponse::NewInstance($oImapResponse);
}
else
{
if ($this->oLogger)
{
$this->oLogger->Write('Skipped Imap Response! ['.$oImapResponse->ToLine().']', \MailSo\Log\Enumerations\Type::NOTICE);
}
}
}
}

View file

@ -64,4 +64,32 @@ class Response
{
return new self();
}
/**
* @param string $aList
*
* @return string
*/
private function recToLine($aList)
{
$aResult = array();
if (\is_array($aList))
{
foreach ($aList as $mItem)
{
$aResult[] = \is_array($mItem) ? '('.$this->recToLine($mItem).')' : (string) $mItem;
}
}
return \implode(' ', $aResult);
}
/**
* @return string
*/
public function ToLine()
{
return $this->recToLine($this->ResponseList);
}
}