X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fprefs.php;h=3ec5848158b62874ab394b33ccec4da6e308338a;hp=f66f863780019f64a159423ef8a7571928e798de;hb=36c59d842cfa1aadf349b367a9c1082ad58ac96b;hpb=8105d00ffd316911ad377816d972c89691ee33a9 diff --git a/functions/prefs.php b/functions/prefs.php index f66f8637..3ec58481 100644 --- a/functions/prefs.php +++ b/functions/prefs.php @@ -1,80 +1,180 @@ -"; - exit; - } - $file = fopen($filename, "r"); - - /** read in all the preferences **/ - for ($i=0; !feof($file); $i++) { - $pref[$i] = fgets($file, 1024); - if (substr($pref[$i], 0, strpos($pref[$i], "=")) == $string) { - $found = true; - $pos = $i; - } - } - fclose($file); - - $file = fopen($filename, "w"); - if ($found == true) { - for ($i=0; $i < count($pref); $i++) { - if ($i == $pos) { - fwrite($file, "$string=$set_to\n", 1024); - } else { - fwrite($file, "$pref[$i]", 1024); + \ No newline at end of file + } + } + + /* And return that directory. */ + return ($real_hash_dir); +} + +/** + * Helper function for getHashDir which does the actual hash calculation. + * + * Uses a crc32 algorithm by default, but if you put + * the following in config/config_local.php, you can + * force md5 instead: + * $hash_dirs_use_md5 = TRUE; + * + * You may also specify that if usernames are in full + * email address format, the domain part (beginning + * with "@") be stripped before calculating the crc + * or md5. Do that by putting the following in + * config/config_local.php: + * $hash_dirs_strip_domain = TRUE; + * + * @param string username the username to calculate the hash dir for + * + * @return array a list of hash dirs for this username + * + * @since 1.2.0 + * + */ +function computeHashDirs($username) { + + global $hash_dirs_use_md5, $hash_dirs_strip_domain; + static $hash_dirs = array(); + + + // strip domain from username + if ($hash_dirs_strip_domain) + $user = substr($username, 0, strpos($username, '@')); + else + $user = $username; + + + // have we already calculated it? + if (!empty($hash_dirs[$user])) + return $hash_dirs[$user]; + + + if ($hash_dirs_use_md5) { + + $hash = md5($user); + //$hash = md5bin($user); + + } else { + + /* Compute the hash for this user and extract the hash directories. */ + /* Note that the crc32() function result will be different on 32 and */ + /* 64 bit systems, thus the hack below. */ + $crc = crc32($user); + if ($crc & 0x80000000) { + $crc ^= 0xffffffff; + $crc += 1; + } + $hash = base_convert($crc, 10, 16); + } + + + $my_hash_dirs = array(); + for ($h = 0; $h < 4; ++ $h) { + $my_hash_dirs[] = substr($hash, $h, 1); + } + + // Return our array of hash directories + $hash_dirs[$user] = $my_hash_dirs; + return ($my_hash_dirs); +} +