From eb11eaa096b7ad65707fe0a7e27af093aa4dae6e Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Tue, 19 Aug 2014 16:39:27 +0400 Subject: [PATCH] MailSo fixes --- .../MailSo/Imap/Enumerations/FetchType.php | 5 +-- .../libraries/MailSo/Imap/FetchResponse.php | 44 ++++++++++++++++++- .../app/libraries/MailSo/Imap/ImapClient.php | 12 ++++- .../app/libraries/MailSo/Imap/Response.php | 28 ++++++++++++ 4 files changed, 83 insertions(+), 6 deletions(-) diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FetchType.php b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FetchType.php index b8acabd4c..6a846f8bd 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FetchType.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/Enumerations/FetchType.php @@ -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; diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/FetchResponse.php b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/FetchResponse.php index 1be2b5d96..8bba372d4 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/FetchResponse.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/FetchResponse.php @@ -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]) + ); } /** diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php index ae9210c08..2dcbec294 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/ImapClient.php @@ -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); + } + } } } diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/Response.php b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/Response.php index a2eb768fd..9518da977 100644 --- a/rainloop/v/0.0.0/app/libraries/MailSo/Imap/Response.php +++ b/rainloop/v/0.0.0/app/libraries/MailSo/Imap/Response.php @@ -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); + } }