示例#1
0
 /**
  * @return bool
  */
 public function HasVisibleSubFolders()
 {
     $sList = array();
     if ($this->oSubFolders) {
         $sList = $this->oSubFolders->FilterList(function (CApiMailFolder $oFolder) {
             return $oFolder->IsSubscribed();
         });
     }
     return 0 < count($sList);
 }
示例#2
0
文件: folder.php 项目: Git-Host/email
 /**
  * Returns **true** if the folder has at least one subfolder and **false** otherwise.
  * 
  * @return bool
  */
 public function hasSubFolders()
 {
     return $this->oSubFolders && 0 < $this->oSubFolders->Count();
 }
示例#3
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;
 }
示例#4
0
 /**
  * @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;
 }