示例#1
0
 /**
  * @param string $sParent = ''
  * @param string $sListPattern = '*'
  * @param bool $bUseListStatus = false
  * @param bool $bUseListSubscribeStatus = false
  *
  * @return \MailSo\Mail\FolderCollection|false
  */
 public function Folders($sParent = '', $sListPattern = '*', $bUseListStatus = false, $bUseListSubscribeStatus = true)
 {
     $oFolderCollection = false;
     $aFolders = $this->oImapClient->FolderList($sParent, $sListPattern);
     $aSubscribedFolders = null;
     if ($bUseListSubscribeStatus) {
         try {
             $aSubscribedFolders = $this->oImapClient->FolderSubscribeList($sParent, $sListPattern);
         } catch (\Exception $oException) {
         }
     }
     // TODO
     //		$mStatusFolders = null;
     //		if ($bUseListStatus)
     //		{
     //			$mStatusFolders = $this->oImapClient->FolderStatusList($sParent, $sListPattern);
     //		}
     $aImapSubscribedFoldersHelper = null;
     if (\is_array($aSubscribedFolders)) {
         $aImapSubscribedFoldersHelper = array();
         foreach ($aSubscribedFolders as $oImapFolder) {
             $aImapSubscribedFoldersHelper[] = $oImapFolder->FullNameRaw();
         }
     }
     $aMailFoldersHelper = null;
     if (\is_array($aFolders)) {
         $aMailFoldersHelper = array();
         foreach ($aFolders as $oImapFolder) {
             $aMailFoldersHelper[] = Folder::NewInstance($oImapFolder, null === $aImapSubscribedFoldersHelper || \in_array($oImapFolder->FullNameRaw(), $aImapSubscribedFoldersHelper) || $oImapFolder->IsInbox());
         }
     }
     if (\is_array($aMailFoldersHelper)) {
         $oFolderCollection = FolderCollection::NewInstance();
         $oFolderCollection->InitByUnsortedMailFolderArray($aMailFoldersHelper);
     }
     if ($oFolderCollection) {
         $oFolderCollection->SortByCallback(function ($oFolderA, $oFolderB) {
             $sA = \strtoupper($oFolderA->FullNameRaw());
             $sB = \strtoupper($oFolderB->FullNameRaw());
             switch (true) {
                 case 'INBOX' === $sA:
                     return -1;
                 case 'INBOX' === $sB:
                     return 1;
                 case '[GMAIL]' === $sA:
                     return -1;
                 case '[GMAIL]' === $sB:
                     return 1;
             }
             return \strnatcmp($oFolderA->FullName(), $oFolderB->FullName());
         });
         $oNamespace = $this->oImapClient->GetNamespace();
         if ($oNamespace) {
             $oFolderCollection->SetNamespace($oNamespace->GetPersonalNamespace());
         }
         $oFolderCollection->IsThreadsSupported = $this->IsThreadsSupported();
     }
     return $oFolderCollection;
 }
示例#2
0
 /**
  * @param bool $bCreateIfNull = false
  * @return \MailSo\Mail\FolderCollection
  */
 public function SubFolders($bCreateIfNull = false)
 {
     if ($bCreateIfNull && !$this->oSubFolders) {
         $this->oSubFolders = FolderCollection::NewInstance();
     }
     return $this->oSubFolders;
 }