/** * @param bool $bCreateIfNull = false * * @return CApiMailFolderCollection */ public function SubFolders($bCreateIfNull = false) { if ($bCreateIfNull && !$this->oSubFolders) { $this->oSubFolders = CApiMailFolderCollection::NewInstance(); } return $this->oSubFolders; }
/** * @param CAccount $oAccount * @param bool $bCreateUnExistenSystemFolders = true * * @return CApiMailFolderCollection */ public function Folders($oAccount, $bCreateUnExistenSystemFolders = true) { $oFolderCollection = false; $sParent = ''; $sListPattern = '*'; $oImapClient =& $this->getImapClient($oAccount); $oNamespace = $oImapClient->GetNamespace(); $aFolders = $oImapClient->FolderList($sParent, $sListPattern); $aSubscribedFolders = $oImapClient->FolderSubscribeList($sParent, $sListPattern); $aImapSubscribedFoldersHelper = array(); if (is_array($aSubscribedFolders)) { foreach ($aSubscribedFolders as $oImapFolder) { $aImapSubscribedFoldersHelper[] = $oImapFolder->FullNameRaw(); } } $aMailFoldersHelper = null; if (is_array($aFolders)) { $aMailFoldersHelper = array(); foreach ($aFolders as $oImapFolder) { $aMailFoldersHelper[] = CApiMailFolder::NewInstance($oImapFolder, in_array($oImapFolder->FullNameRaw(), $aImapSubscribedFoldersHelper) || $oImapFolder->IsInbox()); } } if (is_array($aMailFoldersHelper)) { $oFolderCollection = CApiMailFolderCollection::NewInstance(); if ($oNamespace) { $oFolderCollection->SetNamespace($oNamespace->GetPersonalNamespace()); } $oFolderCollection->InitByUnsortedMailFolderArray($aMailFoldersHelper); if ($this->initSystemFolders($oAccount, $oFolderCollection, $bCreateUnExistenSystemFolders) && $bCreateUnExistenSystemFolders) { $oFolderCollection = $this->Folders($oAccount, false); } } if ($oFolderCollection && $oNamespace) { $oFolderCollection->SetNamespace($oNamespace->GetPersonalNamespace()); } $aFoldersOrderList = null; if (!$oAccount->IsEnabledExtension(CAccount::DisableFoldersManualSort)) { $aFoldersOrderList = $this->FoldersOrder($oAccount); $aFoldersOrderList = is_array($aFoldersOrderList) && 0 < count($aFoldersOrderList) ? $aFoldersOrderList : null; } $oFolderCollection->SortByCallback(function ($oFolderA, $oFolderB) use($aFoldersOrderList) { if (!$aFoldersOrderList) { if (EFolderType::Custom !== $oFolderA->Type() || EFolderType::Custom !== $oFolderB->Type()) { if ($oFolderA->Type() === $oFolderB->Type()) { return 0; } return $oFolderA->Type() < $oFolderB->Type() ? -1 : 1; } } else { $iPosA = array_search($oFolderA->FullNameRaw(), $aFoldersOrderList); $iPosB = array_search($oFolderB->FullNameRaw(), $aFoldersOrderList); if (is_int($iPosA) && is_int($iPosB)) { return $iPosA < $iPosB ? -1 : 1; } else { if (is_int($iPosA)) { return -1; } else { if (is_int($iPosB)) { return 1; } } } } return strnatcmp($oFolderA->FullName(), $oFolderB->FullName()); }); if (null === $aFoldersOrderList && !$oAccount->IsEnabledExtension(CAccount::DisableFoldersManualSort)) { $aNewFoldersOrderList = array(); $oFolderCollection->ForeachListWithSubFolders(function ($oFolder) use(&$aNewFoldersOrderList) { if ($oFolder) { $aNewFoldersOrderList[] = $oFolder->FullNameRaw(); } }); if (0 < count($aNewFoldersOrderList)) { $this->FoldersOrderUpdate($oAccount, $aNewFoldersOrderList); } } // if ($oAccount && $oFolderCollection && $oAccount->IsGmailAccount()) // { // $oFolder = null; // $oFolder =& $oFolderCollection->GetByFullNameRaw('[Gmail]'); // if ($oFolder) // { // $oFolder->SetGmailFolder(true); // } // } return $oFolderCollection; }