Bugfix: there's a long standing IMAP CLIENTBUG where STATUS command is executed after SELECT/EXAMINE on same folder

This commit is contained in:
djmaze 2021-10-27 21:14:52 +02:00
parent a7194b74b9
commit 3230a653d3
2 changed files with 14 additions and 11 deletions

View file

@ -429,6 +429,10 @@ class ImapClient extends \MailSo\Net\NetClient
*/ */
public function FolderStatus(string $sFolderName, array $aStatusItems) : ?array public function FolderStatus(string $sFolderName, array $aStatusItems) : ?array
{ {
$oFolderInfo = $this->oCurrentFolderInfo;
if ($sFolderName === $oFolderInfo->FolderName) {
return $oFolderInfo->getStatusItems();
}
return \count($aStatusItems) return \count($aStatusItems)
? $this->SendRequestGetResponse('STATUS', array($this->EscapeString($sFolderName), $aStatusItems)) ? $this->SendRequestGetResponse('STATUS', array($this->EscapeString($sFolderName), $aStatusItems))
->getStatusFolderInformationResult() ->getStatusFolderInformationResult()
@ -735,6 +739,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (!$aSearchOrSortReturn) if (!$aSearchOrSortReturn)
{ {
// ALL OR COUNT | MIN | MAX
$aSearchOrSortReturn = array('ALL'); $aSearchOrSortReturn = array('ALL');
} }
@ -1039,6 +1044,8 @@ class ImapClient extends \MailSo\Net\NetClient
$sFakeCommand = $sTag.' '.$sCommand.$this->prepareParamLine($aFakeParams); $sFakeCommand = $sTag.' '.$sCommand.$this->prepareParamLine($aFakeParams);
} }
// $this->lastCommand = $sFakeCommand ?: $sRealCommand;
$this->aTagTimeouts[$sTag] = \microtime(true); $this->aTagTimeouts[$sTag] = \microtime(true);
if ($bBreakOnLiteral && !\preg_match('/\d\+\}\r\n/', $sRealCommand)) if ($bBreakOnLiteral && !\preg_match('/\d\+\}\r\n/', $sRealCommand))
@ -1123,6 +1130,12 @@ class ImapClient extends \MailSo\Net\NetClient
throw new Exceptions\ResponseNotFoundException; throw new Exceptions\ResponseNotFoundException;
} }
// RFC 5530
if (\is_array($oResponse->OptionalResponse) && 'CLIENTBUG' === $oResponse->OptionalResponse[0]) {
// The server has detected a client bug.
// \error_log("IMAP {$oResponse->OptionalResponse[0]}: {$this->lastCommand}");
}
$oResult->append($oResponse); $oResult->append($oResponse);
if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) { if ($sEndTag === $oResponse->Tag || Enumerations\ResponseType::CONTINUATION === $oResponse->ResponseType) {
if (isset($this->aTagTimeouts[$sEndTag])) { if (isset($this->aTagTimeouts[$sEndTag])) {
@ -1134,11 +1147,6 @@ class ImapClient extends \MailSo\Net\NetClient
break; break;
} }
// RFC 5530
if (\is_array($oResponse->OptionalResponse) && 'CLIENTBUG' === $oResponse->OptionalResponse[0]) {
// The server has detected a client bug.
}
} }
} }

View file

@ -630,14 +630,9 @@ class MailClient
{ {
$aFlags = array(); $aFlags = array();
$bSelect = false;
if (\count($aUids)) if (\count($aUids))
{ {
if (!$bSelect) $this->oImapClient->FolderSelect($sFolderName);
{
$this->oImapClient->FolderSelect($sFolderName);
}
$aFetchResponse = $this->oImapClient->Fetch(array( $aFetchResponse = $this->oImapClient->Fetch(array(
\MailSo\Imap\Enumerations\FetchType::INDEX, \MailSo\Imap\Enumerations\FetchType::INDEX,