Check if the folder name is valid

@param string $folder Folder name (UTF-8)
@param string &$char  First forbidden character found

@return bool True if the name is valid, False otherwise
518653
public function folder_validate($folder, &$char = null)
    {
        if (parent::folder_validate($folder, $char)) {
            $vendor = $this->get_vendor();
            $regexp = '\\x00-\\x1F\\x7F%*';

            if ($vendor == 'cyrus') {
                // List based on testing Kolab's Cyrus-IMAP 2.5
                $regexp .= '!`@(){}|\\?<;"';
            }

            if (!preg_match("/[$regexp]/", $folder, $m)) {
                return true;
            }

            $char = $m[0];
        }

        return false;
    }
33907
public function doesAcceptCharset($charset = 'utf-8')
	{
		return (in_array(strtolower($charset), $this->getAcceptCharsets(), true)) ? true : false;
	}
835783
public function folder_namespace($folder)
    {
        if ($folder == 'INBOX') {
            return 'personal';
        }

        foreach ($this->namespace as $type => $namespace) {
            if (is_array($namespace)) {
                foreach ($namespace as $ns) {
                    if ($len = strlen($ns[0])) {
                        if (($len > 1 && $folder == substr($ns[0], 0, -1))
                            || strpos($folder, $ns[0]) === 0
                        ) {
                            return $type;
                        }
                    }
                }
            }
        }

        return 'personal';
    }
485858
public function setFolderName($folder = null) {
    if($folder) {
      $folder = Folder::find_or_make($folder);
      $this->folderID = $folder->ID;
      $folder = str_replace('assets/', '', $folder->Filename);
      $this->folder = rtrim($this->folder . $folder, '/') . '/';
    }
  }
1225731
protected function validateFolder($exposeFolder)
    {
        if (strstr($exposeFolder, '.')) {
            return false;
        }
        if (strpos($exposeFolder, '/') === 0) {
            return false;
        }
        if (strpos($exposeFolder, '\\') === 0) {
            return false;
        }
        return true;
    }
1275061
public function folder_exists($folder, $subscription = false)
    {
        if ($folder == 'INBOX') {
            return true;
        }

        $key = $subscription ? 'subscribed' : 'existing';

        if (is_array($this->icache[$key]) && in_array($folder, $this->icache[$key])) {
            return true;
        }

        if (!$this->check_connection()) {
            return false;
        }

        if ($subscription) {
            // It's possible we already called LIST command, check LIST data
            if (!empty($this->conn->data['LIST']) && !empty($this->conn->data['LIST'][$folder])
                && in_array_nocase('\\Subscribed', $this->conn->data['LIST'][$folder])
            ) {
                $a_folders = array($folder);
            }
            else {
                $a_folders = $this->conn->listSubscribed('', $folder);
            }
        }
        else {
            // It's possible we already called LIST command, check LIST data
            if (!empty($this->conn->data['LIST']) && isset($this->conn->data['LIST'][$folder])) {
                $a_folders = array($folder);
            }
            else {
                $a_folders = $this->conn->listMailboxes('', $folder);
            }
        }

        if (is_array($a_folders) && in_array($folder, $a_folders)) {
            $this->icache[$key][] = $folder;
            return true;
        }

        return false;
    }
1368428
private function validateFolder(FolderInterface $folder)
    {
        $errorList = $this->get('validator')->validate($folder);
        if ($errorList->count()) {
            return $errorList->get(0)->getMessage();
        }
        return true;
    }
840017
def is_valid_xml_char(self, char):
        """"""
        codepoint = ord(char)
        return (0x20 <= codepoint <= 0xD7FF or
                codepoint in (0x9, 0xA, 0xD) or
                0xE000 <= codepoint <= 0xFFFD or
                0x10000 <= codepoint <= 0x10FFFF)
1102886
protected function realpath($folder)
    {
        $separator = (string) DIRECTORY_SEPARATOR;

        $search = array('\\', '/', (string) '\\\\');

        $path = str_replace($search, $separator, $folder);

        file_exists($path) || mkdir((string) $path);

        $exists = in_array(substr($path, -1), $search);

        return $exists ? $path : $path . $separator;
    }
476599
private static boolean isValidCharacter(int ch) {
		return
			(ch >= 0x20 && ch <= 0xD7FF) // Most common condition first
			|| ch == 0x9
			|| ch == 0xA
			|| ch == 0xD
			|| (ch >= 0xE000 && ch <= 0xFFFD)
			|| (ch >= 0x10000 && ch <= 0x10FFFF)
		;
	}
236647
public function checkIsHiddenFolder($folderName)
    {
        if (is_null($this->_config)) {
            $this->_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
        }

        $regex = $this->_config->getHideFoldersRegex();
        if ($regex) {
            return preg_match($regex, $folderName);
        }

        return false;
    }
81731
protected function folderContainsValidGithubRepo($folder)
    {
        $remote = $this->remoteGithub($folder);
        if ($this->isAGithubRepo($remote)) {
            return true;
        }
        return false;
    }
848413
public boolean isValidPosixFileName(String name) {
    for (int i = 0; i < name.length(); i++) {
      char c = name.charAt(i);
      if (i == 0) {
        if (c == '-') {
          return false;
        }
      }
      if (!isValidPosixFileChar(c)) {
        return false;
      }
    }
    return true;
  }
1236178
public static function isUpperCase($char): bool
    {
        self::handleIncomingChar($char);

        return static::compare($char, static::toUpperCase($char)) === 0;
    }
855812
public function folder_size($folder)
    {
        if (!strlen($folder)) {
            return false;
        }

        if (!$this->check_connection()) {
            return 0;
        }

        // On Cyrus we can use special folder annotation, which should be much faster
        if ($this->get_vendor() == 'cyrus') {
            $idx    = '/shared/vendor/cmu/cyrus-imapd/size';
            $result = $this->get_metadata($folder, $idx, array(), true);

            if (!empty($result) && is_numeric($result[$folder][$idx])) {
                return $result[$folder][$idx];
            }
        }

        // @TODO: could we try to use QUOTA here?
        $result = $this->conn->fetchHeaderIndex($folder, '1:*', 'SIZE', false);

        if (is_array($result)) {
            $result = array_sum($result);
        }

        return $result;
    }
357290
public function checkChars($value)
    {
        if (!is_string($value)) {
            return false;
        }

        $characters = $this->getCharacters();
        if ($characters == 128) {
            for ($x = 0; $x < 128; ++$x) {
                $value = str_replace(chr($x), '', $value);
            }
        } else {
            $chars = str_split($characters);
            foreach ($chars as $char) {
                $value = str_replace($char, '', $value);
            }
        }

        if (strlen($value) > 0) {
            return false;
        }

        return true;
    }
1060554
public function checkFolderIsEmptyOrNot(string $folderName):bool
    {
        $files = array ();
        if ($handle = opendir($folderName)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != "..") {
                    $files [] = $file;
                }
            }
            closedir($handle);
        }
        return ((count($files) === 0) ?  true : false);
    }