Improve getFoldersFromResult fix

This commit is contained in:
RainLoop Team 2021-05-05 23:46:51 +03:00
parent 86e62d90ea
commit 46c3e305d7
2 changed files with 64 additions and 36 deletions

View file

@ -646,6 +646,36 @@ class ImapClient extends \MailSo\Net\NetClient
return $aResult;
}
/**
* @param array|string $mName
*
* @return string
*/
private function getArrayNameToStringName($mName)
{
if (\is_string($mName))
{
return $mName;
}
if (\is_array($mName))
{
if (0 === \count($mName))
{
return '[]';
}
foreach ($mName as &$mSubName)
{
$mSubName = "[{$this->getArrayNameToStringName($mSubName)}]";
}
return \implode('', $mName);
}
return '';
}
/**
* @param array $aResult
* @param string $sStatus
@ -670,20 +700,18 @@ class ImapClient extends \MailSo\Net\NetClient
{
/**
* A bug in the parser converts folder names that start with '[' into arrays,
* and subfolders are in $oResponse->ResponseList[5+]
* and subfolders are in $oImapResponse->ResponseList[5+]
* https://github.com/the-djmaze/snappymail/issues/1
* https://github.com/the-djmaze/snappymail/issues/70
* https://github.com/RainLoop/rainloop-webmail/issues/2037
*/
$sFullNameRaw = \array_slice($oImapResponse->ResponseList, 4);
foreach ($sFullNameRaw as &$name) {
if (\is_array($name)) {
$name = "[{$name[0]}]";
} else if (!\is_string($name)) {
$name = '';
}
$aFullNameRawList = \array_slice($oImapResponse->ResponseList, 4);
foreach ($aFullNameRawList as &$sName)
{
$sName = $this->getArrayNameToStringName($sName);
}
$sFullNameRaw = \implode('', $sFullNameRaw);
$sFullNameRaw = \implode('', $aFullNameRawList);
$oFolder = Folder::NewInstance($sFullNameRaw,
$oImapResponse->ResponseList[3], $oImapResponse->ResponseList[2]);