示例#1
0
 /**
  * Obtains the list of IMAP folders.
  * 
  * @param CAccount $oAccount Account object.
  * @param bool $bCreateUnExistenSystemFolders = true. Creating folders is required for WebMail work, usually it is done on first login to the account.
  *
  * @return CApiMailFolderCollection Collection of folders.
  */
 public function getFolders($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::createInstance($oImapFolder, in_array($oImapFolder->FullNameRaw(), $aImapSubscribedFoldersHelper) || $oImapFolder->IsInbox());
         }
     }
     if (is_array($aMailFoldersHelper)) {
         $oFolderCollection = CApiMailFolderCollection::createInstance();
         if ($oNamespace) {
             $oFolderCollection->setNamespace($oNamespace->GetPersonalNamespace());
         }
         $oFolderCollection->initialize($aMailFoldersHelper);
         if ($this->_initSystemFolders($oAccount, $oFolderCollection, $bCreateUnExistenSystemFolders) && $bCreateUnExistenSystemFolders) {
             $oFolderCollection = $this->getFolders($oAccount, false);
         }
     }
     if ($oFolderCollection && $oNamespace) {
         $oFolderCollection->setNamespace($oNamespace->GetPersonalNamespace());
     }
     $aFoldersOrderList = null;
     if (!$oAccount->isExtensionEnabled(CAccount::DisableFoldersManualSort)) {
         $aFoldersOrderList = $this->getFoldersOrder($oAccount);
         $aFoldersOrderList = is_array($aFoldersOrderList) && 0 < count($aFoldersOrderList) ? $aFoldersOrderList : null;
     }
     $oFolderCollection->sort(function ($oFolderA, $oFolderB) use($aFoldersOrderList) {
         if (!$aFoldersOrderList) {
             if (EFolderType::Custom !== $oFolderA->getType() || EFolderType::Custom !== $oFolderB->getType()) {
                 if ($oFolderA->getType() === $oFolderB->getType()) {
                     return 0;
                 }
                 return $oFolderA->getType() < $oFolderB->getType() ? -1 : 1;
             }
         } else {
             $iPosA = array_search($oFolderA->getRawFullName(), $aFoldersOrderList);
             $iPosB = array_search($oFolderB->getRawFullName(), $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(strtolower($oFolderA->getFullName()), strtolower($oFolderB->getFullName()));
     });
     if (null === $aFoldersOrderList && !$oAccount->isExtensionEnabled(CAccount::DisableFoldersManualSort)) {
         $aNewFoldersOrderList = array();
         $oFolderCollection->foreachWithSubFolders(function ($oFolder) use(&$aNewFoldersOrderList) {
             if ($oFolder) {
                 $aNewFoldersOrderList[] = $oFolder->getRawFullName();
             }
         });
         if (0 < count($aNewFoldersOrderList)) {
             $this->updateFoldersOrder($oAccount, $aNewFoldersOrderList);
         }
     }
     return $oFolderCollection;
 }
示例#2
0
文件: folder.php 项目: Git-Host/email
 /**
  * Return list of subfolders belonging to the folder.
  * 
  * @param bool $bCreateIfNull = false. If **true** the collection will be created even if there are no subfolders present.
  *
  * @return CApiMailFolderCollection
  */
 public function getSubFolders($bCreateIfNull = false)
 {
     if ($bCreateIfNull && !$this->oSubFolders) {
         $this->oSubFolders = CApiMailFolderCollection::createInstance();
     }
     return $this->oSubFolders;
 }