Speedup IMAP FETCH response

This commit is contained in:
djmaze 2022-01-06 13:16:18 +01:00
parent 58f98cd69d
commit ab6b9bb412
2 changed files with 10 additions and 34 deletions

View file

@ -157,43 +157,19 @@ class FetchResponse
return '';
}
private static function findFetchUidAndSize(array $aList) : bool
public static function isValidImapResponse(Response $oImapResponse) : bool
{
$bUid = false;
$bSize = false;
foreach ($aList as $mItem)
{
if (Enumerations\FetchType::UID === $mItem)
{
$bUid = true;
}
else if (Enumerations\FetchType::RFC822_SIZE === $mItem)
{
$bSize = true;
}
}
return $bUid && $bSize;
}
public static function IsValidFetchImapResponse(Response $oImapResponse) : bool
{
return (
$oImapResponse
&& true !== $oImapResponse->IsStatusResponse
return
true !== $oImapResponse->IsStatusResponse
&& Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType
&& 3 < count($oImapResponse->ResponseList) && 'FETCH' === $oImapResponse->ResponseList[2]
&& is_array($oImapResponse->ResponseList[3])
);
&& 3 < \count($oImapResponse->ResponseList) && 'FETCH' === $oImapResponse->ResponseList[2]
&& \is_array($oImapResponse->ResponseList[3]);
}
public static function IsNotEmptyFetchImapResponse(Response $oImapResponse) : bool
public static function hasUidAndSize(Response $oImapResponse) : bool
{
return (
$oImapResponse
&& self::IsValidFetchImapResponse($oImapResponse)
&& isset($oImapResponse->ResponseList[3])
&& self::findFetchUidAndSize($oImapResponse->ResponseList[3])
);
return \in_array(Enumerations\FetchType::UID, $oImapResponse->ResponseList[3])
&& \in_array(Enumerations\FetchType::RFC822_SIZE, $oImapResponse->ResponseList[3]);
}
/**

View file

@ -883,8 +883,8 @@ class ImapClient extends \MailSo\Net\NetClient
$this->SendRequest($bIndexIsUid ? 'UID FETCH' : 'FETCH', $aParams);
foreach ($this->yieldUntaggedResponses() as $oResponse) {
if (FetchResponse::IsValidFetchImapResponse($oResponse)) {
if (FetchResponse::IsNotEmptyFetchImapResponse($oResponse)) {
if (FetchResponse::isValidImapResponse($oResponse)) {
if (FetchResponse::hasUidAndSize($oResponse)) {
$aReturn[] = new FetchResponse($oResponse);
} else if ($this->oLogger) {
$this->oLogger->Write('Skipped Imap Response! ['.$oResponse->ToLine().']', \MailSo\Log\Enumerations\Type::NOTICE);