public function localize_foldername($name, $with_path = false, $path_remove = false)
    {
        $realnames = $this->config->get('show_real_foldernames');

        if (!$realnames && ($folder_class = $this->folder_classname($name))) {
            return $this->gettext($folder_class);
        }

        $storage   = $this->get_storage();
        $delimiter = $storage->get_hierarchy_delimiter();

        // Remove the path
        if ($path_remove) {
            if (strpos($name, $delimiter)) {
                $path = explode($delimiter, $name);
                $name = array_pop($path);
            }
        }
        // try to localize path of the folder
        else if ($with_path && !$realnames) {
            $path  = explode($delimiter, $name);
            $count = count($path);

            if ($count > 1) {
                for ($i = 1; $i < $count; $i++) {
                    $folder = implode($delimiter, array_slice($path, 0, -$i));
                    if ($folder_class = $this->folder_classname($folder)) {
                        $name = implode($delimiter, array_slice($path, $count - $i));
                        $name = rcube_charset::convert($name, 'UTF7-IMAP');

                        return $this->gettext($folder_class) . $delimiter . $name;
                    }
                }
            }
        }

        return rcube_charset::convert($name, 'UTF7-IMAP');
    }