Fixes a search for non-ascii strings (#793)

This commit is contained in:
RainLoop Team 2015-08-12 23:39:49 +04:00
parent 106ee26ad2
commit 2a7d8ccab8
2 changed files with 70 additions and 8 deletions

View file

@ -1300,6 +1300,25 @@ class ImapClient extends \MailSo\Net\NetClient
return $this->simpleESearchOrESortHelper(true, $sSearchCriterias, $aSearchReturn, $bReturnUid, $sLimit, '', $aSortTypes);
}
/**
* @param array $aResult
* @return \MailSo\Imap\Response
*/
private function findLastResponse($aResult)
{
$oResult = null;
if (\is_array($aResult) && 0 < \count($aResult))
{
$oResult = $aResult[\count($aResult) - 1];
if (!($oResult instanceof \MailSo\Imap\Response))
{
$oResult = null;
}
}
return $oResult;
}
/**
* @param string $sSearchCriterias
* @param bool $bReturnUid = true
@ -1328,8 +1347,32 @@ class ImapClient extends \MailSo\Net\NetClient
$sCmd = 'SEARCH';
$this->SendRequest($sCommandPrefix.$sCmd, $aRequest);
$aResult = $this->parseResponseWithValidation();
$sCont = $this->SendRequest($sCommandPrefix.$sCmd, $aRequest, true);
if ('' !== $sCont)
{
$aResult = $this->parseResponseWithValidation();
$oItem = $this->findLastResponse($aResult);
if ($oItem && \MailSo\Imap\Enumerations\ResponseType::CONTINUATION === $oItem->ResponseType)
{
$aParts = explode("\r\n", $sCont);
foreach ($aParts as $sLine)
{
$this->sendRaw($sLine);
$aResult = $this->parseResponseWithValidation();
$oItem = $this->findLastResponse($aResult);
if ($oItem && \MailSo\Imap\Enumerations\ResponseType::CONTINUATION === $oItem->ResponseType)
{
continue;
}
}
}
}
else
{
$aResult = $this->parseResponseWithValidation();
}
$aReturn = array();
$oImapResponse = null;
@ -1660,13 +1703,14 @@ class ImapClient extends \MailSo\Net\NetClient
/**
* @param string $sCommand
* @param array $aParams = array()
* @param bool $bBreakOnLiteral = false
*
* @return void
* @return string
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
*/
public function SendRequest($sCommand, $aParams = array())
public function SendRequest($sCommand, $aParams = array(), $bBreakOnLiteral = false)
{
if (!\MailSo\Base\Validator::NotEmptyString($sCommand, true) || !\is_array($aParams))
{
@ -1690,7 +1734,23 @@ class ImapClient extends \MailSo\Net\NetClient
}
$this->aTagTimeouts[$sTag] = \microtime(true);
if ($bBreakOnLiteral && !\preg_match('/\d\+\}\r\n/', $sRealCommand))
{
$iPos = \strpos($sRealCommand, "}\r\n");
if (false !== $iPos)
{
$iFakePos = \strpos($sFakeCommand, "}\r\n");
$this->sendRaw(\substr($sRealCommand, 0, $iPos + 1), true,
false !== $iFakePos ? \substr($sFakeCommand, 0, $iFakePos + 3) : '');
return \substr($sRealCommand, $iPos + 3);
}
}
$this->sendRaw($sRealCommand, true, $sFakeCommand);
return '';
}
/**

View file

@ -967,8 +967,10 @@ class MailClient
*/
private function escapeSearchString($sSearch, $bDetectGmail = true)
{
return ($bDetectGmail && !\MailSo\Base\Utils::IsAscii($sSearch) && $this->IsGmail())
? '{'.\strlen($sSearch).'+}'."\r\n".$sSearch : $this->oImapClient->EscapeString($sSearch);
return !\MailSo\Base\Utils::IsAscii($sSearch)
? '{'.\strlen($sSearch).'}'."\r\n".$sSearch : $this->oImapClient->EscapeString($sSearch);
// return ($bDetectGmail && !\MailSo\Base\Utils::IsAscii($sSearch) && $this->IsGmail())
// ? '{'.\strlen($sSearch).'+}'."\r\n".$sSearch : $this->oImapClient->EscapeString($sSearch);
}
/**
@ -1396,7 +1398,7 @@ class MailClient
}
$sCriteriasResult = \trim($sCriteriasResult);
$sCriteriasResult .= ' NOT DELETED';
$sCriteriasResult .= ' UNDELETED';
$sFilter = \trim($sFilter);
if ('' !== $sFilter)
@ -1832,7 +1834,7 @@ class MailClient
{
$aResultUids = $bUseSortIfSupported ?
$this->oImapClient->MessageSimpleSort(array('REVERSE ARRIVAL'), $sSearchCriterias, true) :
$this->oImapClient->MessageSimpleSearch($sSearchCriterias, true)
$this->oImapClient->MessageSimpleSearch($sSearchCriterias, true, \MailSo\Base\Utils::IsAscii($sSearchCriterias) ? '' : 'UTF-8')
;
if (!$bUidsFromCacher && $bUseCacheAfterSearch && \is_array($aResultUids) && $oCacher && $oCacher->IsInited() && 0 < \strlen($sSerializedHash))