src/IMAP/Client.php
public function getFolders($hierarchical = true, $parent_folder = null) {
        $this->checkConnection();
        $folders = FolderCollection::make([]);

        $pattern = $parent_folder.($hierarchical ? '%' : '*');

        $items = imap_getmailboxes($this->connection, $this->getAddress(), $pattern);
        if(is_array($items)){
            foreach ($items as $item) {
                $folder = new Folder($this, $item);

                if ($hierarchical && $folder->hasChildren()) {
                    $pattern = $folder->full_name.$folder->delimiter.'%';

                    $children = $this->getFolders(true, $pattern);
                    $folder->setChildren($children);
                }

                $folders->push($folder);
            }

            return $folders;
        }else{
            throw new MailboxFetchingException($this->getLastError());
        }
    }
public function getFolders($hierarchical = true, $parent_folder = null) {
        $this->checkConnection();
        $folders = FolderCollection::make([]);

        $pattern = $parent_folder.($hierarchical ? '%' : '*');

        $items = imap_getmailboxes($this->connection, $this->getAddress(), $pattern);
        if(is_array($items)){
            foreach ($items as $item) {
                $folder = new Folder($this, $item);

                if ($hierarchical && $folder->hasChildren()) {
                    $pattern = $folder->full_name.$folder->delimiter.'%';

                    $children = $this->getFolders(true, $pattern);
                    $folder->setChildren($children);
                }

                $folders->push($folder);
            }

            return $folders;
        }else{
            throw new MailboxFetchingException($this->getLastError());
        }
    }
public function getFolders ( $ hierarchical = true , $ parent_folder = null ) { $ this -> checkConnection ( ) ; $ folders = FolderCollection :: make ( [ ] ) ; $ pattern = $ parent_folder . ( $ hierarchical ? '%' : '*' ) ; $ items = imap_getmailboxes ( $ this -> connection , $ this -> getAddress ( ) , $ pattern ) ; if ( is_array ( $ items ) ) { foreach ( $ items as $ item ) { $ folder = new Folder ( $ this , $ item ) ; if ( $ hierarchical && $ folder -> hasChildren ( ) ) { $ pattern = $ folder -> full_name . $ folder -> delimiter . '%' ; $ children = $ this -> getFolders ( true , $ pattern ) ; $ folder -> setChildren ( $ children ) ; } $ folders -> push ( $ folder ) ; } return $ folders ; } else { throw new MailboxFetchingException ( $ this -> getLastError ( ) ) ; } }
Get folders list.
If hierarchical order is set to true, it will make a tree of folders, otherwise it will return flat array.

@param boolean     $hierarchical
@param string|null $parent_folder

@return FolderCollection
@throws ConnectionFailedException
@throws MailboxFetchingException
Get folders list . If hierarchical order is set to true it will make a tree of folders otherwise it will return flat array .