public function getFolders($separator = null, $type = 0)
    {
        if(preg_match( '/^{.+}/', $this->mailbox, $matches)){
            $mailbox = $matches[0];
        }else{
            $mailbox = $this->mailbox;
        };

        $folders = imap_list($this->imap, $mailbox, "*");

        if ($type == 2) {
            return $folders;
        };
        if ($type == 1) {
            return str_replace($mailbox, "", $folders);
        };
        if ($type == 0) {
            $arrayRaw = str_replace($mailbox, "", $folders);
            if (!isset($separator)) {
                $separator = '.';
            };
            $arrayNew = [];
            foreach ($arrayRaw as $string) {
                $array = explode($separator, $string);
                $count = count($array);
                $count = $count-1;
                $cache = false;
                for($i=$count; $i>=0; $i--){
                    if($i == $count){
                        $cache = [$array[$i]=>[]];
                    }else{
                        $cache = [$array[$i] => $cache];
                    };
                };
                $arrayNew = array_merge_recursive($arrayNew, $cache);
            };
            return $arrayNew;
        }
        return null;
    }
public function getFolders($separator = null, $type = 0)
    {
        if(preg_match( '/^{.+}/', $this->mailbox, $matches)){
            $mailbox = $matches[0];
        }else{
            $mailbox = $this->mailbox;
        };

        $folders = imap_list($this->imap, $mailbox, "*");

        if ($type == 2) {
            return $folders;
        };
        if ($type == 1) {
            return str_replace($mailbox, "", $folders);
        };
        if ($type == 0) {
            $arrayRaw = str_replace($mailbox, "", $folders);
            if (!isset($separator)) {
                $separator = '.';
            };
            $arrayNew = [];
            foreach ($arrayRaw as $string) {
                $array = explode($separator, $string);
                $count = count($array);
                $count = $count-1;
                $cache = false;
                for($i=$count; $i>=0; $i--){
                    if($i == $count){
                        $cache = [$array[$i]=>[]];
                    }else{
                        $cache = [$array[$i] => $cache];
                    };
                };
                $arrayNew = array_merge_recursive($arrayNew, $cache);
            };
            return $arrayNew;
        }
        return null;
    }
public function getFolders ( $ separator = null , $ type = 0 ) { if ( preg_match ( '/^{.+}/' , $ this -> mailbox , $ matches ) ) { $ mailbox = $ matches [ 0 ] ; } else { $ mailbox = $ this -> mailbox ; } ; $ folders = imap_list ( $ this -> imap , $ mailbox , "*" ) ; if ( $ type == 2 ) { return $ folders ; } ; if ( $ type == 1 ) { return str_replace ( $ mailbox , "" , $ folders ) ; } ; if ( $ type == 0 ) { $ arrayRaw = str_replace ( $ mailbox , "" , $ folders ) ; if ( ! isset ( $ separator ) ) { $ separator = '.' ; } ; $ arrayNew = [ ] ; foreach ( $ arrayRaw as $ string ) { $ array = explode ( $ separator , $ string ) ; $ count = count ( $ array ) ; $ count = $ count - 1 ; $ cache = false ; for ( $ i = $ count ; $ i >= 0 ; $ i -- ) { if ( $ i == $ count ) { $ cache = [ $ array [ $ i ] => [ ] ] ; } else { $ cache = [ $ array [ $ i ] => $ cache ] ; } ; } ; $ arrayNew = array_merge_recursive ( $ arrayNew , $ cache ) ; } ; return $ arrayNew ; } return null ; }
Returns all available folders

@param string $separator. Default is '.'
@param int $type. Has three meanings 0,1,2.
If 0 return nested array, if 1 return an array of strings, if 2 return raw imap_list()
@return array with folder names
Returns all available folders